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 96 - (show annotations) (download) (as text)
Sat Jan 31 15:32:42 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 6544 byte(s)
Intermediate version during code cleanup.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.27 2009-01-31 15:32:41 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 #include <string.h>
18
19 #include "types.h"
20 #include "nodes.h"
21 #include "segments.h"
22 #include "ways.h"
23 #include "profiles.h"
24 #include "functions.h"
25
26
27 int main(int argc,char** argv)
28 {
29 NodesMem *OSMNodesMem;
30 SegmentsMem *OSMSegmentsMem,*SuperSegmentsMem=NULL;
31 WaysMem *OSMWaysMem;
32 int iteration=0,quit=0;
33 int help_profile=0,max_iterations=5;
34 char *dirname=NULL,*prefix=NULL,*filename;
35 Profile profile;
36 int i;
37
38 /* Fill in the default profile. */
39
40 profile.transport=Transport_None; /* Not used by planetsplitter */
41
42 profile.allow=Allow_ALL;
43
44 for(i=1;i<Way_Unknown;i++)
45 profile.highways[i]=1;
46
47 for(i=1;i<Way_Unknown;i++)
48 profile.speed[i]=0; /* Not used by planetsplitter */
49
50 profile.oneway=1; /* Not used by planetsplitter */
51
52 /* Parse the command line arguments */
53
54 while(--argc>=1)
55 {
56 if(!strcmp(argv[argc],"-help"))
57 goto usage;
58 else if(!strcmp(argv[argc],"-help-profile"))
59 help_profile=1;
60 else if(!strncmp(argv[argc],"-dir=",5))
61 dirname=&argv[argc][5];
62 else if(!strncmp(argv[argc],"-prefix=",8))
63 prefix=&argv[argc][8];
64 else if(!strncmp(argv[argc],"-max-iterations=",16))
65 max_iterations=atoi(&argv[argc][16]);
66 else if(!strncmp(argv[argc],"-transport=",11))
67 {
68 profile.transport=TransportType(&argv[argc][11]);
69 profile.allow=1<<(profile.transport-1);
70 }
71 else if(!strncmp(argv[argc],"-not-highway=",13))
72 {
73 Highway highway=HighwayType(&argv[argc][13]);
74 profile.highways[highway]=0;
75 }
76 else
77 {
78 usage:
79
80 fprintf(stderr,"Usage: planetsplitter\n"
81 " [-help] [-help-profile]\n"
82 " [-dir=<name>] [-prefix=<name>]\n"
83 " [-max-iterations=<number>]\n"
84 " [-transport=<transport>]\n"
85 " [-not-highway=<highway> ...]\n"
86 "\n"
87 "<transport> defaults to all but can be set to:\n"
88 "%s"
89 "\n"
90 "<highway> can be selected from:\n"
91 "%s",
92 TransportList(),HighwayList());
93
94 return(1);
95 }
96 }
97
98 if(help_profile)
99 {
100 PrintProfile(&profile);
101
102 return(0);
103 }
104
105 /* Create new variables */
106
107 OSMNodesMem=NewNodeList();
108 OSMSegmentsMem=NewSegmentList();
109 OSMWaysMem=NewWayList();
110
111 /* Parse the file */
112
113 printf("\nParsing OSM Data\n================\n\n"); fflush(stdout);
114
115 ParseXML(stdin,OSMNodesMem,OSMSegmentsMem,OSMWaysMem,&profile);
116
117 printf("\nProcessing OSM Data\n===================\n\n"); fflush(stdout);
118
119 /* Sort the ways */
120
121 printf("Sorting Ways"); fflush(stdout);
122 SortWayList(OSMWaysMem);
123 printf("\rSorted Ways \n"); fflush(stdout);
124
125 /* Sort the segments */
126
127 printf("Sorting Segments"); fflush(stdout);
128 SortSegmentList(OSMSegmentsMem);
129 printf("\rSorted Segments \n"); fflush(stdout);
130
131 /* Remove bad segments */
132
133 RemoveBadSegments(OSMSegmentsMem);
134
135 printf("Sorting Segments"); fflush(stdout);
136 SortSegmentList(OSMSegmentsMem);
137 printf("\rSorted Segments \n"); fflush(stdout);
138
139 /* Remove non-way nodes */
140
141 RemoveNonHighwayNodes(OSMNodesMem,OSMSegmentsMem);
142
143 printf("Sorting Nodes"); fflush(stdout);
144 SortNodeList(OSMNodesMem);
145 printf("\rSorted Nodes \n"); fflush(stdout);
146
147 /* Measure the segments */
148
149 MeasureSegments(OSMSegmentsMem,OSMNodesMem);
150
151
152 /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */
153
154 do
155 {
156 printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":""); fflush(stdout);
157
158 if(iteration==0)
159 {
160 /* Select the super-nodes */
161
162 ChooseSuperNodes(OSMNodesMem,OSMSegmentsMem,OSMWaysMem,iteration);
163
164 /* Select the super-segments */
165
166 SuperSegmentsMem=CreateSuperSegments(OSMNodesMem,OSMSegmentsMem,OSMWaysMem,iteration);
167 }
168 else
169 {
170 SegmentsMem *SuperSegmentsMem2;
171
172 /* Select the super-nodes */
173
174 ChooseSuperNodes(OSMNodesMem,SuperSegmentsMem,OSMWaysMem,iteration);
175
176 /* Select the super-segments */
177
178 SuperSegmentsMem2=CreateSuperSegments(OSMNodesMem,SuperSegmentsMem,OSMWaysMem,iteration);
179
180 FreeSegmentList(SuperSegmentsMem);
181
182 SuperSegmentsMem=SuperSegmentsMem2;
183 }
184
185 /* Sort the super-segments */
186
187 printf("Sorting Super-Segments"); fflush(stdout);
188 SortSegmentList(SuperSegmentsMem);
189 printf("\rSorted Super-Segments \n"); fflush(stdout);
190
191 iteration++;
192
193 if(iteration>max_iterations)
194 quit=1;
195 }
196 while(!quit);
197
198
199 /* Fix the node indexes */
200
201 FixupSegments(OSMSegmentsMem,OSMNodesMem,SuperSegmentsMem);
202
203 FreeSegmentList(SuperSegmentsMem);
204
205 /* Sort the segments */
206
207 printf("Sorting Segments"); fflush(stdout);
208 SortSegmentList(OSMSegmentsMem);
209 printf("\rSorted Segments \n"); fflush(stdout);
210
211 /* Fix the segment indexes */
212
213 FixupNodes(OSMNodesMem,OSMSegmentsMem,iteration);
214
215 /* Write out the nodes */
216
217 filename=(char*)malloc((dirname?strlen(dirname):0)+(prefix?strlen(prefix):0)+16);
218
219 printf("Saving Nodes"); fflush(stdout);
220 sprintf(filename,"%s%s%s%snodes.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":"");
221 SaveNodeList(OSMNodesMem,filename);
222 printf("\rSaved Nodes: %d\n",OSMNodesMem->number); fflush(stdout);
223
224 /* Write out the segments */
225
226 printf("Saving Segments"); fflush(stdout);
227 sprintf(filename,"%s%s%s%ssegments.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":"");
228 SaveSegmentList(OSMSegmentsMem,filename);
229 printf("\rSaved Segments: %d\n",OSMSegmentsMem->number); fflush(stdout);
230
231 /* Write out the ways */
232
233 printf("Saving Ways"); fflush(stdout);
234 sprintf(filename,"%s%s%s%sways.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":"");
235 SaveWayList(OSMWaysMem,filename);
236 printf("\rSaved Ways: %d\n",OSMWaysMem->number); fflush(stdout);
237
238 return(0);
239 }

Properties

Name Value
cvs:description Planet file splitter.