Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/planetsplitter.c
Parent Directory
|
Revision Log
Revision 199 -
(hide annotations)
(download)
(as text)
Mon Jun 15 18:56:09 2009 UTC (15 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 6085 byte(s)
Mon Jun 15 18:56:09 2009 UTC (15 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 6085 byte(s)
Put some of types.h into typesx.h (for extended data types). Put some of functions.h into functionsx.h (for OSM parser). Change included files to match.
1 | amb | 2 | /*************************************** |
2 | amb | 199 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.38 2009-06-15 18:56:09 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 | 82 | Profile profile; |
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 | for(i=1;i<Way_Unknown;i++) | ||
61 | profile.speed[i]=0; /* Not used by planetsplitter */ | ||
62 | |||
63 | profile.oneway=1; /* Not used by planetsplitter */ | ||
64 | |||
65 | /* Parse the command line arguments */ | ||
66 | |||
67 | amb | 60 | while(--argc>=1) |
68 | { | ||
69 | amb | 101 | if(!strcmp(argv[argc],"--help")) |
70 | amb | 75 | goto usage; |
71 | amb | 101 | else if(!strncmp(argv[argc],"--dir=",6)) |
72 | dirname=&argv[argc][6]; | ||
73 | else if(!strncmp(argv[argc],"--prefix=",9)) | ||
74 | prefix=&argv[argc][9]; | ||
75 | else if(!strncmp(argv[argc],"--max-iterations=",17)) | ||
76 | max_iterations=atoi(&argv[argc][17]); | ||
77 | else if(!strncmp(argv[argc],"--transport=",12)) | ||
78 | amb | 82 | { |
79 | amb | 101 | profile.transport=TransportType(&argv[argc][12]); |
80 | amb | 82 | profile.allow=1<<(profile.transport-1); |
81 | } | ||
82 | amb | 101 | else if(!strncmp(argv[argc],"--not-highway=",14)) |
83 | amb | 75 | { |
84 | amb | 101 | Highway highway=HighwayType(&argv[argc][14]); |
85 | amb | 166 | profile.highway[highway]=0; |
86 | amb | 75 | } |
87 | amb | 60 | else |
88 | { | ||
89 | amb | 75 | usage: |
90 | |||
91 | fprintf(stderr,"Usage: planetsplitter\n" | ||
92 | amb | 150 | " [--help]\n" |
93 | amb | 101 | " [--dir=<name>] [--prefix=<name>]\n" |
94 | " [--max-iterations=<number>]\n" | ||
95 | " [--transport=<transport>]\n" | ||
96 | " [--not-highway=<highway> ...]\n" | ||
97 | amb | 75 | "\n" |
98 | amb | 82 | "<transport> defaults to all but can be set to:\n" |
99 | amb | 75 | "%s" |
100 | "\n" | ||
101 | amb | 82 | "<highway> can be selected from:\n" |
102 | amb | 75 | "%s", |
103 | TransportList(),HighwayList()); | ||
104 | |||
105 | amb | 60 | return(1); |
106 | } | ||
107 | } | ||
108 | amb | 26 | |
109 | amb | 89 | /* Create new variables */ |
110 | amb | 82 | |
111 | amb | 97 | OSMNodes=NewNodeList(); |
112 | OSMSegments=NewSegmentList(); | ||
113 | OSMWays=NewWayList(); | ||
114 | amb | 26 | |
115 | amb | 89 | /* Parse the file */ |
116 | amb | 2 | |
117 | amb | 89 | printf("\nParsing OSM Data\n================\n\n"); fflush(stdout); |
118 | amb | 2 | |
119 | amb | 97 | ParseXML(stdin,OSMNodes,OSMSegments,OSMWays,&profile); |
120 | amb | 80 | |
121 | amb | 89 | printf("\nProcessing OSM Data\n===================\n\n"); fflush(stdout); |
122 | amb | 8 | |
123 | amb | 89 | /* Sort the ways */ |
124 | amb | 80 | |
125 | amb | 97 | SortWayList(OSMWays); |
126 | amb | 87 | |
127 | amb | 89 | /* Sort the segments */ |
128 | amb | 87 | |
129 | amb | 97 | SortSegmentList(OSMSegments); |
130 | amb | 84 | |
131 | amb | 195 | /* Sort the nodes */ |
132 | |||
133 | SortNodeList(OSMNodes); | ||
134 | |||
135 | amb | 89 | /* Remove bad segments */ |
136 | amb | 84 | |
137 | amb | 195 | RemoveBadSegments(OSMNodes,OSMSegments); |
138 | amb | 87 | |
139 | amb | 97 | SortSegmentList(OSMSegments); |
140 | amb | 87 | |
141 | amb | 89 | /* Remove non-way nodes */ |
142 | amb | 41 | |
143 | amb | 97 | RemoveNonHighwayNodes(OSMNodes,OSMSegments); |
144 | amb | 41 | |
145 | amb | 97 | SortNodeList(OSMNodes); |
146 | amb | 41 | |
147 | amb | 89 | /* Measure the segments */ |
148 | amb | 66 | |
149 | amb | 97 | MeasureSegments(OSMSegments,OSMNodes); |
150 | amb | 66 | |
151 | |||
152 | amb | 58 | /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */ |
153 | |||
154 | do | ||
155 | { | ||
156 | amb | 80 | printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":""); fflush(stdout); |
157 | |||
158 | amb | 90 | if(iteration==0) |
159 | { | ||
160 | /* Select the super-nodes */ | ||
161 | amb | 58 | |
162 | amb | 97 | ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays,iteration); |
163 | amb | 58 | |
164 | amb | 90 | /* Select the super-segments */ |
165 | amb | 58 | |
166 | amb | 97 | SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,iteration); |
167 | amb | 90 | } |
168 | else | ||
169 | { | ||
170 | amb | 97 | SegmentsX *SuperSegments2; |
171 | amb | 58 | |
172 | amb | 90 | /* Select the super-nodes */ |
173 | |||
174 | amb | 97 | ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays,iteration); |
175 | amb | 90 | |
176 | /* Select the super-segments */ | ||
177 | |||
178 | amb | 97 | SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays,iteration); |
179 | amb | 90 | |
180 | amb | 104 | if(SuperSegments->number==SuperSegments2->number) |
181 | quit=1; | ||
182 | |||
183 | amb | 97 | FreeSegmentList(SuperSegments); |
184 | amb | 90 | |
185 | amb | 97 | SuperSegments=SuperSegments2; |
186 | amb | 90 | } |
187 | |||
188 | amb | 66 | /* Sort the super-segments */ |
189 | amb | 58 | |
190 | amb | 97 | SortSegmentList(SuperSegments); |
191 | amb | 58 | |
192 | amb | 89 | iteration++; |
193 | amb | 58 | |
194 | amb | 89 | if(iteration>max_iterations) |
195 | quit=1; | ||
196 | } | ||
197 | while(!quit); | ||
198 | amb | 58 | |
199 | amb | 104 | printf("\n"); fflush(stdout); |
200 | amb | 58 | |
201 | amb | 104 | /* Mark the super-nodes */ |
202 | amb | 66 | |
203 | amb | 104 | MarkSuperNodes(OSMNodes,iteration); |
204 | amb | 66 | |
205 | amb | 104 | /* Merge the super-segments */ |
206 | |||
207 | MergeSuperSegments(OSMSegments,SuperSegments); | ||
208 | |||
209 | amb | 97 | FreeSegmentList(SuperSegments); |
210 | amb | 58 | |
211 | amb | 90 | /* Sort the segments */ |
212 | amb | 58 | |
213 | amb | 97 | SortSegmentList(OSMSegments); |
214 | amb | 90 | |
215 | amb | 104 | /* Rotate segments so that node1<node2 */ |
216 | amb | 90 | |
217 | amb | 104 | RotateSegments(OSMSegments,OSMNodes); |
218 | amb | 90 | |
219 | amb | 104 | /* Sort the segments */ |
220 | |||
221 | SortSegmentList(OSMSegments); | ||
222 | |||
223 | /* Remove duplicated segments */ | ||
224 | |||
225 | DeduplicateSegments(OSMSegments,OSMNodes,OSMWays); | ||
226 | |||
227 | /* Sort the segments */ | ||
228 | |||
229 | SortSegmentList(OSMSegments); | ||
230 | |||
231 | /* Fix the segment and node indexes */ | ||
232 | |||
233 | IndexNodes(OSMNodes,OSMSegments); | ||
234 | |||
235 | IndexSegments(OSMSegments,OSMNodes); | ||
236 | |||
237 | amb | 89 | /* Write out the nodes */ |
238 | amb | 58 | |
239 | amb | 162 | SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem")); |
240 | amb | 95 | |
241 | amb | 89 | /* Write out the segments */ |
242 | amb | 58 | |
243 | amb | 162 | SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem")); |
244 | amb | 58 | |
245 | amb | 89 | /* Write out the ways */ |
246 | amb | 58 | |
247 | amb | 162 | SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem")); |
248 | amb | 58 | |
249 | amb | 2 | return(0); |
250 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |