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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1057 - (show annotations) (download) (as text)
Sun Aug 12 14:09:12 2012 UTC (12 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 24361 byte(s)
Fix for highway type visualiser (was missing one-way segments).

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

Properties

Name Value
cvs:description Functions for data visualisation.