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 247 - (show annotations) (download) (as text)
Tue Aug 25 18:00:21 2009 UTC (15 years, 6 months ago) by amb
File MIME type: text/x-csrc
File size: 6596 byte(s)
Revert the order that the functions are called.

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

Properties

Name Value
cvs:description Planet file splitter.