forked from terranodo/osm-extract
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
169 lines (127 loc) · 8.22 KB
/
Makefile
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
# Install gdal 1.10 or newer and compile using the following:
# ./configure --with-spatialite=yes --with-expat=yes --with-python=yes
# Without it, the OSM format will not be enabled.
# Install latest osmosis to get the read-pbf-fast command. older versions
# like the one shipped with Ubuntu 14.04 do not have this option.
# Once you have them, make sure gdal/apps and osmosis/bin are added to our path before running this file.
ifeq ($(URL),)
abort:
@echo Variable URL not set && false
endif
ifeq ($(NAME),)
abort:
@echo Variable NAME not set && false
endif
DB=$(NAME)_osm
SETNAME=$(NAME)
mk-work-dir:
mkdir -p ./$(NAME)
latest.pbf: mk-work-dir
curl -g -o $(NAME)/$@.temp $(URL)
if file $(NAME)/$@.temp | grep XML; then \
osmosis --read-xml file="$(NAME)/$@.temp" --write-pbf file="$(NAME)/$@"; \
else \
mv $(NAME)/$@.temp $(NAME)/$@; \
fi
aerodromes_point.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="aeroway.aerodrome" --write-pbf file="$(NAME)/$@"
aerodromes_polygon.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="aeroway.aerodrome" --used-node --write-pbf file="$(NAME)/$@"
all_places.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="place.city,place.borough,place.suburb,place.quarter,place.neighbourhood,place.city_block,place.plot,place.town,place.village,place.hamlet,place.isolated_dwelling,place.farm,place.allotments" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
all_roads.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "highway=*" --used-node --write-pbf file="$(NAME)/$@"
banks.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes amenity=bank,atm,bureau_de_change --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
buildings.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "building=*" --write-pbf file="$(NAME)/$@"
built_up_areas.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways landuse=residential,allotments,cemetery,construction,depot,garages,brownfield,commercial,industrial,retail --used-node --write-pbf file="$(NAME)/$@"
cities.pbf: all_places.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "place=city" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
farms.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="landuse.farm,landuse.farmland,landuse.farmyard,landuse.livestock" --used-node --write-pbf file="$(NAME)/$@"
forest.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="landuse.forest,natural.wood" --used-node --write-pbf file="$(NAME)/$@"
grassland.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="landuse.grass,landuse.meadow,landuse.scrub,landuse.village_green,natural.scrub,natural.heath,natural.grassland" --used-node --write-pbf file="$(NAME)/$@"
helipads.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes aeroway=helipad,heliport --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
hotels.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="tourism.hotel,tourism.hostel,tourism.motel,tourism.guest_house" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
inland_water_line.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" \
--tf reject-relations --tf accept-ways waterway=* --used-node \
--write-pbf file="$(NAME)/$@"
inland_water_polygon.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" \
--tf accept-ways natural=water,wetland,bay landuse=reservoir,basin,salt_pond waterway=river,riverbank \
--tf accept-relations natural=water,wetland,bay landuse=reservoir,basin,salt_pond waterway=river,riverbank \
--used-node --write-pbf file="$(NAME)/$@"
main_roads.pbf: all_roads.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="highway.motorway,highway.trunk,highway.primary" --used-node --write-pbf file="$(NAME)/$@"
medical_point.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="amenity.baby_hatch,amenity.clinic,amenity.dentist,amenity.doctors,amenity.hospital,amenity.nursing_home,amenity.pharmacy,amenity.social_facility,amenity.veterinary,amenity.blood_donation" --write-pbf file="$(NAME)/$@"
medical_polygon.pbf: buildings.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="amenity.baby_hatch,amenity.clinic,amenity.dentist,amenity.doctors,amenity.hospital,amenity.nursing_home,amenity.pharmacy,amenity.social_facility,amenity.veterinary,amenity.blood_donation" --used-node --write-pbf file="$(NAME)/$@"
paths.pbf: all_roads.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="highway.footway,highway.bridleway,highway.steps,highway.path" --used-node --write-pbf file="$(NAME)/$@"
police_stations.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="amenity.police" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
railways.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "railway=*" --used-node --write-pbf file="$(NAME)/$@"
schools_point.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" \
--nkv keyValueList="amenity.school,amenity.university,amenity.college,amenity.kindergarten,amenity.library,amenity.public_bookcase,amenity.music_school,amenity.driving_school,amenity.language_school" \
--write-pbf file="$(NAME)/$@"
schools_polygon.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" \
--wkv keyValueList="amenity.school,amenity.university,amenity.college,amenity.kindergarten,amenity.library,amenity.public_bookcase,amenity.music_school,amenity.driving_school,amenity.language_school" \
--used-node --write-pbf file="$(NAME)/$@"
towns.pbf: all_places.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "place=town" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
tracks.pbf: all_roads.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="highway.track" --used-node --write-pbf file="$(NAME)/$@"
transport_point.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" \
--tf accept-nodes amenity=bicycle_parking,bicycle_repair_station,bicycle_rental,boat_sharing,bus_station,car_rental,car_sharing,car_wash,charging_station,ferry_terminal,fuel,grit_brin,motorcycle_parking,parking,parking_entrance,parking_space,taxi \
public_transport=* railway=halt,station,subway_entrance,tram_stop waterway=dock,boatyard \
--tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
utilities.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf reject-ways --tf reject-relations \
--tf accept-nodes amenity=shower,toilets,water_point,drinking_water,water_in_place \
--write-pbf file="$(NAME)/$@"
villages.pbf: all_places.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "place=village" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
SQL_EXPORTS = aerodromes_point.sql aerodromes_polygon.sql all_places.sql \
all_roads.sql banks.sql buildings.sql built_up_areas.sql cities.sql farms.sql \
forest.sql grassland.sql helipads.sql hotels.sql inland_water_line.sql \
inland_water_polygon.sql main_roads.sql medical_point.sql medical_polygon.sql \
paths.sql police_stations.sql railways.sql schools_point.sql schools_polygon.sql \
towns.sql tracks.sql transport_point.sql utilities.sql villages.sql
PBF_EXPORTS = $(SQL_EXPORTS:.sql=.pbf)
POSTGIS_EXPORTS = $(SQL_EXPORTS:.sql=.postgis)
%.sql: %.pbf
ogr2ogr -f PGDump $(NAME)/$@ $(NAME)/$< -lco COLUMN_TYPES=other_tags=hstore --config OSM_CONFIG_FILE conf/$(basename $@).ini
%.postgis: %.sql
psql -f $(NAME)/$< $(DB)
psql -f conf/$(basename $@)_alter.sql $(DB)
psql -f conf/clean.sql -q $(DB)
.PHONY: createdb
createdb:
if psql -lqt | cut -d \| -f 1 | grep -w $(DB); then \
echo "Database exists"; \
else \
createdb $(DB); \
psql -d $(DB) -c 'create extension postgis;'; \
psql -d $(DB) -c 'create extension hstore;'; \
fi
all: createdb $(PBF_EXPORTS) $(SQL_EXPORTS) $(POSTGIS_EXPORTS)
postgis: $(POSTGIS_EXPORTS)
.PHONY: clean
clean:
rm -rf $(NAME)/*.pbf
rm -rf $(NAME)/*.sql
if psql -lqt | cut -d \| -f 1 | grep -w $(DB); then \
psql -f conf/clean.sql -q $(DB); \
fi