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 258 - (hide annotations) (download) (as text)
Tue Sep 15 11:39:50 2009 UTC (15 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 7449 byte(s)
Some bug fixes and some missing unmap function calls.

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

Properties

Name Value
cvs:description Planet file splitter.