Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/planetsplitter.c
Parent Directory
|
Revision Log
Revision 58 -
(show annotations)
(download)
(as text)
Mon Jan 19 19:51:42 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 7577 byte(s)
Mon Jan 19 19:51:42 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 7577 byte(s)
Iteratively calculate the super-segments.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.11 2009-01-19 19:51:42 amb Exp $ |
3 | |
4 | OSM planet file splitter. |
5 | ******************/ /****************** |
6 | Written by Andrew M. Bishop |
7 | |
8 | This file Copyright 2008,2009 Andrew M. Bishop |
9 | It may be distributed under the GNU Public License, version 2, or |
10 | any higher version. See section COPYING of the GNU Public license |
11 | for conditions under which this file may be redistributed. |
12 | ***************************************/ |
13 | |
14 | |
15 | #include <stdio.h> |
16 | #include <stdlib.h> |
17 | |
18 | #include "nodes.h" |
19 | #include "ways.h" |
20 | #include "segments.h" |
21 | #include "functions.h" |
22 | |
23 | |
24 | #define SKIP_PARSING 0 |
25 | #define MAX_ITERATIONS 5 |
26 | |
27 | |
28 | int main(int argc,char** argv) |
29 | { |
30 | #if !SKIP_PARSING |
31 | NodesMem *OSMNodesMem; |
32 | WaysMem *OSMWaysMem; |
33 | SegmentsMem *OSMSegmentsMem; |
34 | #endif |
35 | NodesMem *SuperNodesMem,*SuperNodesMem2; |
36 | SegmentsMem *SuperSegmentsMem,*SuperSegmentsMem2; |
37 | WaysMem *SuperWaysMem,*SuperWaysMem2; |
38 | Nodes *OSMNodes; |
39 | Ways *OSMWays; |
40 | Segments *OSMSegments; |
41 | Nodes *SuperNodes,*SuperNodes2; |
42 | Segments *SuperSegments,*SuperSegments2; |
43 | Ways *SuperWays,*SuperWays2; |
44 | int iteration=0,quit=0; |
45 | |
46 | #if !SKIP_PARSING |
47 | |
48 | /* Create new variables */ |
49 | |
50 | OSMNodesMem=NewNodeList(); |
51 | OSMWaysMem=NewWayList(); |
52 | OSMSegmentsMem=NewSegmentList(); |
53 | |
54 | /* Parse the file */ |
55 | |
56 | ParseXML(stdin,OSMNodesMem,OSMSegmentsMem,OSMWaysMem); |
57 | |
58 | /* Sort the variables */ |
59 | |
60 | printf("Sorting All Nodes"); fflush(stdout); |
61 | SortNodeList(OSMNodesMem); |
62 | printf("\rSorted All Nodes \n"); fflush(stdout); |
63 | |
64 | printf("Sorting Ways"); fflush(stdout); |
65 | SortWayList(OSMWaysMem); |
66 | printf("\rSorted Ways \n"); fflush(stdout); |
67 | |
68 | printf("Sorting Segments"); fflush(stdout); |
69 | SortSegmentList(OSMSegmentsMem); |
70 | printf("\rSorted Segments \n"); fflush(stdout); |
71 | |
72 | /* Write out the variables */ |
73 | |
74 | printf("Saving All Nodes"); fflush(stdout); |
75 | OSMNodes=SaveNodeList(OSMNodesMem,"data/all-nodes.mem"); |
76 | printf("\rSaved All Nodes: %d\n",OSMNodes->number); fflush(stdout); |
77 | |
78 | printf("Saving Ways"); fflush(stdout); |
79 | OSMWays=SaveWayList(OSMWaysMem,"data/ways.mem"); |
80 | printf("\rSaved Ways: %d\n",OSMWays->number); fflush(stdout); |
81 | |
82 | /* Remove bad segments */ |
83 | |
84 | RemoveBadSegments(OSMSegmentsMem); |
85 | |
86 | printf("Sorting Segments"); fflush(stdout); |
87 | SortSegmentList(OSMSegmentsMem); |
88 | printf("\rSorted Segments \n"); fflush(stdout); |
89 | |
90 | /* Remove non-way nodes */ |
91 | |
92 | OSMNodesMem=NewNodeList(); |
93 | |
94 | RemoveNonWayNodes(OSMNodesMem,OSMNodes,OSMSegmentsMem->segments); |
95 | |
96 | UnMapFile(OSMNodes); |
97 | |
98 | printf("Sorting Way Nodes"); fflush(stdout); |
99 | SortNodeList(OSMNodesMem); |
100 | printf("\rSorted Way Nodes \n"); fflush(stdout); |
101 | |
102 | printf("Saving Way Nodes"); fflush(stdout); |
103 | OSMNodes=SaveNodeList(OSMNodesMem,"data/nodes.mem"); |
104 | printf("\rSaved Way Nodes: %d\n",OSMNodes->number); fflush(stdout); |
105 | |
106 | /* Fix the segment lengths */ |
107 | |
108 | FixupSegmentLengths(OSMSegmentsMem,OSMNodes,OSMWays); |
109 | |
110 | /* Write out the variables */ |
111 | |
112 | printf("Saving Segments"); fflush(stdout); |
113 | OSMSegments=SaveSegmentList(OSMSegmentsMem,"data/segments.mem"); |
114 | printf("\rSaved Segments: %d\n",OSMSegments->number); fflush(stdout); |
115 | |
116 | #else |
117 | |
118 | /* Load in the data */ |
119 | |
120 | OSMNodes=LoadNodeList("data/nodes.mem"); |
121 | OSMWays=LoadWayList("data/ways.mem"); |
122 | OSMSegments=LoadSegmentList("data/segments.mem"); |
123 | |
124 | #endif |
125 | |
126 | /* Select the super-nodes */ |
127 | |
128 | SuperNodesMem=ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays); |
129 | |
130 | /* Sort the super-nodes */ |
131 | |
132 | printf("Sorting Super-Nodes"); fflush(stdout); |
133 | SortNodeList(SuperNodesMem); |
134 | printf("\rSorted Super-Nodes \n"); fflush(stdout); |
135 | |
136 | /* Write out the variables */ |
137 | |
138 | printf("Saving Super-Nodes"); fflush(stdout); |
139 | SuperNodes=SaveNodeList(SuperNodesMem,"data/super-nodes.mem"); |
140 | printf("\rSaved Super-Nodes: %d\n",SuperNodes->number); fflush(stdout); |
141 | |
142 | /* Select the super-segments */ |
143 | |
144 | SuperSegmentsMem=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,SuperNodes,iteration); |
145 | |
146 | /* Sort the variables */ |
147 | |
148 | printf("Sorting Super-Segments"); fflush(stdout); |
149 | SortSegmentList(SuperSegmentsMem); |
150 | printf("\rSorted Super-Segments \n"); fflush(stdout); |
151 | |
152 | /* Select the super-ways */ |
153 | |
154 | SuperWaysMem=CreateSuperWays(OSMWays,SuperSegmentsMem); |
155 | |
156 | /* Sort the variables */ |
157 | |
158 | printf("Sorting Super-Ways"); fflush(stdout); |
159 | SortWayList(SuperWaysMem); |
160 | printf("\rSorted Super-Ways \n"); fflush(stdout); |
161 | |
162 | /* Write out the variables */ |
163 | |
164 | printf("Saving Super-Segments"); fflush(stdout); |
165 | SuperSegments=SaveSegmentList(SuperSegmentsMem,"data/super-segments.mem"); |
166 | printf("\rSaved Super-Segments: %d\n",SuperSegments->number); fflush(stdout); |
167 | |
168 | printf("Saving Super-Ways"); fflush(stdout); |
169 | SuperWays=SaveWayList(SuperWaysMem,"data/super-ways.mem"); |
170 | printf("\rSaved Super-Ways: %d\n",SuperWays->number); fflush(stdout); |
171 | |
172 | /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */ |
173 | |
174 | UnMapFile(SuperNodes); |
175 | UnMapFile(SuperSegments); |
176 | UnMapFile(SuperWays); |
177 | |
178 | do |
179 | { |
180 | iteration++; |
181 | |
182 | if(iteration>=MAX_ITERATIONS) |
183 | break; |
184 | |
185 | SuperNodes=LoadNodeList("data/super-nodes.mem"); |
186 | SuperWays=LoadWayList("data/super-ways.mem"); |
187 | SuperSegments=LoadSegmentList("data/super-segments.mem"); |
188 | |
189 | /* Select the super-nodes */ |
190 | |
191 | SuperNodesMem2=ChooseSuperNodes(SuperNodes,SuperSegments,SuperWays); |
192 | |
193 | /* Sort the super-nodes */ |
194 | |
195 | printf("Sorting Super-Nodes [iteration %d]",iteration); fflush(stdout); |
196 | SortNodeList(SuperNodesMem2); |
197 | printf("\rSorted Super-Nodes [iteration %d] \n",iteration); fflush(stdout); |
198 | |
199 | /* Write out the variables */ |
200 | |
201 | printf("Saving Super-Nodes [iteration %d]",iteration); fflush(stdout); |
202 | SuperNodes2=SaveNodeList(SuperNodesMem2,"data/super-nodes2.mem"); |
203 | printf("\rSaved Super-Nodes [iteration %d]: %d\n",iteration,SuperNodes2->number); fflush(stdout); |
204 | |
205 | /* Select the super-segments */ |
206 | |
207 | SuperSegmentsMem2=CreateSuperSegments(SuperNodes,SuperSegments,SuperWays,SuperNodes2,iteration); |
208 | |
209 | /* Sort the variables */ |
210 | |
211 | printf("Sorting Super-Segments [iteration %d]",iteration); fflush(stdout); |
212 | SortSegmentList(SuperSegmentsMem2); |
213 | printf("\rSorted Super-Segments [iteration %d] \n",iteration); fflush(stdout); |
214 | |
215 | /* Select the super-ways */ |
216 | |
217 | SuperWaysMem2=CreateSuperWays(SuperWays,SuperSegmentsMem2); |
218 | |
219 | /* Sort the variables */ |
220 | |
221 | printf("Sorting Super-Ways [iteration %d]",iteration); fflush(stdout); |
222 | SortWayList(SuperWaysMem2); |
223 | printf("\rSorted Super-Ways [iteration %d] \n",iteration); fflush(stdout); |
224 | |
225 | /* Write out the variables */ |
226 | |
227 | printf("Saving Super-Segments [iteration %d]",iteration); fflush(stdout); |
228 | SuperSegments2=SaveSegmentList(SuperSegmentsMem2,"data/super-segments2.mem"); |
229 | printf("\rSaved Super-Segments [iteration %d]: %d\n",iteration,SuperSegments2->number); fflush(stdout); |
230 | |
231 | printf("Saving Super-Ways [iteration %d]",iteration); fflush(stdout); |
232 | SuperWays2=SaveWayList(SuperWaysMem2,"data/super-ways2.mem"); |
233 | printf("\rSaved Super-Ways [iteration %d]: %d\n",iteration,SuperWays2->number); fflush(stdout); |
234 | |
235 | /* Decide when to quit */ |
236 | |
237 | quit=0; |
238 | if(SuperNodes2->number>(0.95*SuperNodes->number)) quit=1; |
239 | if(SuperSegments2->number>(0.95*SuperSegments->number)) quit=1; |
240 | |
241 | /* Rename the files and unmap the data */ |
242 | |
243 | UnMapFile(SuperNodes); |
244 | UnMapFile(SuperSegments); |
245 | UnMapFile(SuperWays); |
246 | |
247 | UnMapFile(SuperNodes2); |
248 | UnMapFile(SuperSegments2); |
249 | UnMapFile(SuperWays2); |
250 | |
251 | rename("data/super-nodes2.mem","data/super-nodes.mem"); |
252 | rename("data/super-segments2.mem","data/super-segments.mem"); |
253 | rename("data/super-ways2.mem","data/super-ways.mem"); |
254 | } |
255 | while(!quit); |
256 | |
257 | UnMapFile(OSMNodes); |
258 | UnMapFile(OSMSegments); |
259 | UnMapFile(OSMWays); |
260 | |
261 | return(0); |
262 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |