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/visualiser.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1002 - (hide annotations) (download) (as text)
Tue Jun 5 13:17:42 2012 UTC (12 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 22118 byte(s)
Add an option to the visualiser to display segments accessible to each of the
transport types.

1 amb 184 /***************************************
2     Extract data from Routino.
3    
4     Part of the Routino routing software.
5     ******************/ /******************
6 amb 955 This file Copyright 2008-2012 Andrew M. Bishop
7 amb 184
8     This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU Affero General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12    
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     GNU Affero General Public License for more details.
17    
18     You should have received a copy of the GNU Affero General Public License
19     along with this program. If not, see <http://www.gnu.org/licenses/>.
20     ***************************************/
21    
22    
23     #include <stdio.h>
24     #include <stdlib.h>
25     #include <string.h>
26    
27     #include "types.h"
28     #include "nodes.h"
29     #include "segments.h"
30     #include "ways.h"
31 amb 623 #include "relations.h"
32 amb 184
33 amb 955 #include "visualiser.h"
34 amb 184
35 amb 955
36 amb 934 /*+ The maximum number of segments per node (used to size temporary storage). +*/
37     #define MAX_SEG_PER_NODE 32
38    
39 amb 760 /* Limit types */
40    
41 amb 184 #define SPEED_LIMIT 1
42     #define WEIGHT_LIMIT 2
43     #define HEIGHT_LIMIT 3
44     #define WIDTH_LIMIT 4
45     #define LENGTH_LIMIT 5
46    
47     /* Local types */
48    
49 amb 219 typedef void (*callback_t)(index_t node,double latitude,double longitude);
50 amb 184
51     /* Local variables */
52    
53 amb 623 static Nodes *OSMNodes;
54     static Segments *OSMSegments;
55     static Ways *OSMWays;
56     static Relations *OSMRelations;
57 amb 184
58 amb 219 static double LatMin;
59     static double LatMax;
60     static double LonMin;
61     static double LonMax;
62 amb 217
63 amb 184 static int limit_type=0;
64 amb 1002 static Transports transports=Transports_None;
65 amb 184
66     /* Local functions */
67    
68 amb 217 static void find_all_nodes(Nodes *nodes,callback_t callback);
69 amb 219 static void output_junctions(index_t node,double latitude,double longitude);
70     static void output_super(index_t node,double latitude,double longitude);
71     static void output_oneway(index_t node,double latitude,double longitude);
72 amb 1002 static void output_transport(index_t node,double latitude,double longitude);
73 amb 623 static void output_turnrestriction(index_t node,double latitude,double longitude);
74 amb 219 static void output_limits(index_t node,double latitude,double longitude);
75 amb 184
76    
77     /*++++++++++++++++++++++++++++++++++++++
78     Output the data for junctions.
79    
80     Nodes *nodes The set of nodes to use.
81    
82     Segments *segments The set of segments to use.
83    
84     Ways *ways The set of ways to use.
85    
86 amb 680 Relations *relations The set of relations to use.
87 amb 623
88 amb 219 double latmin The minimum latitude.
89 amb 184
90 amb 219 double latmax The maximum latitude.
91 amb 184
92 amb 219 double lonmin The minimum longitude.
93 amb 184
94 amb 219 double lonmax The maximum longitude.
95 amb 184 ++++++++++++++++++++++++++++++++++++++*/
96    
97 amb 623 void OutputJunctions(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
98 amb 184 {
99     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
100    
101     OSMNodes=nodes;
102     OSMSegments=segments;
103     OSMWays=ways;
104 amb 623 OSMRelations=relations;
105 amb 184
106 amb 217 LatMin=latmin;
107     LatMax=latmax;
108     LonMin=lonmin;
109     LonMax=lonmax;
110    
111 amb 184 /* Iterate through the nodes and process them */
112    
113 amb 217 find_all_nodes(nodes,(callback_t)output_junctions);
114 amb 184 }
115    
116    
117     /*++++++++++++++++++++++++++++++++++++++
118 amb 680 Process a single node as a junction (called as a callback).
119 amb 184
120     index_t node The node to output.
121    
122 amb 219 double latitude The latitude of the node.
123 amb 184
124 amb 219 double longitude The longitude of the node.
125 amb 184 ++++++++++++++++++++++++++++++++++++++*/
126    
127 amb 219 static void output_junctions(index_t node,double latitude,double longitude)
128 amb 184 {
129 amb 885 Node *nodep=LookupNode(OSMNodes,node,1);
130 amb 184 Segment *segment;
131     Way *firstway;
132     int count=0,difference=0;
133    
134 amb 885 segment=FirstSegment(OSMSegments,nodep,1);
135 amb 460 firstway=LookupWay(OSMWays,segment->way,1);
136 amb 184
137     do
138     {
139 amb 460 Way *way=LookupWay(OSMWays,segment->way,2);
140 amb 184
141     if(IsNormalSegment(segment))
142     count++;
143    
144 amb 201 if(WaysCompare(firstway,way))
145 amb 184 difference=1;
146    
147     segment=NextSegment(OSMSegments,segment,node);
148     }
149     while(segment);
150    
151     if(count!=2 || difference)
152 amb 198 printf("%.6f %.6f %d\n",radians_to_degrees(latitude),radians_to_degrees(longitude),count);
153 amb 184 }
154    
155    
156     /*++++++++++++++++++++++++++++++++++++++
157     Output the data for super-nodes and super-segments.
158    
159     Nodes *nodes The set of nodes to use.
160    
161     Segments *segments The set of segments to use.
162    
163     Ways *ways The set of ways to use.
164    
165 amb 680 Relations *relations The set of relations to use.
166 amb 623
167 amb 219 double latmin The minimum latitude.
168 amb 184
169 amb 219 double latmax The maximum latitude.
170 amb 184
171 amb 219 double lonmin The minimum longitude.
172 amb 184
173 amb 219 double lonmax The maximum longitude.
174 amb 184 ++++++++++++++++++++++++++++++++++++++*/
175    
176 amb 623 void OutputSuper(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
177 amb 184 {
178     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
179    
180     OSMNodes=nodes;
181     OSMSegments=segments;
182     OSMWays=ways;
183 amb 623 OSMRelations=relations;
184 amb 184
185 amb 217 LatMin=latmin;
186     LatMax=latmax;
187     LonMin=lonmin;
188     LonMax=lonmax;
189    
190 amb 184 /* Iterate through the nodes and process them */
191    
192 amb 217 find_all_nodes(nodes,(callback_t)output_super);
193 amb 184 }
194    
195    
196     /*++++++++++++++++++++++++++++++++++++++
197 amb 680 Process a single node as a super-node (called as a callback).
198 amb 184
199     index_t node The node to output.
200    
201 amb 219 double latitude The latitude of the node.
202 amb 184
203 amb 219 double longitude The longitude of the node.
204 amb 184 ++++++++++++++++++++++++++++++++++++++*/
205    
206 amb 219 static void output_super(index_t node,double latitude,double longitude)
207 amb 184 {
208 amb 885 Node *nodep=LookupNode(OSMNodes,node,1);
209 amb 184 Segment *segment;
210    
211 amb 885 if(!IsSuperNode(nodep))
212 amb 184 return;
213    
214 amb 198 printf("%.6f %.6f n\n",radians_to_degrees(latitude),radians_to_degrees(longitude));
215 amb 188
216 amb 885 segment=FirstSegment(OSMSegments,nodep,1);
217 amb 184
218     do
219     {
220     if(IsSuperSegment(segment))
221     {
222     index_t othernode=OtherNode(segment,node);
223 amb 219 double lat,lon;
224 amb 184
225 amb 217 GetLatLong(OSMNodes,othernode,&lat,&lon);
226 amb 184
227 amb 217 if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax))
228 amb 198 printf("%.6f %.6f s\n",radians_to_degrees(lat),radians_to_degrees(lon));
229 amb 184 }
230    
231     segment=NextSegment(OSMSegments,segment,node);
232     }
233     while(segment);
234     }
235    
236    
237     /*++++++++++++++++++++++++++++++++++++++
238     Output the data for one-way segments.
239    
240     Nodes *nodes The set of nodes to use.
241    
242     Segments *segments The set of segments to use.
243    
244     Ways *ways The set of ways to use.
245    
246 amb 680 Relations *relations The set of relations to use.
247 amb 623
248 amb 219 double latmin The minimum latitude.
249 amb 184
250 amb 219 double latmax The maximum latitude.
251 amb 184
252 amb 219 double lonmin The minimum longitude.
253 amb 184
254 amb 219 double lonmax The maximum longitude.
255 amb 184 ++++++++++++++++++++++++++++++++++++++*/
256    
257 amb 623 void OutputOneway(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
258 amb 184 {
259     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
260    
261     OSMNodes=nodes;
262     OSMSegments=segments;
263     OSMWays=ways;
264 amb 623 OSMRelations=relations;
265 amb 184
266 amb 217 LatMin=latmin;
267     LatMax=latmax;
268     LonMin=lonmin;
269     LonMax=lonmax;
270    
271 amb 184 /* Iterate through the nodes and process them */
272    
273 amb 217 find_all_nodes(nodes,(callback_t)output_oneway);
274 amb 184 }
275    
276    
277     /*++++++++++++++++++++++++++++++++++++++
278 amb 680 Process a single node and all connected one-way segments (called as a callback).
279 amb 184
280     index_t node The node to output.
281    
282 amb 219 double latitude The latitude of the node.
283 amb 184
284 amb 219 double longitude The longitude of the node.
285 amb 184 ++++++++++++++++++++++++++++++++++++++*/
286    
287 amb 219 static void output_oneway(index_t node,double latitude,double longitude)
288 amb 184 {
289 amb 885 Node *nodep=LookupNode(OSMNodes,node,1);
290 amb 184 Segment *segment;
291    
292 amb 885 segment=FirstSegment(OSMSegments,nodep,1);
293 amb 184
294     do
295     {
296     if(IsNormalSegment(segment))
297     {
298     index_t othernode=OtherNode(segment,node);
299    
300     if(node>othernode)
301     {
302 amb 219 double lat,lon;
303 amb 184
304     GetLatLong(OSMNodes,othernode,&lat,&lon);
305    
306     if(IsOnewayFrom(segment,node))
307 amb 198 printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
308 amb 184 else if(IsOnewayFrom(segment,othernode))
309 amb 198 printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(lat),radians_to_degrees(lon),radians_to_degrees(latitude),radians_to_degrees(longitude));
310 amb 184 }
311     }
312    
313     segment=NextSegment(OSMSegments,segment,node);
314     }
315     while(segment);
316     }
317    
318    
319     /*++++++++++++++++++++++++++++++++++++++
320 amb 1002 Output the data for segments allowed for a paticular type of traffic.
321    
322     Nodes *nodes The set of nodes to use.
323    
324     Segments *segments The set of segments to use.
325    
326     Ways *ways The set of ways to use.
327    
328     Relations *relations The set of relations to use.
329    
330     double latmin The minimum latitude.
331    
332     double latmax The maximum latitude.
333    
334     double lonmin The minimum longitude.
335    
336     double lonmax The maximum longitude.
337    
338     Transport transport The type of transport.
339     ++++++++++++++++++++++++++++++++++++++*/
340    
341     void OutputTransport(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Transport transport)
342     {
343     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
344    
345     OSMNodes=nodes;
346     OSMSegments=segments;
347     OSMWays=ways;
348     OSMRelations=relations;
349    
350     LatMin=latmin;
351     LatMax=latmax;
352     LonMin=lonmin;
353     LonMax=lonmax;
354    
355     /* Iterate through the nodes and process them */
356    
357     transports=TRANSPORTS(transport);
358    
359     find_all_nodes(nodes,(callback_t)output_transport);
360     }
361    
362    
363     /*++++++++++++++++++++++++++++++++++++++
364     Process a single node and all connected one-way segments (called as a callback).
365    
366     index_t node The node to output.
367    
368     double latitude The latitude of the node.
369    
370     double longitude The longitude of the node.
371     ++++++++++++++++++++++++++++++++++++++*/
372    
373     static void output_transport(index_t node,double latitude,double longitude)
374     {
375     Node *nodep=LookupNode(OSMNodes,node,1);
376     Segment *segment;
377    
378     segment=FirstSegment(OSMSegments,nodep,1);
379    
380     do
381     {
382     if(IsNormalSegment(segment))
383     {
384     index_t othernode=OtherNode(segment,node);
385    
386     if(node>othernode)
387     {
388     Way *way=LookupWay(OSMWays,segment->way,1);
389    
390     if(way->allow&transports)
391     {
392     double lat,lon;
393    
394     GetLatLong(OSMNodes,othernode,&lat,&lon);
395    
396     printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
397     }
398     }
399     }
400    
401     segment=NextSegment(OSMSegments,segment,node);
402     }
403     while(segment);
404     }
405    
406    
407     /*++++++++++++++++++++++++++++++++++++++
408 amb 623 Output the data for turn restrictions.
409    
410     Nodes *nodes The set of nodes to use.
411    
412     Segments *segments The set of segments to use.
413    
414     Ways *ways The set of ways to use.
415    
416 amb 680 Relations *relations The set of relations to use.
417 amb 623
418     double latmin The minimum latitude.
419    
420     double latmax The maximum latitude.
421    
422     double lonmin The minimum longitude.
423    
424     double lonmax The maximum longitude.
425     ++++++++++++++++++++++++++++++++++++++*/
426    
427     void OutputTurnRestrictions(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
428     {
429     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
430    
431     OSMNodes=nodes;
432     OSMSegments=segments;
433     OSMWays=ways;
434     OSMRelations=relations;
435    
436     LatMin=latmin;
437     LatMax=latmax;
438     LonMin=lonmin;
439     LonMax=lonmax;
440    
441     /* Iterate through the nodes and process them */
442    
443     find_all_nodes(nodes,(callback_t)output_turnrestriction);
444     }
445    
446    
447     /*++++++++++++++++++++++++++++++++++++++
448 amb 680 Process a single node as the 'via' node for a turn restriction (called as a callback).
449 amb 623
450     index_t node The node to output.
451    
452     double latitude The latitude of the node.
453    
454     double longitude The longitude of the node.
455     ++++++++++++++++++++++++++++++++++++++*/
456    
457     static void output_turnrestriction(index_t node,double latitude,double longitude)
458     {
459 amb 885 Node *nodep=LookupNode(OSMNodes,node,1);
460 amb 623 index_t turnrelation=NO_RELATION;
461    
462 amb 885 if(!IsTurnRestrictedNode(nodep))
463 amb 623 return;
464    
465     turnrelation=FindFirstTurnRelation1(OSMRelations,node);
466    
467     do
468     {
469     TurnRelation *relation;
470     Segment *from_segment,*to_segment;
471     index_t from_node,to_node;
472     double from_lat,from_lon,to_lat,to_lon;
473    
474     relation=LookupTurnRelation(OSMRelations,turnrelation,1);
475    
476     from_segment=LookupSegment(OSMSegments,relation->from,1);
477 amb 707 to_segment =LookupSegment(OSMSegments,relation->to ,2);
478 amb 623
479     from_node=OtherNode(from_segment,node);
480     to_node=OtherNode(to_segment,node);
481    
482     GetLatLong(OSMNodes,from_node,&from_lat,&from_lon);
483     GetLatLong(OSMNodes,to_node,&to_lat,&to_lon);
484    
485     printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",radians_to_degrees(from_lat),radians_to_degrees(from_lon),
486     radians_to_degrees(latitude),radians_to_degrees(longitude),
487     radians_to_degrees(to_lat),radians_to_degrees(to_lon));
488    
489     turnrelation=FindNextTurnRelation1(OSMRelations,turnrelation);
490     }
491     while(turnrelation!=NO_RELATION);
492     }
493    
494    
495     /*++++++++++++++++++++++++++++++++++++++
496 amb 184 Output the data for speed limits.
497    
498     Nodes *nodes The set of nodes to use.
499    
500     Segments *segments The set of segments to use.
501    
502     Ways *ways The set of ways to use.
503    
504 amb 680 Relations *relations The set of relations to use.
505 amb 623
506 amb 219 double latmin The minimum latitude.
507 amb 184
508 amb 219 double latmax The maximum latitude.
509 amb 184
510 amb 219 double lonmin The minimum longitude.
511 amb 184
512 amb 219 double lonmax The maximum longitude.
513 amb 184 ++++++++++++++++++++++++++++++++++++++*/
514    
515 amb 623 void OutputSpeedLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
516 amb 184 {
517     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
518    
519     OSMNodes=nodes;
520     OSMSegments=segments;
521     OSMWays=ways;
522 amb 623 OSMRelations=relations;
523 amb 184
524 amb 217 LatMin=latmin;
525     LatMax=latmax;
526     LonMin=lonmin;
527     LonMax=lonmax;
528    
529 amb 184 /* Iterate through the nodes and process them */
530    
531     limit_type=SPEED_LIMIT;
532    
533 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
534 amb 184 }
535    
536    
537     /*++++++++++++++++++++++++++++++++++++++
538     Output the data for weight limits.
539    
540     Nodes *nodes The set of nodes to use.
541    
542     Segments *segments The set of segments to use.
543    
544     Ways *ways The set of ways to use.
545    
546 amb 680 Relations *relations The set of relations to use.
547 amb 623
548 amb 219 double latmin The minimum latitude.
549 amb 184
550 amb 219 double latmax The maximum latitude.
551 amb 184
552 amb 219 double lonmin The minimum longitude.
553 amb 184
554 amb 219 double lonmax The maximum longitude.
555 amb 184 ++++++++++++++++++++++++++++++++++++++*/
556    
557 amb 623 void OutputWeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
558 amb 184 {
559     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
560    
561     OSMNodes=nodes;
562     OSMSegments=segments;
563     OSMWays=ways;
564 amb 623 OSMRelations=relations;
565 amb 184
566 amb 217 LatMin=latmin;
567     LatMax=latmax;
568     LonMin=lonmin;
569     LonMax=lonmax;
570    
571 amb 184 /* Iterate through the nodes and process them */
572    
573     limit_type=WEIGHT_LIMIT;
574    
575 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
576 amb 184 }
577    
578    
579     /*++++++++++++++++++++++++++++++++++++++
580     Output the data for height limits.
581    
582     Nodes *nodes The set of nodes to use.
583    
584     Segments *segments The set of segments to use.
585    
586     Ways *ways The set of ways to use.
587    
588 amb 680 Relations *relations The set of relations to use.
589 amb 623
590 amb 219 double latmin The minimum latitude.
591 amb 184
592 amb 219 double latmax The maximum latitude.
593 amb 184
594 amb 219 double lonmin The minimum longitude.
595 amb 184
596 amb 219 double lonmax The maximum longitude.
597 amb 184 ++++++++++++++++++++++++++++++++++++++*/
598    
599 amb 623 void OutputHeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
600 amb 184 {
601     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
602    
603     OSMNodes=nodes;
604     OSMSegments=segments;
605     OSMWays=ways;
606 amb 623 OSMRelations=relations;
607 amb 184
608 amb 217 LatMin=latmin;
609     LatMax=latmax;
610     LonMin=lonmin;
611     LonMax=lonmax;
612    
613 amb 184 /* Iterate through the nodes and process them */
614    
615     limit_type=HEIGHT_LIMIT;
616    
617 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
618 amb 184 }
619    
620    
621     /*++++++++++++++++++++++++++++++++++++++
622     Output the data for width limits.
623    
624     Nodes *nodes The set of nodes to use.
625    
626     Segments *segments The set of segments to use.
627    
628     Ways *ways The set of ways to use.
629    
630 amb 680 Relations *relations The set of relations to use.
631 amb 623
632 amb 219 double latmin The minimum latitude.
633 amb 184
634 amb 219 double latmax The maximum latitude.
635 amb 184
636 amb 219 double lonmin The minimum longitude.
637 amb 184
638 amb 219 double lonmax The maximum longitude.
639 amb 184 ++++++++++++++++++++++++++++++++++++++*/
640    
641 amb 623 void OutputWidthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
642 amb 184 {
643     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
644    
645     OSMNodes=nodes;
646     OSMSegments=segments;
647     OSMWays=ways;
648 amb 623 OSMRelations=relations;
649 amb 184
650 amb 217 LatMin=latmin;
651     LatMax=latmax;
652     LonMin=lonmin;
653     LonMax=lonmax;
654    
655 amb 184 /* Iterate through the nodes and process them */
656    
657     limit_type=WIDTH_LIMIT;
658    
659 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
660 amb 184 }
661    
662    
663     /*++++++++++++++++++++++++++++++++++++++
664     Output the data for length limits.
665    
666     Nodes *nodes The set of nodes to use.
667    
668     Segments *segments The set of segments to use.
669    
670     Ways *ways The set of ways to use.
671    
672 amb 680 Relations *relations The set of relations to use.
673 amb 623
674 amb 219 double latmin The minimum latitude.
675 amb 184
676 amb 219 double latmax The maximum latitude.
677 amb 184
678 amb 219 double lonmin The minimum longitude.
679 amb 184
680 amb 219 double lonmax The maximum longitude.
681 amb 184 ++++++++++++++++++++++++++++++++++++++*/
682    
683 amb 623 void OutputLengthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
684 amb 184 {
685     /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
686    
687     OSMNodes=nodes;
688     OSMSegments=segments;
689     OSMWays=ways;
690 amb 623 OSMRelations=relations;
691 amb 184
692 amb 217 LatMin=latmin;
693     LatMax=latmax;
694     LonMin=lonmin;
695     LonMax=lonmax;
696    
697 amb 184 /* Iterate through the nodes and process them */
698    
699     limit_type=LENGTH_LIMIT;
700    
701 amb 217 find_all_nodes(nodes,(callback_t)output_limits);
702 amb 184 }
703    
704    
705     /*++++++++++++++++++++++++++++++++++++++
706 amb 680 Process a single node as a speed, weight, height, length, width limit (called as a callback).
707 amb 184
708     index_t node The node to output.
709    
710 amb 219 double latitude The latitude of the node.
711 amb 184
712 amb 219 double longitude The longitude of the node.
713 amb 184 ++++++++++++++++++++++++++++++++++++++*/
714    
715 amb 219 static void output_limits(index_t node,double latitude,double longitude)
716 amb 184 {
717 amb 885 Node *nodep=LookupNode(OSMNodes,node,1);
718 amb 934 Segment *segment,segments[MAX_SEG_PER_NODE];
719     int limits[MAX_SEG_PER_NODE];
720 amb 184 int count=0;
721     int i,j,same=0;
722    
723 amb 885 segment=FirstSegment(OSMSegments,nodep,1);
724 amb 184
725     do
726     {
727 amb 934 if(IsNormalSegment(segment) && count<MAX_SEG_PER_NODE)
728 amb 184 {
729 amb 934 Way *way=LookupWay(OSMWays,segment->way,1);
730 amb 184
731 amb 934 segments[count]=*segment;
732    
733 amb 184 switch(limit_type)
734     {
735 amb 934 case SPEED_LIMIT: limits[count]=way->speed; break;
736     case WEIGHT_LIMIT: limits[count]=way->weight; break;
737     case HEIGHT_LIMIT: limits[count]=way->height; break;
738     case WIDTH_LIMIT: limits[count]=way->width; break;
739     case LENGTH_LIMIT: limits[count]=way->length; break;
740 amb 184 }
741    
742 amb 934 if(limits[count] || HIGHWAY(way->type)<Way_Track)
743 amb 217 count++;
744 amb 184 }
745    
746     segment=NextSegment(OSMSegments,segment,node);
747     }
748     while(segment);
749    
750     /* Nodes with only one limit are not interesting */
751    
752     if(count==1)
753     return;
754    
755 amb 934 /* Nodes with all segments the same limit are not interesting */
756 amb 184
757     same=0;
758     for(j=0;j<count;j++)
759     if(limits[0]==limits[j])
760     same++;
761    
762     if(same==count)
763     return;
764    
765 amb 934 /* Display the interesting limits */
766 amb 184
767 amb 198 printf("%.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude));
768 amb 184
769     for(i=0;i<count;i++)
770     {
771     same=0;
772     for(j=0;j<count;j++)
773     if(limits[i]==limits[j])
774     same++;
775    
776     if(count==2 || same!=(count-1))
777     {
778 amb 219 double lat,lon;
779 amb 184
780 amb 934 GetLatLong(OSMNodes,OtherNode(&segments[i],node),&lat,&lon);
781 amb 184
782     switch(limit_type)
783     {
784     case SPEED_LIMIT:
785 amb 219 printf("%.6f %.6f %d\n",radians_to_degrees(lat),radians_to_degrees(lon),speed_to_kph(limits[i]));
786 amb 184 break;
787     case WEIGHT_LIMIT:
788 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),weight_to_tonnes(limits[i]));
789 amb 184 break;
790     case HEIGHT_LIMIT:
791 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),height_to_metres(limits[i]));
792 amb 184 break;
793     case WIDTH_LIMIT:
794 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),width_to_metres(limits[i]));
795 amb 184 break;
796     case LENGTH_LIMIT:
797 amb 198 printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),length_to_metres(limits[i]));
798 amb 184 break;
799     }
800     }
801     }
802     }
803    
804    
805     /*++++++++++++++++++++++++++++++++++++++
806     A function to iterate through all nodes and call a callback function for each one.
807    
808 amb 681 Nodes *nodes The set of nodes to use.
809 amb 184
810     callback_t callback The callback function for each node.
811     ++++++++++++++++++++++++++++++++++++++*/
812    
813 amb 217 static void find_all_nodes(Nodes *nodes,callback_t callback)
814 amb 184 {
815 amb 780 ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(LatMin))-nodes->file.latzero;
816     ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(LatMax))-nodes->file.latzero;
817     ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(LonMin))-nodes->file.lonzero;
818     ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(LonMax))-nodes->file.lonzero;
819     ll_bin_t latb,lonb;
820 amb 462 index_t i,index1,index2;
821 amb 184
822     /* Loop through all of the nodes. */
823    
824     for(latb=latminbin;latb<=latmaxbin;latb++)
825     for(lonb=lonminbin;lonb<=lonmaxbin;lonb++)
826     {
827 amb 780 ll_bin2_t llbin=lonb*nodes->file.latbins+latb;
828 amb 184
829 amb 453 if(llbin<0 || llbin>(nodes->file.latbins*nodes->file.lonbins))
830 amb 184 continue;
831    
832 amb 462 index1=LookupNodeOffset(nodes,llbin);
833     index2=LookupNodeOffset(nodes,llbin+1);
834    
835     for(i=index1;i<index2;i++)
836 amb 184 {
837 amb 453 Node *node=LookupNode(nodes,i,1);
838 amb 184
839 amb 453 double lat=latlong_to_radians(bin_to_latlong(nodes->file.latzero+latb)+off_to_latlong(node->latoffset));
840     double lon=latlong_to_radians(bin_to_latlong(nodes->file.lonzero+lonb)+off_to_latlong(node->lonoffset));
841    
842 amb 217 if(lat>LatMin && lat<LatMax && lon>LonMin && lon<LonMax)
843 amb 453 (*callback)(i,lat,lon);
844 amb 184 }
845     }
846     }

Properties

Name Value
cvs:description Functions for data visualisation.