-
Notifications
You must be signed in to change notification settings - Fork 174
/
osm.c
4241 lines (3930 loc) · 154 KB
/
osm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Navit, a modular navigation system.
* Copyright (C) 2005-2011 Navit Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "navit_lfs.h"
#ifdef _MSC_VER
#define strcasecmp _stricmp
#define snprintf _snprintf
#else
#include <unistd.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include "maptool.h"
#include "debug.h"
#include "linguistics.h"
#include "country.h"
#include "file.h"
#include "profile.h"
#include "types.h"
#include "transform.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#define M_PI_4 0.785398163397448309616
#endif
static int in_way, in_node, in_relation;
osmid nodeid,wayid;
static GHashTable *attr_hash,*country_table_hash,*attr_hash;
static char *attr_present;
static int attr_present_count;
static struct item_bin item;
int maxspeed_attr_value;
char debug_attr_buffer[BUFFER_SIZE];
int flags[4];
int flagsa[4];
int flags_attr_value;
struct attr_bin osmid_attr;
long long osmid_attr_value;
char is_in_buffer[BUFFER_SIZE];
char attr_strings_buffer[BUFFER_SIZE*16];
int attr_strings_buffer_free_offset;
#define MAX_COORD_COUNT 65536
struct coord coord_buffer[MAX_COORD_COUNT];
struct attr_mapping {
enum item_type type;
int attr_present_idx_count;
int attr_present_idx[0];
};
static void nodes_ref_item_bin(struct item_bin *ib);
static struct attr_mapping **attr_mapping_node;
static int attr_mapping_node_count;
static struct attr_mapping **attr_mapping_way;
static int attr_mapping_way_count;
static struct attr_mapping **attr_mapping_way2poi;
static int attr_mapping_way2poi_count;
static struct attr_mapping **attr_mapping_rel2poly_place;
static int attr_mapping_rel2poly_place_count;
static int attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count);
static void attr_longest_match_clear(void);
enum attr_strings_type {
attr_string_phone,
attr_string_fax,
attr_string_email,
attr_string_url,
attr_string_district_name,
attr_string_street_name,
attr_string_street_name_systematic,
attr_string_street_name_systematic_nat,
attr_string_street_name_systematic_int,
attr_string_ref,
attr_string_exit_to,
attr_string_street_destination,
attr_string_street_destination_forward,
attr_string_street_destination_backward,
attr_string_house_number,
attr_string_label,
attr_string_postal,
attr_string_population,
attr_string_county_name,
attr_string_last,
};
char *attr_strings[attr_string_last];
char *osm_types[]= {"unknown","node","way","relation"};
/*
* These macros are designed to handle maptool internal node id reference representation. This representation does not leak
* to binfile, so it's safe to change it without breaking binfile binary compatibility.
* Currently it keeps low 31 bits in y coordinate and up to 30 high order bits in x coordinate, allowing for 61 bit osm node id in total.
*/
#define REF_MARKER (1ull << 30)
#define REF_MASK (3ull << 30)
#define IS_REF(c) (((c).x & REF_MASK)==REF_MARKER)
#define GET_REF(c) ((((osmid)(c).x & ~REF_MARKER)<<31) + (c).y )
#define SET_REF(c,ref) do { (c).x = REF_MARKER | ((osmid)(ref)>>31); (c).y = (osmid)(ref) & 0x7fffffffull; } while(0)
/* Table of country codes with possible is_in spellings.
* Note: If you update this list, check also country array in country.c
*/
struct country_table {
int countryid;
char *names;
char *admin_levels; /**<
* String indicating how to interpret admin levels for this country.
*
* Each character of the string specifies how to treat the corresponding admin level.
* The first character corresponds to level 3, each following character to the next
* lower level (usually up to level 8, but that is just a convention):
* `s`: use the name as the state label, `c`: use the name as the county label,
* `m`: use the name as the municipality label, `M`: same as `m`, but additionally
* use the boundary as the town boundary, `T`: use the boundary the town boundary and
* ignore the name. All other characters are ignored; by convention use the digit
* corresponding to the admin level to indicate this level should be skipped.
*
* See
* https://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative#10_admin_level_values_for_specific_countries
* for values used in specific countries.
*/
FILE *file;
int size;
struct rect r;
int nparts;
} country_table[] = {
{ 4,"Afghanistan"},
{ 8,"Albania"},
{ 10,"Antarctica"},
{ 12,"Algeria"},
{ 16,"American Samoa"},
{ 20,"Andorra"},
{ 24,"Angola"},
{ 28,"Antigua and Barbuda"},
{ 31,"Azerbaijan"},
{ 32,"Argentina,República Argentina,AR "},
{ 36,"Australia,AUS","3s456c8"},
{ 40,"Austria,Österreich,AUT","3s5c78"},
{ 44,"Bahamas"},
{ 48,"Bahrain"},
{ 50,"Bangladesh"},
{ 51,"Armenia"},
{ 52,"Barbados"},
{ 56,"Belgium,Belgique,Belgie,België,Belgien","345c7M"},
{ 60,"Bermuda"},
{ 64,"Bhutan"},
{ 68,"Bolivia, Plurinational State of"},
{ 70,"Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина"},
{ 72,"Botswana"},
{ 74,"Bouvet Island"},
{ 76,"Brazil","3s5cm8"},
{ 84,"Belize"},
{ 86,"British Indian Ocean Territory"},
{ 90,"Solomon Islands"},
{ 92,"Virgin Islands, British"},
{ 96,"Brunei Darussalam"},
{ 100,"Bulgaria,България","3s5cm8"},
{ 104,"Myanmar"},
{ 108,"Burundi"},
{ 112,"Belarus","3s5c78"},
{ 116,"Cambodia"},
{ 120,"Cameroon"},
{ 124,"Canada","3scm78"},
{ 132,"Cape Verde"},
{ 136,"Cayman Islands"},
{ 140,"Central African Republic"},
{ 144,"Sri Lanka"},
{ 148,"Chad"},
{ 152,"Chile"},
{ 156,"China"},
{ 158,"Taiwan, Province of China"},
{ 162,"Christmas Island"},
{ 166,"Cocos (Keeling) Islands"},
{ 170,"Colombia"},
{ 174,"Comoros"},
{ 175,"Mayotte"},
{ 178,"Congo"},
{ 180,"Congo, the Democratic Republic of the"},
{ 184,"Cook Islands"},
{ 188,"Costa Rica"},
{ 191,"Croatia,Republika Hrvatska,HR","34scm8"},
{ 192,"Cuba"},
{ 196,"Cyprus","345c7m"},
{ 203,"Czech Republic,Česká republika,CZ","345cm8"},
{ 204,"Benin"},
{ 208,"Denmark,Danmark,DK","3c56m8"},
{ 212,"Dominica"},
{ 214,"Dominican Republic"},
{ 218,"Ecuador"},
{ 222,"El Salvador"},
{ 226,"Equatorial Guinea"},
{ 231,"Ethiopia"},
{ 232,"Eritrea"},
{ 233,"Estonia,Eesti","345cm8"},
{ 234,"Faroe Islands,Føroyar"},
{ 238,"Falkland Islands (Malvinas)"},
{ 239,"South Georgia and the South Sandwich Islands"},
{ 242,"Fiji"},
{ 246,"Finland,Suomi","3s5cm8"},
{ 248,"Åland Islands"},
{ 250,"France,République française,FR","3s5c7M"},
{ 254,"French Guiana"},
{ 258,"French Polynesia"},
{ 260,"French Southern Territories"},
{ 262,"Djibouti"},
{ 266,"Gabon"},
{ 268,"Georgia","3s5c78"},
{ 270,"Gambia"},
{ 275,"Palestinian Territory, Occupied"},
{ 276,"Germany,Deutschland,Bundesrepublik Deutschland","3s5c7M"},
{ 288,"Ghana"},
{ 292,"Gibraltar"},
{ 296,"Kiribati"},
{ 300,"Greece"},
{ 304,"Greenland"},
{ 308,"Grenada"},
{ 312,"Guadeloupe"},
{ 316,"Guam"},
{ 320,"Guatemala"},
{ 324,"Guinea"},
{ 328,"Guyana"},
{ 332,"Haiti"},
{ 334,"Heard Island and McDonald Islands"},
{ 336,"Holy See (Vatican City State)"},
{ 340,"Honduras"},
{ 344,"Hong Kong"},
{ 348,"Hungary,Magyarország","345c78"},
{ 352,"Iceland","34cm78"},
{ 356,"India","3sc6m8"},
{ 360,"Indonesia"},
{ 364,"Iran, Islamic Republic of"},
{ 368,"Iraq"},
{ 372,"Ireland","345c78"},
{ 376,"Israel"},
{ 380,"Italy,Italia","3s5c78"},
{ 384,"Côte d'Ivoire"},
{ 388,"Jamaica"},
{ 392,"Japan","3s5cm8"},
{ 398,"Kazakhstan"},
{ 400,"Jordan"},
{ 404,"Kenya"},
{ 408,"Korea, Democratic People's Republic of","3s5cm8"},
{ 410,"Korea, Republic of","3s5cm8"},
{ 412,"Kosovo,Kosova"},
{ 414,"Kuwait"},
{ 417,"Kyrgyzstan"},
{ 418,"Lao People's Democratic Republic"},
{ 422,"Lebanon"},
{ 426,"Lesotho"},
{ 428,"Latvia,Latvija","345c78"},
{ 430,"Liberia"},
{ 434,"Libyan Arab Jamahiriya"},
{ 438,"Liechtenstein"},
{ 440,"Lithuania,Lietuva","3cm67T"},
{ 442,"Luxembourg","3s5c78"},
{ 446,"Macao"},
{ 450,"Madagascar"},
{ 454,"Malawi"},
{ 458,"Malaysia"},
{ 462,"Maldives"},
{ 466,"Mali"},
{ 470,"Malta"},
{ 474,"Martinique"},
{ 478,"Mauritania"},
{ 480,"Mauritius"},
{ 484,"Mexico","3s5m78"},
{ 492,"Monaco"},
{ 496,"Mongolia"},
{ 498,"Moldova, Republic of"},
{ 499,"Montenegro,Црна Гора,Crna Gora"},
{ 500,"Montserrat"},
{ 504,"Morocco"},
{ 508,"Mozambique"},
{ 512,"Oman"},
{ 516,"Namibia"},
{ 520,"Nauru"},
{ 524,"Nepal"},
{ 528,"Nederland,The Netherlands,Niederlande,NL,Netherlands","3c567M"},
{ 530,"Netherlands Antilles"},
{ 531,"Curacao"},
{ 533,"Aruba"},
{ 534,"Sint Maarten (Dutch part)"},
{ 535,"Bonaire, Sint Eustatius and Saba"},
{ 540,"New Caledonia"},
{ 548,"Vanuatu"},
{ 554,"New Zealand","3s5m78"},
{ 558,"Nicaragua"},
{ 562,"Niger"},
{ 566,"Nigeria"},
{ 570,"Niue"},
{ 574,"Norfolk Island"},
{ 578,"Norway,Norge,Noreg,NO","3c56m8"},
{ 580,"Northern Mariana Islands"},
{ 581,"United States Minor Outlying Islands"},
{ 583,"Micronesia, Federated States of"},
{ 584,"Marshall Islands"},
{ 585,"Palau"},
{ 586,"Pakistan"},
{ 591,"Panama"},
{ 598,"Papua New Guinea"},
{ 600,"Paraguay"},
{ 604,"Peru"},
{ 608,"Philippines"},
{ 612,"Pitcairn"},
{ 616,"Poland,Polska,PL","3s5cmT"},
{ 620,"Portugal","345cm8"},
{ 624,"Guinea-Bissau"},
{ 626,"Timor-Leste"},
{ 630,"Puerto Rico"},
{ 634,"Qatar"},
{ 638,"Réunion"},
{ 642,"România,Romania,RO","sc5m78"},
{ 643,"Россия,Российская Федерация,Russia,Russian Federation","3s5c7m"},
{ 646,"Rwanda"},
{ 652,"Saint Barthélemy"},
{ 654,"Saint Helena, Ascension and Tristan da Cunha"},
{ 659,"Saint Kitts and Nevis"},
{ 660,"Anguilla"},
{ 662,"Saint Lucia"},
{ 663,"Saint Martin (French part)"},
{ 666,"Saint Pierre and Miquelon"},
{ 670,"Saint Vincent and the Grenadines"},
{ 674,"San Marino"},
{ 678,"Sao Tome and Principe"},
{ 682,"Saudi Arabia"},
{ 686,"Senegal"},
{ 688,"Srbija,Србија,Serbia","3scm78"},
{ 690,"Seychelles"},
{ 694,"Sierra Leone"},
{ 702,"Singapore"},
{ 703,"Slovakia,Slovensko,SK","3c567m"},
{ 704,"Viet Nam"},
{ 705,"Slovenia,Republika Slovenija,SI","34s6cm"},
{ 706,"Somalia"},
{ 710,"South Africa"},
{ 716,"Zimbabwe"},
{ 724,"Spain,Espana,España,Reino de Espana,Reino de España","345scm"},
{ 728,"South Sudan"},
{ 732,"Western Sahara"},
{ 736,"Sudan"},
{ 740,"Suriname"},
{ 744,"Svalbard and Jan Mayen"},
{ 748,"Swaziland"},
{ 752,"Sweden,Sverige,Konungariket Sverige,SE","3c56m8"},
{ 756,"Switzerland,Schweiz","3s5c7M"},
{ 760,"Syrian Arab Republic"},
{ 762,"Tajikistan"},
{ 764,"Thailand"},
{ 768,"Togo"},
{ 772,"Tokelau"},
{ 776,"Tonga"},
{ 780,"Trinidad and Tobago"},
{ 784,"United Arab Emirates"},
{ 788,"Tunisia"},
{ 792,"Turkey","sc5m78"},
{ 795,"Turkmenistan"},
{ 796,"Turks and Caicos Islands"},
{ 798,"Tuvalu"},
{ 800,"Uganda"},
{ 804,"Ukraine","3s5c78"},
{ 807,"Macedonia,Македонија"},
{ 818,"Egypt"},
{ 826,"United Kingdom,UK","3s5c7m"},
{ 831,"Guernsey"},
{ 832,"Jersey"},
{ 833,"Isle of Man"},
{ 834,"Tanzania, United Republic of"},
{ 840,"USA","3s5c7m"},
{ 850,"Virgin Islands, U.S."},
{ 854,"Burkina Faso"},
{ 858,"Uruguay"},
{ 860,"Uzbekistan"},
{ 862,"Venezuela, Bolivarian Republic of"},
{ 876,"Wallis and Futuna"},
{ 882,"Samoa"},
{ 887,"Yemen"},
{ 894,"Zambia"},
{ 999,"Unknown"},
};
// first char - item type
// =w - ways
// =? - used both for nodes and ways
// otherwise - nodes
static char *attrmap= {
"n *=* point_unkn\n"
"? addr:housenumber=* house_number\n"
"? aeroway=aerodrome poi_airport\n"
"? aeroway=airport poi_airport\n"
"? aeroway=helipad poi_heliport\n"
"? aeroway=terminal poi_airport\n"
"? amenity=atm poi_atm\n"
"? amenity=bank poi_bank\n"
"? amenity=bar poi_bar\n"
"n amenity=bench poi_bench\n"
"? amenity=bicycle_rental poi_bicycle_rental\n"
"? amenity=bicycle_parking poi_bicycle_parking\n"
"? amenity=biergarten poi_biergarten\n"
"? amenity=bus_station poi_bus_station\n"
"? amenity=cafe poi_cafe\n"
"? amenity=car_sharing poi_car_sharing\n"
"? amenity=car_wash poi_car_wash\n"
"? amenity=cinema poi_cinema\n"
"? amenity=college poi_school_college\n"
"? amenity=courthouse poi_justice\n"
"? amenity=drinking_water poi_potable_water\n"
"? amenity=fast_food poi_fastfood\n"
"? amenity=fire_station poi_firebrigade\n"
"? amenity=fountain poi_fountain\n"
"? amenity=fuel poi_fuel\n"
"? amenity=grave_yard poi_cemetery\n"
"? amenity=hospital poi_hospital\n"
"? amenity=hunting_stand poi_hunting_stand\n"
"? amenity=kindergarten poi_kindergarten\n"
"? amenity=library poi_library\n"
"? amenity=nightclub poi_nightclub\n"
"? amenity=park_bench poi_bench\n"
"? amenity=parking poi_car_parking\n"
"? amenity=pharmacy poi_pharmacy\n"
"? amenity=place_of_worship,religion=christian poi_church\n"
"? amenity=place_of_worship poi_worship\n"
"? amenity=police poi_police\n"
"? amenity=post_box poi_post_box\n"
"? amenity=post_office poi_post_office\n"
"? amenity=prison poi_prison\n"
"? amenity=pub poi_pub\n"
"? amenity=public_building poi_public_office\n"
"? amenity=recycling poi_recycling\n"
"? amenity=restaurant,cuisine=fine_dining poi_dining\n"
"? amenity=restaurant poi_restaurant\n"
"? amenity=school poi_school\n"
"? amenity=shelter poi_shelter\n"
"? amenity=taxi poi_taxi\n"
"? amenity=tec_common tec_common\n"
"? amenity=telephone poi_telephone\n"
"? amenity=theatre poi_theater\n"
"? amenity=toilets poi_restroom\n"
"? amenity=townhall poi_townhall\n"
"? amenity=university poi_school_university\n"
"? amenity=vending_machine poi_vending_machine\n"
"n barrier=bollard barrier_bollard\n"
"n barrier=cycle_barrier barrier_cycle\n"
"n barrier=lift_gate barrier_lift_gate\n"
"? car=car_rental poi_car_rent\n"
"? highway=bus_station poi_bus_station\n"
"? highway=bus_stop poi_bus_stop\n"
"n highway=mini_roundabout mini_roundabout\n"
"n highway=motorway_junction highway_exit\n"
"n highway=stop traffic_sign_stop\n"
"n highway=toll_booth poi_toll_booth\n"
"n highway=traffic_signals traffic_signals\n"
"n highway=turning_circle turning_circle\n"
"? historic=boundary_stone poi_boundary_stone\n"
"? historic=castle poi_castle\n"
"? historic=memorial poi_memorial\n"
"? historic=monument poi_monument\n"
"? historic=ruins poi_ruins\n"
"n historic=archaeological_site poi_archaeological_site\n"
// "? historic=* poi_ruins\n"
"? landuse=cemetery poi_cemetery\n"
"? leisure=fishing poi_fish\n"
"? leisure=golf_course poi_golf\n"
"? leisure=marina poi_marine\n"
"? leisure=playground poi_playground\n"
"? leisure=slipway poi_boat_ramp\n"
"? leisure=sports_centre poi_sport\n"
"? leisure=stadium poi_stadium\n"
"? man_made=tower poi_tower\n"
"? military=airfield poi_military\n"
"? military=barracks poi_military\n"
"? military=bunker poi_military\n"
"? military=danger_area poi_danger_area\n"
"? military=range poi_military\n"
"? natural=bay poi_bay\n"
"? natural=peak,ele=* poi_peak\n" // show only major peaks with elevation
"? natural=tree poi_tree\n"
"n place=city town_label_2e5\n"
"n place=hamlet town_label_2e2\n"
"n place=locality town_label_2e0\n"
"n place=suburb district_label\n"
"n place=town town_label_2e4\n"
"n place=village town_label_2e3\n"
"n power=tower power_tower\n"
"n power=sub_station power_substation\n"
"n railway=halt poi_rail_halt\n"
"n railway=level_crossing poi_level_crossing\n"
"? railway=station poi_rail_station\n"
"? railway=tram_stop poi_rail_tram_stop\n"
"? shop=baker poi_shop_baker\n"
"? shop=bakery poi_shop_baker\n"
"? shop=beverages poi_shop_beverages\n"
"? shop=bicycle poi_shop_bicycle\n"
"? shop=butcher poi_shop_butcher\n"
"? shop=car poi_car_dealer_parts\n"
"? shop=car_repair poi_repair_service\n"
"? shop=clothes poi_shop_apparel\n"
"? shop=convenience poi_shop_grocery\n"
"? shop=chemist poi_shop_drugstore\n"
"? shop=florist poi_shop_florist\n"
"? shop=fruit poi_shop_fruit\n"
"? shop=furniture poi_shop_furniture\n"
"? shop=garden_centre poi_shop_handg\n"
"? shop=hardware poi_shop_handg\n"
"? shop=hairdresser poi_hairdresser\n"
"? shop=kiosk poi_shop_kiosk\n"
"? shop=optician poi_shop_optician\n"
"? shop=parfum poi_shop_parfum\n"
"? shop=photo poi_shop_photo\n"
"? shop=shoes poi_shop_shoes\n"
"? shop=supermarket poi_shopping\n"
"? shop=mall poi_mall\n"
"? sport=10pin poi_bowling\n"
"? sport=baseball poi_baseball\n"
"? sport=basketball poi_basketball\n"
"? sport=climbing poi_climbing\n"
"? sport=golf poi_golf\n"
"? sport=motor_sports poi_motor_sport\n"
"? sport=skiing poi_skiing\n"
"? sport=soccer poi_soccer\n"
"? sport=stadium poi_stadium\n"
"? sport=swimming poi_swimming\n"
"? sport=tennis poi_tennis\n"
"? tourism=attraction poi_attraction\n"
"? tourism=camp_site poi_camp_rv\n"
"? tourism=caravan_site poi_camp_rv\n"
"? tourism=guest_house poi_guesthouse\n"
"? tourism=hostel poi_hostel\n"
"? tourism=hotel poi_hotel\n"
"? tourism=information poi_information\n"
"? tourism=motel poi_motel\n"
"? tourism=museum poi_museum_history\n"
"? tourism=picnic_site poi_picnic\n"
"? tourism=theme_park poi_resort\n"
"? tourism=viewpoint poi_viewpoint\n"
"? tourism=zoo poi_zoo\n"
"n natural=cave_entrance poi_cave\n"
"n traffic_sign=city_limit traffic_sign_city_limit\n"
"n highway=speed_camera tec_common\n"
"w *=* street_unkn\n"
"w addr:interpolation=even house_number_interpolation_even\n"
"w addr:interpolation=odd house_number_interpolation_odd\n"
"w addr:interpolation=all house_number_interpolation_all\n"
"w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n"
"w aerialway=cable_car lift_cable_car\n"
"w aerialway=chair_lift lift_chair\n"
"w aerialway=drag_lift lift_drag\n"
"w aeroway=aerodrome poly_airport\n"
/* airport wins over military landuse and specifier if given */
"w aeroway=aerodrome,landuse=military poly_airfield\n"
"w aeroway=aerodrome,landuse=military,military=* poly_airfield\n"
"w aeroway=apron poly_apron\n"
"w aeroway=runway aeroway_runway\n"
"w aeroway=taxiway aeroway_taxiway\n"
"w aeroway=terminal poly_terminal\n"
"w amenity=college poly_college\n"
"w amenity=grave_yard poly_cemetery\n"
"w amenity=parking poly_car_parking\n"
"w amenity=place_of_worship poly_building\n"
"w amenity=university poly_university\n"
"w boundary=administrative,admin_level=2 border_country\n"
"w boundary=civil border_civil\n"
"w boundary=national_park border_national_park\n"
"w boundary=political border_political\n"
"w building=* poly_building\n"
"w contour_ext=elevation_major height_line_1\n"
"w contour_ext=elevation_medium height_line_2\n"
"w contour_ext=elevation_minor height_line_3\n"
"w highway=bridleway bridleway\n"
"w highway=bus_guideway bus_guideway\n"
"w highway=construction street_construction\n"
"w highway=cyclepath cycleway\n"
"w highway=cycleway cycleway\n"
"w highway=footway footway\n"
"w highway=footway,piste:type=nordic footway_and_piste_nordic\n"
"w highway=living_street living_street\n"
"w highway=minor street_1_land\n"
"w highway=parking_lane street_parking_lane\n"
"w highway=path path\n"
"w highway=path,bicycle=designated cycleway\n"
"w highway=path,bicycle=official cycleway\n"
"w highway=path,bicycle=designated,foot=designated cycleway\n"
"w highway=path,bicycle=official,foot=official cycleway\n"
"w highway=path,foot=designated footway\n"
"w highway=path,foot=official footway\n"
"w highway=path,horse=designated bridleway\n"
"w highway=path,horse=official bridleway\n"
"w highway=path,sac_scale=alpine_hiking hiking_alpine\n"
"w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n"
"w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n"
"w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n"
"w highway=path,sac_scale=hiking hiking\n"
"w highway=path,sac_scale=mountain_hiking hiking_mountain\n"
"w highway=pedestrian street_pedestrian\n"
"w highway=pedestrian,area=1 poly_pedestrian\n"
"w highway=plaza poly_plaza\n"
"w highway=motorway highway_land\n"
"w highway=motorway,rural=0 highway_city\n"
"w highway=motorway_link ramp\n"
"w highway=trunk street_n_lanes\n"
"w highway=trunk_link ramp\n"
"w highway=primary street_4_land\n"
"w highway=primary,name=*,rural=1 street_4_land\n"
"w highway=primary,name=* street_4_city\n"
"w highway=primary,rural=0 street_4_city\n"
"w highway=primary_link ramp\n"
"w highway=secondary street_3_land\n"
"w highway=secondary,name=*,rural=1 street_3_land\n"
"w highway=secondary,name=* street_3_city\n"
"w highway=secondary,rural=0 street_3_city\n"
"w highway=secondary,area=1 poly_street_3\n"
"w highway=secondary_link ramp\n"
"w highway=tertiary street_2_land\n"
"w highway=tertiary,name=*,rural=1 street_2_land\n"
"w highway=tertiary,name=* street_2_city\n"
"w highway=tertiary,rural=0 street_2_city\n"
"w highway=tertiary,area=1 poly_street_2\n"
"w highway=tertiary_link ramp\n"
"w highway=residential street_1_city\n"
"w highway=residential,area=1 poly_street_1\n"
"w highway=unclassified street_1_city\n"
"w highway=unclassified,area=1 poly_street_1\n"
"w highway=road street_1_city\n"
"w highway=service street_service\n"
"w highway=service,area=1 poly_service\n"
"w highway=service,service=parking_aisle street_parking_lane\n"
"w highway=track track_gravelled\n"
"w highway=track,surface=grass track_grass\n"
"w highway=track,surface=gravel track_gravelled\n"
"w highway=track,surface=ground track_ground\n"
"w highway=track,surface=paved track_paved\n"
"w highway=track,surface=unpaved track_unpaved\n"
"w highway=track,tracktype=grade1 track_paved\n"
"w highway=track,tracktype=grade2 track_gravelled\n"
"w highway=track,tracktype=grade3 track_unpaved\n"
"w highway=track,tracktype=grade4 track_ground\n"
"w highway=track,tracktype=grade5 track_grass\n"
"w highway=track,surface=paved,tracktype=grade1 track_paved\n"
"w highway=track,surface=gravel,tracktype=grade2 track_gravelled\n"
"w highway=track,surface=unpaved,tracktype=grade3 track_unpaved\n"
"w highway=track,surface=ground,tracktype=grade4 track_ground\n"
"w highway=track,surface=grass,tracktype=grade5 track_grass\n"
"w highway=unsurfaced track_gravelled\n"
"w highway=steps steps\n"
"w historic=archaeological_site poly_archaeological_site\n"
/* Albeit historic=archaeological_site should not be used on ways (only on areas) according to OSM wiki,
* it is at least done so for the Limes in germany. Luckily we can sort the Limes out as it has it's own
* tag scheme.*/
"w historic=archaeological_site,site_type=fortification,fortification_type=limes archaeological_site\n"
"w historic=battlefield poly_battlefield\n"
"w historic=ruins poly_ruins\n"
"w historic=town_gate poly_building\n"
"w landuse=allotments poly_allotments\n"
"w landuse=basin poly_basin\n"
"w landuse=brownfield poly_brownfield\n"
"w landuse=cemetery poly_cemetery\n"
"w landuse=commercial poly_commercial\n"
"w landuse=construction poly_construction\n"
"w landuse=farm poly_farm\n"
"w landuse=farmland poly_farm\n"
"w landuse=farmyard poly_town\n"
"w landuse=forest poly_wood\n"
"w landuse=grass poly_meadow\n"
"w landuse=greenfield poly_greenfield\n"
"w landuse=industrial poly_industry\n"
"w landuse=landfill poly_landfill\n"
/* landuse=military plus military tag */
"w landuse=military poly_military\n"
"w landuse=military,military=* poly_military\n"
"w landuse=military,military=airfield poly_airfield\n"
"w landuse=military,military=barracks poly_barracks\n"
"w landuse=military,military=danger_area poly_danger_area\n"
"w landuse=military,military=naval_base poly_naval_base\n"
"w landuse=military,military=range poly_range\n"
"w landuse=military,military=training_area poly_military_zone\n"
"w landuse=meadow poly_meadow\n"
"w landuse=plaza poly_plaza\n"
"w landuse=quarry poly_quarry\n"
"w landuse=railway poly_railway\n"
"w landuse=recreation_ground poly_recreation_ground\n"
"w landuse=reservoir poly_reservoir\n"
"w landuse=residential poly_town\n"
"w landuse=residential,area=1 poly_town\n"
"w landuse=retail poly_retail\n"
"w landuse=village_green poly_village_green\n"
"w landuse=vineyard poly_farm\n"
"w landuse=depot poly_depot\n"
"w landuse=garages poly_garages\n"
"w landuse=greenhouse_horticulture poly_greenhouse\n"
"w landuse=orchard poly_orchard\n"
"w landuse=plant_nursery poly_plantnursery\n"
"w landuse=port poly_port\n"
"w landuse=salt_pond poly_saltpond\n"
"w leisure=common poly_common\n"
"w leisure=fishing poly_fishing\n"
"w leisure=garden poly_garden\n"
"w leisure=golf_course poly_golf_course\n"
"w leisure=marina poly_marina\n"
"w leisure=nature_reserve poly_nature_reserve\n"
"w leisure=park poly_park\n"
"w leisure=pitch poly_sports_pitch\n"
"w leisure=playground poly_playground\n"
"w leisure=sports_centre,building=1 poly_building\n"
"w leisure=sports_centre poly_sport\n"
"w leisure=stadium poly_sports_stadium\n"
"w leisure=track,area=1 poly_sports_track\n"
"w leisure=track,area=0 sports_track\n"
"w leisure=track,type=multipolygon poly_sports_track\n"
"w leisure=track sports_track\n"
"w leisure=water_park poly_water_park\n"
"w leisure=swimming_pool poly_swimming_pool\n"
/* military tag without further info */
"w military=airfield poly_airfield\n"
"w military=barracks poly_barracks\n"
"w military=danger_area poly_danger_area\n"
"w military=naval_base poly_naval_base\n"
"w military=range poly_range\n"
"w military=training_area poly_military_zone\n"
"w natural=beach poly_beach\n"
"w natural=coastline water_line\n"
"w natural=fell poly_fell\n"
"w natural=glacier poly_glacier\n"
"w natural=grassland poly_meadow\n"
"w natural=heath poly_heath\n"
"w natural=land poly_land\n"
"w natural=marsh poly_marsh\n"
"w natural=meadow poly_meadow\n"
"w natural=mud poly_mud\n"
"w natural=sand poly_beach\n"
"w natural=scree poly_scree\n"
"w natural=scrub poly_scrub\n"
"w natural=water poly_water\n"
"w natural=wetland poly_mud\n"
"w natural=wood poly_wood\n"
"w natural=cliff cliff\n"
"w man_made=embankment embankment\n"
"w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n"
"w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n"
"w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n"
"w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n"
"w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n"
"w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n"
"w piste:type=nordic piste_nordic\n"
"w place=suburb poly_place1\n"
"w place=hamlet poly_place2\n"
"w place=isolated_dwelling poly_place2\n"
"w place=locality poly_place2\n"
"w place=village poly_place3\n"
"w place=municipality poly_place4\n"
"w place=town poly_place5\n"
"w place=city poly_place6\n"
"w de:place=city poly_place6\n"
"w power=line powerline\n"
"w railway=abandoned rail_abandoned\n"
"w railway=disused rail_disused\n"
"w railway=light_rail rail_light\n"
"w railway=monorail rail_mono\n"
"w railway=narrow_gauge rail_narrow_gauge\n"
"w railway=preserved rail_preserved\n"
"w railway=rail rail\n"
"w railway=subway rail_subway\n"
"w railway=tram rail_tram\n"
"w route=ferry ferry\n"
"w route=ski piste_nordic\n"
"w sport=* poly_sport\n"
"w tourism=artwork poly_artwork\n"
"w tourism=attraction poly_attraction\n"
"w tourism=camp_site poly_camp_site\n"
"w tourism=caravan_site poly_caravan_site\n"
"w tourism=picnic_site poly_picnic_site\n"
"w tourism=theme_park poly_theme_park\n"
"w tourism=zoo poly_zoo\n"
"w waterway=canal water_canal\n"
"w waterway=drain water_drain\n"
"w waterway=river water_river\n"
"w waterway=riverbank poly_water\n"
"w waterway=stream water_stream\n"
"w waterway=dam poly_dam\n"
"w waterway=weir poly_dam\n"
"w barrier=ditch ditch\n"
"w barrier=hedge hedge\n"
"w barrier=fence fence\n"
"w barrier=wall wall\n"
"w barrier=retaining_wall retaining_wall\n"
"w barrier=city_wall city_wall\n"
};
static void build_attrmap_line(char *line) {
char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv;
struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping));
int idx,attr_mapping_count=0;
t=line;
p=strpbrk(t," \t");
if (p) {
while (*p && isspace(*p))
*p++='\0';
kvl=p;
p=strpbrk(kvl," \t");;
}
if (p) {
while (*p && isspace(*p))
*p++='\0';
i=p;
}
if (t[0] == 'w') {
if (! i)
i="street_unkn";
} else {
if (! i)
i="point_unkn";
}
attr_mapping->type=item_from_name(i);
if (!attr_mapping->type) {
printf("no id found for '%s'\n",i);
}
while ((kv=strtok(kvl, ","))) {
kvl=NULL;
if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) {
idx=attr_present_count++;
g_hash_table_insert(attr_hash, kv, (gpointer)(long long)idx);
}
attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int));
attr_mapping->attr_present_idx[attr_mapping_count++]=idx;
attr_mapping->attr_present_idx_count=attr_mapping_count;
}
if (t[0]== 'w') {
attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1));
attr_mapping_way[attr_mapping_way_count++]=attr_mapping;
if(item_is_poly_place(*attr_mapping)) {
attr_mapping_rel2poly_place=g_realloc(attr_mapping_rel2poly_place,
sizeof(*attr_mapping_rel2poly_place)*(attr_mapping_rel2poly_place_count+1));
attr_mapping_rel2poly_place[attr_mapping_rel2poly_place_count++]=attr_mapping;
}
}
if (t[0]== '?') {
attr_mapping_way2poi=g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi)*(attr_mapping_way2poi_count+1));
attr_mapping_way2poi[attr_mapping_way2poi_count++]=attr_mapping;
}
if (t[0]!= 'w') {
attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1));
attr_mapping_node[attr_mapping_node_count++]=attr_mapping;
}
}
static void build_attrmap(FILE* rule_file) {
attr_hash=g_hash_table_new(g_str_hash, g_str_equal);
attr_present_count=1;
// build attribute map from rule file if given
if( rule_file ) {
char buffer[200], *p;
while (fgets( buffer, 200, rule_file )) {
p=strchr(buffer,'\n');
if(p)
*p = 0;
build_attrmap_line( g_strdup( buffer ) );
}
fclose( rule_file );
}
// use hardcoded default attributes
else {
char *p,*map=g_strdup(attrmap);
while (map) {
p=strchr(map,'\n');
if (p)
*p++='\0';
if (strlen(map))
build_attrmap_line(map);
map=p;
}
}
attr_present=g_malloc0(sizeof(*attr_present)*attr_present_count);
}
static void build_countrytable(void) {
int i;
char *names,*str,*tok;
country_table_hash=g_hash_table_new(g_str_hash, g_str_equal);
for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
names=g_strdup(country_table[i].names);
str=names;
while ((tok=strtok(str, ","))) {
str=NULL;
g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]);
}
}
}
static void osm_logv(char *prefix, char *objtype, osmid id, int cont, struct coord_geo *geo, char *fmt, va_list ap) {
char str[4096];
vsnprintf(str, sizeof(str), fmt, ap);
if(cont)
prefix="";
if(objtype)
fprintf(stderr,"%shttp://www.openstreetmap.org/%s/"OSMID_FMT" %s", prefix, objtype, id, str);
else if(geo)
fprintf(stderr,"%shttp://www.openstreetmap.org/#map=19/%.5f/%.5f %s",prefix, geo->lat, geo->lng, str);
else
fprintf(stderr,"%s[no osm object info] %s",prefix, str);
}
void osm_warning(char *type, osmid id, int cont, char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
osm_logv("OSM Warning:", type, id, cont, NULL, fmt, ap);
va_end(ap);
}
void osm_info(char *type, osmid id, int cont, char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
osm_logv("OSM Info:", type, id, cont, NULL, fmt, ap);
va_end(ap);
}
static void itembin_warning(struct item_bin *ib, int cont, char *fmt, ...) {
char *type=NULL;
osmid id;
struct coord_geo geo;
va_list ap;
if(0!=(id=item_bin_get_nodeid(ib))) {
type="node";
} else if(0!=(id=item_bin_get_wayid(ib))) {
type="way";
} else if(0!=(id=item_bin_get_relationid(ib))) {
type="relation";
} else {
struct coord *c=(struct coord *)(ib+1);
transform_to_geo(projection_mg, c, &geo);
}
va_start(ap, fmt);
osm_logv("OSM Warning:", type, id, cont, &geo, fmt, ap);
va_end(ap);
}
static void attr_strings_clear(void) {
attr_strings_buffer_free_offset=0;
memset(attr_strings, 0, sizeof(attr_strings));
}
static void attr_strings_save(enum attr_strings_type id, char *str) {
int str_size=strlen(str)+1;
dbg_assert(attr_strings_buffer_free_offset+str_size<sizeof(attr_strings_buffer));
attr_strings[id]=attr_strings_buffer+attr_strings_buffer_free_offset;
g_strlcpy(attr_strings[id], str, str_size);
attr_strings_buffer_free_offset+=str_size;
}
static osmid item_bin_get_nodeid_from_attr(struct item_bin *ib, enum attr_type attr_type) {
unsigned long long *ret=item_bin_get_attr(ib, attr_type, NULL);
if (ret)
return *ret;
return 0;
}
osmid item_bin_get_nodeid(struct item_bin *ib) {
return item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid);
}
osmid item_bin_get_wayid(struct item_bin *ib) {
unsigned long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL);
if (ret)