Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/planetsplitter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 227 - (show annotations) (download) (as text)
Sun Jul 12 08:38:12 2009 UTC (15 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 6165 byte(s)
Check all print statements and made them more consistent and/or accurate.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.47 2009-07-12 08:38:12 amb Exp $
3
4 OSM planet file splitter.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008,2009 Andrew M. Bishop
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ***************************************/
23
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "typesx.h"
30 #include "types.h"
31 #include "functionsx.h"
32 #include "functions.h"
33 #include "nodesx.h"
34 #include "segmentsx.h"
35 #include "waysx.h"
36 #include "superx.h"
37 #include "profiles.h"
38
39
40 int main(int argc,char** argv)
41 {
42 NodesX *OSMNodes;
43 SegmentsX *OSMSegments,*SuperSegments=NULL;
44 WaysX *OSMWays;
45 int iteration=0,quit=0;
46 int max_iterations=10;
47 char *dirname=NULL,*prefix=NULL;
48 Profile profile={0};
49 int i;
50
51 /* Fill in the default profile. */
52
53 profile.transport=Transport_None; /* Not used by planetsplitter */
54
55 profile.allow=Allow_ALL;
56
57 for(i=1;i<Way_Unknown;i++)
58 profile.highway[i]=1;
59
60 profile.oneway=1; /* Not used by planetsplitter */
61
62 /* Parse the command line arguments */
63
64 while(--argc>=1)
65 {
66 if(!strcmp(argv[argc],"--help"))
67 goto usage;
68 else if(!strncmp(argv[argc],"--dir=",6))
69 dirname=&argv[argc][6];
70 else if(!strncmp(argv[argc],"--prefix=",9))
71 prefix=&argv[argc][9];
72 else if(!strncmp(argv[argc],"--max-iterations=",17))
73 max_iterations=atoi(&argv[argc][17]);
74 else if(!strncmp(argv[argc],"--transport=",12))
75 {
76 profile.transport=TransportType(&argv[argc][12]);
77 profile.allow=1<<(profile.transport-1);
78 }
79 else if(!strncmp(argv[argc],"--not-highway=",14))
80 {
81 Highway highway=HighwayType(&argv[argc][14]);
82 profile.highway[highway]=0;
83 }
84 else
85 {
86 usage:
87
88 fprintf(stderr,"Usage: planetsplitter\n"
89 " [--help]\n"
90 " [--dir=<name>] [--prefix=<name>]\n"
91 " [--max-iterations=<number>]\n"
92 " [--transport=<transport>]\n"
93 " [--not-highway=<highway> ...]\n"
94 "\n"
95 "<transport> defaults to all but can be set to:\n"
96 "%s"
97 "\n"
98 "<highway> can be selected from:\n"
99 "%s",
100 TransportList(),HighwayList());
101
102 return(1);
103 }
104 }
105
106 /* Create new variables */
107
108 OSMNodes=NewNodeList();
109 OSMSegments=NewSegmentList();
110 OSMWays=NewWayList();
111
112 /* Parse the file */
113
114 printf("\nParsing OSM Data\n================\n\n");
115 fflush(stdout);
116
117 ParseXML(stdin,OSMNodes,OSMSegments,OSMWays,&profile);
118
119 printf("\nProcessing OSM Data\n===================\n\n");
120 fflush(stdout);
121
122 /* Sort the ways */
123
124 SortWayList(OSMWays);
125
126 /* Sort the segments */
127
128 SortSegmentList(OSMSegments);
129
130 /* Sort the nodes */
131
132 SortNodeList(OSMNodes);
133
134 /* Compact the ways */
135
136 CompactWays(OSMWays);
137
138 /* Remove bad segments */
139
140 RemoveBadSegments(OSMNodes,OSMSegments);
141
142 SortSegmentList(OSMSegments);
143
144 /* Remove non-way nodes */
145
146 RemoveNonHighwayNodes(OSMNodes,OSMSegments);
147
148 SortNodeList(OSMNodes);
149
150 /* Measure the segments */
151
152 MeasureSegments(OSMSegments,OSMNodes);
153
154
155 /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */
156
157 do
158 {
159 printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":"");
160 fflush(stdout);
161
162 if(iteration==0)
163 {
164 /* Select the super-nodes */
165
166 ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays);
167
168 /* Select the super-segments */
169
170 SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,iteration);
171 }
172 else
173 {
174 SegmentsX *SuperSegments2;
175
176 /* Select the super-nodes */
177
178 ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays);
179
180 /* Select the super-segments */
181
182 SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays,iteration);
183
184 if(SuperSegments->number==SuperSegments2->number)
185 quit=1;
186
187 FreeSegmentList(SuperSegments);
188
189 SuperSegments=SuperSegments2;
190 }
191
192 /* Sort the super-segments */
193
194 SortSegmentList(SuperSegments);
195
196 iteration++;
197
198 if(iteration>max_iterations)
199 quit=1;
200 }
201 while(!quit);
202
203 printf("\n");
204 fflush(stdout);
205
206 /* Merge the super-segments */
207
208 MergeSuperSegments(OSMSegments,SuperSegments);
209
210 FreeSegmentList(SuperSegments);
211
212 SortSegmentList(OSMSegments);
213
214 /* Rotate segments so that node1<node2 */
215
216 RotateSegments(OSMSegments);
217
218 SortSegmentList(OSMSegments);
219
220 /* Remove duplicated segments */
221
222 DeduplicateSegments(OSMSegments,OSMWays);
223
224 SortSegmentList(OSMSegments);
225
226 /* Sort the node list geographically */
227
228 SortNodeListGeographically(OSMNodes);
229
230 /* Create the real segments and nodes */
231
232 CreateRealNodes(OSMNodes,iteration);
233
234 CreateRealSegments(OSMSegments,OSMWays);
235
236 /* Fix the segment and node indexes */
237
238 IndexNodes(OSMNodes,OSMSegments);
239
240 IndexSegments(OSMSegments,OSMNodes);
241
242 /* Write out the nodes */
243
244 SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem"));
245
246 FreeNodeList(OSMNodes);
247
248 /* Write out the segments */
249
250 SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem"));
251
252 FreeSegmentList(OSMSegments);
253
254 /* Write out the ways */
255
256 SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem"));
257
258 FreeWayList(OSMWays);
259
260 return(0);
261 }

Properties

Name Value
cvs:description Planet file splitter.