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 220 - (hide annotations) (download) (as text)
Thu Jul 9 17:32:35 2009 UTC (15 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 6027 byte(s)
Ensure that variable is reset before using it.

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

Properties

Name Value
cvs:description Planet file splitter.