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 166 - (show annotations) (download) (as text)
Thu Apr 30 17:29:03 2009 UTC (15 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 5983 byte(s)
First attempt at preferences for highways - uses integer arithmetic and doesn't
work well.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.36 2009-04-30 17:29:02 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 "types.h"
30 #include "functions.h"
31 #include "nodesx.h"
32 #include "segmentsx.h"
33 #include "waysx.h"
34 #include "superx.h"
35 #include "profiles.h"
36
37
38 int main(int argc,char** argv)
39 {
40 NodesX *OSMNodes;
41 SegmentsX *OSMSegments,*SuperSegments=NULL;
42 WaysX *OSMWays;
43 int iteration=0,quit=0;
44 int max_iterations=10;
45 char *dirname=NULL,*prefix=NULL;
46 Profile profile;
47 int i;
48
49 /* Fill in the default profile. */
50
51 profile.transport=Transport_None; /* Not used by planetsplitter */
52
53 profile.allow=Allow_ALL;
54
55 for(i=1;i<Way_Unknown;i++)
56 profile.highway[i]=1;
57
58 for(i=1;i<Way_Unknown;i++)
59 profile.speed[i]=0; /* Not used by planetsplitter */
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("\nParsing OSM Data\n================\n\n"); fflush(stdout);
116
117 ParseXML(stdin,OSMNodes,OSMSegments,OSMWays,&profile);
118
119 printf("\nProcessing OSM Data\n===================\n\n"); fflush(stdout);
120
121 /* Sort the ways */
122
123 SortWayList(OSMWays);
124
125 /* Sort the segments */
126
127 SortSegmentList(OSMSegments);
128
129 /* Remove bad segments */
130
131 RemoveBadSegments(OSMSegments);
132
133 SortSegmentList(OSMSegments);
134
135 /* Remove non-way nodes */
136
137 RemoveNonHighwayNodes(OSMNodes,OSMSegments);
138
139 SortNodeList(OSMNodes);
140
141 /* Measure the segments */
142
143 MeasureSegments(OSMSegments,OSMNodes);
144
145
146 /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */
147
148 do
149 {
150 printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":""); fflush(stdout);
151
152 if(iteration==0)
153 {
154 /* Select the super-nodes */
155
156 ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays,iteration);
157
158 /* Select the super-segments */
159
160 SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,iteration);
161 }
162 else
163 {
164 SegmentsX *SuperSegments2;
165
166 /* Select the super-nodes */
167
168 ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays,iteration);
169
170 /* Select the super-segments */
171
172 SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays,iteration);
173
174 if(SuperSegments->number==SuperSegments2->number)
175 quit=1;
176
177 FreeSegmentList(SuperSegments);
178
179 SuperSegments=SuperSegments2;
180 }
181
182 /* Sort the super-segments */
183
184 SortSegmentList(SuperSegments);
185
186 iteration++;
187
188 if(iteration>max_iterations)
189 quit=1;
190 }
191 while(!quit);
192
193 printf("\n"); fflush(stdout);
194
195 /* Mark the super-nodes */
196
197 MarkSuperNodes(OSMNodes,iteration);
198
199 /* Merge the super-segments */
200
201 MergeSuperSegments(OSMSegments,SuperSegments);
202
203 FreeSegmentList(SuperSegments);
204
205 /* Sort the segments */
206
207 SortSegmentList(OSMSegments);
208
209 /* Rotate segments so that node1<node2 */
210
211 RotateSegments(OSMSegments,OSMNodes);
212
213 /* Sort the segments */
214
215 SortSegmentList(OSMSegments);
216
217 /* Remove duplicated segments */
218
219 DeduplicateSegments(OSMSegments,OSMNodes,OSMWays);
220
221 /* Sort the segments */
222
223 SortSegmentList(OSMSegments);
224
225 /* Fix the segment and node indexes */
226
227 IndexNodes(OSMNodes,OSMSegments);
228
229 IndexSegments(OSMSegments,OSMNodes);
230
231 /* Write out the nodes */
232
233 SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem"));
234
235 /* Write out the segments */
236
237 SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem"));
238
239 /* Write out the ways */
240
241 SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem"));
242
243 return(0);
244 }

Properties

Name Value
cvs:description Planet file splitter.