Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/planetsplitter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 310 - (hide annotations) (download) (as text)
Fri Dec 11 19:27:39 2009 UTC (15 years, 3 months ago) by amb
File MIME type: text/x-csrc
File size: 7837 byte(s)
Added a new function to sort variable length data - simplifies the compacting of
ways, reduces memory usage potentially required for it and simplifies the code.

1 amb 2 /***************************************
2 amb 310 $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.65 2009-12-11 19:27:39 amb Exp $
3 amb 2
4     OSM planet file splitter.
5 amb 151
6     Part of the Routino routing software.
7 amb 2 ******************/ /******************
8 amb 151 This file Copyright 2008,2009 Andrew M. Bishop
9 amb 2
10 amb 151 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 amb 2 ***************************************/
23    
24    
25     #include <stdio.h>
26     #include <stdlib.h>
27 amb 60 #include <string.h>
28 amb 2
29 amb 199 #include "typesx.h"
30 amb 96 #include "types.h"
31 amb 199 #include "functionsx.h"
32 amb 109 #include "functions.h"
33     #include "nodesx.h"
34     #include "segmentsx.h"
35     #include "waysx.h"
36     #include "superx.h"
37 amb 82 #include "profiles.h"
38 amb 228 #include "ways.h"
39 amb 2
40    
41 amb 284 /* Variables */
42    
43 amb 249 /*+ The option to use a slim mode with file-backed read-only intermediate storage. +*/
44     int option_slim=0;
45    
46 amb 256 /*+ The name of the temporary directory. +*/
47 amb 284 char *option_tmpdirname=NULL;
48 amb 249
49 amb 284
50 amb 2 int main(int argc,char** argv)
51     {
52 amb 256 NodesX *Nodes;
53     SegmentsX *Segments,*SuperSegments=NULL,*MergedSegments=NULL;
54     WaysX *Ways;
55 amb 58 int iteration=0,quit=0;
56 amb 150 int max_iterations=10;
57 amb 256 char *dirname=NULL,*prefix=NULL;
58 amb 220 Profile profile={0};
59 amb 75 int i;
60 amb 26
61 amb 82 /* Fill in the default profile. */
62 amb 31
63 amb 82 profile.transport=Transport_None; /* Not used by planetsplitter */
64 amb 75
65 amb 307 profile.allow=0;
66 amb 75
67 amb 300 for(i=1;i<Way_Count;i++)
68 amb 166 profile.highway[i]=1;
69 amb 82
70 amb 298 for(i=1;i<Property_Count;i++)
71     profile.props_yes[i]=1;
72    
73 amb 82 profile.oneway=1; /* Not used by planetsplitter */
74    
75     /* Parse the command line arguments */
76    
77 amb 60 while(--argc>=1)
78     {
79 amb 101 if(!strcmp(argv[argc],"--help"))
80 amb 75 goto usage;
81 amb 249 else if(!strcmp(argv[argc],"--slim"))
82     option_slim=1;
83 amb 101 else if(!strncmp(argv[argc],"--dir=",6))
84     dirname=&argv[argc][6];
85 amb 252 else if(!strncmp(argv[argc],"--tmpdir=",9))
86 amb 284 option_tmpdirname=&argv[argc][9];
87 amb 101 else if(!strncmp(argv[argc],"--prefix=",9))
88     prefix=&argv[argc][9];
89     else if(!strncmp(argv[argc],"--max-iterations=",17))
90     max_iterations=atoi(&argv[argc][17]);
91     else if(!strncmp(argv[argc],"--transport=",12))
92 amb 82 {
93 amb 307 Transport transport=TransportType(&argv[argc][12]);
94     if(transport==Transport_None)
95     goto usage;
96     profile.allow|=ALLOWED(transport);
97 amb 82 }
98 amb 101 else if(!strncmp(argv[argc],"--not-highway=",14))
99 amb 75 {
100 amb 101 Highway highway=HighwayType(&argv[argc][14]);
101 amb 300 if(highway==Way_Count)
102 amb 298 goto usage;
103 amb 166 profile.highway[highway]=0;
104 amb 75 }
105 amb 298 else if(!strncmp(argv[argc],"--not-property=",15))
106     {
107     Property property=PropertyType(&argv[argc][15]);
108     if(property==Property_Count)
109     goto usage;
110     profile.props_yes[property]=0;
111     }
112 amb 60 else
113     {
114 amb 75 usage:
115    
116     fprintf(stderr,"Usage: planetsplitter\n"
117 amb 150 " [--help]\n"
118 amb 298 " [--dir=<name>] [--prefix=<name>]\n"
119 amb 252 " [--slim] [--tmpdir=<name>]\n"
120 amb 101 " [--max-iterations=<number>]\n"
121 amb 307 " [--transport=<transport> ...]\n"
122 amb 101 " [--not-highway=<highway> ...]\n"
123 amb 298 " [--not-property=<property> ...]\n"
124 amb 75 "\n"
125 amb 82 "<transport> defaults to all but can be set to:\n"
126 amb 75 "%s"
127     "\n"
128 amb 82 "<highway> can be selected from:\n"
129 amb 298 "%s"
130     "\n"
131     "<property> can be selected from:\n"
132 amb 75 "%s",
133 amb 298 TransportList(),HighwayList(),PropertyList());
134 amb 75
135 amb 60 return(1);
136     }
137     }
138 amb 26
139 amb 284 if(!option_tmpdirname)
140 amb 252 {
141     if(!dirname)
142 amb 284 option_tmpdirname=".";
143 amb 252 else
144 amb 284 option_tmpdirname=dirname;
145 amb 252 }
146    
147 amb 307 if(!profile.allow)
148     profile.allow=Allow_ALL;
149    
150 amb 275 /* Create new node, segment and way variables */
151 amb 82
152 amb 256 Nodes=NewNodeList();
153 amb 275
154 amb 256 Segments=NewSegmentList();
155 amb 275
156 amb 256 Ways=NewWayList();
157 amb 26
158 amb 89 /* Parse the file */
159 amb 2
160 amb 229 printf("\nParse OSM Data\n==============\n\n");
161 amb 227 fflush(stdout);
162 amb 2
163 amb 256 ParseXML(stdin,Nodes,Segments,Ways,&profile);
164 amb 80
165 amb 229 /* Process the data */
166    
167     printf("\nProcess OSM Data\n================\n\n");
168 amb 227 fflush(stdout);
169 amb 8
170 amb 275 /* Sort the nodes, segments and ways */
171 amb 263
172     SortNodeList(Nodes);
173    
174 amb 275 SortSegmentList(Segments);
175 amb 80
176 amb 256 SortWayList(Ways);
177 amb 87
178 amb 279 /* Remove bad segments (must be after sorting the nodes and segments) */
179 amb 247
180 amb 256 RemoveBadSegments(Nodes,Segments);
181 amb 87
182 amb 247 /* Remove non-highway nodes (must be after removing the bad segments) */
183 amb 66
184 amb 256 RemoveNonHighwayNodes(Nodes,Segments);
185 amb 247
186 amb 279 /* Measure the segments and replace node/way id with index (must be after removing non-highway nodes) */
187 amb 247
188 amb 279 UpdateSegments(Segments,Nodes,Ways);
189 amb 66
190    
191 amb 258 /* Repeated iteration on Super-Nodes and Super-Segments */
192 amb 58
193     do
194     {
195 amb 229 printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":"");
196 amb 227 fflush(stdout);
197 amb 80
198 amb 90 if(iteration==0)
199     {
200     /* Select the super-nodes */
201 amb 58
202 amb 256 ChooseSuperNodes(Nodes,Segments,Ways);
203 amb 58
204 amb 90 /* Select the super-segments */
205 amb 58
206 amb 256 SuperSegments=CreateSuperSegments(Nodes,Segments,Ways,iteration);
207 amb 90 }
208     else
209     {
210 amb 97 SegmentsX *SuperSegments2;
211 amb 58
212 amb 90 /* Select the super-nodes */
213    
214 amb 256 ChooseSuperNodes(Nodes,SuperSegments,Ways);
215 amb 90
216     /* Select the super-segments */
217    
218 amb 256 SuperSegments2=CreateSuperSegments(Nodes,SuperSegments,Ways,iteration);
219 amb 90
220 amb 282 if(SuperSegments->xnumber==SuperSegments2->xnumber)
221 amb 104 quit=1;
222    
223 amb 97 FreeSegmentList(SuperSegments);
224 amb 90
225 amb 97 SuperSegments=SuperSegments2;
226 amb 90 }
227    
228 amb 275 /* Sort the super-segments */
229 amb 58
230 amb 275 SortSegmentList(SuperSegments);
231 amb 58
232 amb 229 /* Remove duplicated super-segments */
233    
234 amb 279 DeduplicateSegments(SuperSegments,Nodes,Ways);
235 amb 229
236 amb 89 iteration++;
237 amb 58
238 amb 89 if(iteration>max_iterations)
239     quit=1;
240     }
241     while(!quit);
242 amb 58
243 amb 229 /* Combine the super-segments */
244    
245     printf("\nCombine Segments and Super-Segments\n===================================\n\n");
246 amb 227 fflush(stdout);
247 amb 58
248 amb 104 /* Merge the super-segments */
249    
250 amb 256 MergedSegments=MergeSuperSegments(Segments,SuperSegments);
251 amb 104
252 amb 256 FreeSegmentList(Segments);
253    
254 amb 97 FreeSegmentList(SuperSegments);
255 amb 58
256 amb 256 Segments=MergedSegments;
257 amb 90
258 amb 275 /* Rotate segments so that node1<node2 */
259 amb 256
260 amb 275 RotateSegments(Segments);
261 amb 256
262 amb 275 /* Sort the segments */
263 amb 258
264 amb 275 SortSegmentList(Segments);
265 amb 258
266 amb 275 /* Remove duplicated segments */
267    
268 amb 279 DeduplicateSegments(Segments,Nodes,Ways);
269 amb 275
270 amb 229 /* Cross reference the nodes and segments */
271 amb 90
272 amb 229 printf("\nCross-Reference Nodes and Segments\n==================================\n\n");
273     fflush(stdout);
274 amb 90
275 amb 212 /* Sort the node list geographically */
276 amb 209
277 amb 256 SortNodeListGeographically(Nodes);
278 amb 212
279     /* Create the real segments and nodes */
280    
281 amb 256 CreateRealNodes(Nodes,iteration);
282 amb 212
283 amb 256 CreateRealSegments(Segments,Ways);
284 amb 209
285 amb 104 /* Fix the segment and node indexes */
286    
287 amb 256 IndexNodes(Nodes,Segments);
288 amb 104
289 amb 256 IndexSegments(Segments,Nodes);
290 amb 104
291 amb 229 /* Output the results */
292    
293     printf("\nWrite Out Database Files\n========================\n\n");
294     fflush(stdout);
295    
296 amb 89 /* Write out the nodes */
297 amb 58
298 amb 256 SaveNodeList(Nodes,FileName(dirname,prefix,"nodes.mem"));
299 amb 95
300 amb 256 FreeNodeList(Nodes);
301 amb 226
302 amb 89 /* Write out the segments */
303 amb 58
304 amb 256 SaveSegmentList(Segments,FileName(dirname,prefix,"segments.mem"));
305 amb 58
306 amb 256 FreeSegmentList(Segments);
307 amb 226
308 amb 89 /* Write out the ways */
309 amb 58
310 amb 307 SaveWayList(Ways,FileName(dirname,prefix,"ways.mem"),&profile);
311 amb 58
312 amb 256 FreeWayList(Ways);
313 amb 226
314 amb 2 return(0);
315     }

Properties

Name Value
cvs:description Planet file splitter.