forked from GFDRR/osm-extract
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
234 lines (172 loc) · 10.7 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
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
# 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)
EXPORT_DIR=/var/www/html/$(NAME)/data
mk-work-dir:
mkdir -p ./$(NAME)
latest.pbf: mk-work-dir
curl -g -o $(NAME)/[email protected] $(URL)
if file $(NAME)/[email protected] | grep XML; then \
osmosis --read-xml file="$(NAME)/[email protected]" --write-pbf file="$(NAME)/$@"; \
else \
mv $(NAME)/[email protected] $(NAME)/$@; \
fi
buildings.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "building=*" --write-pbf file="$(NAME)/$@"
bridges.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "bridge=*" --write-pbf file="$(NAME)/$@"
idp_camps.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="idp:camp_site=spontaneous_camp,damage:event.dominica_earthquake_2015" --used-node --write-pbf file="$(NAME)/$@"
huts.pbf: buildings.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "building=hut" --used-node --write-pbf file="$(NAME)/$@"
trees.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "natural=tree" --tf reject-ways --tf reject-relations --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" --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" --used-node --write-pbf file="$(NAME)/$@"
medical_point.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="amenity.hospital,amenity.doctors,amenity.doctor,amenity.clinic,amenity.health_post" --write-pbf file="$(NAME)/$@"
medical_polygon.pbf: buildings.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="amenity.hospital,amenity.doctors,amenity.doctor,amenity.clinic,amenity.health_post" --used-node --write-pbf file="$(NAME)/$@"
roads.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "highway=*" --used-node --write-pbf file="$(NAME)/$@"
rivers.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="waterway.river,waterway.stream,waterway.ditch" --used-node --write-pbf file="$(NAME)/$@"
riverbanks.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="waterway.riverbank" --used-node --write-pbf file="$(NAME)/$@"
lakes.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="natural.water,water.lake" --used-node --write-pbf file="$(NAME)/$@"
beaches.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="natural.beach" --used-node --write-pbf file="$(NAME)/$@"
farms.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="landuse.farm,landuse.farmland,landuse.farmyard" --used-node --write-pbf file="$(NAME)/$@"
forest.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="landuse.forest" --used-node --write-pbf file="$(NAME)/$@"
grassland.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="landuse.grass,landuse.grassland,natural.wood,natural.grassland" --used-node --write-pbf file="$(NAME)/$@"
military.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "landuse=military" --used-node --write-pbf file="$(NAME)/$@"
orchards.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "landuse=orchard" --used-node --write-pbf file="$(NAME)/$@"
residential.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "landuse=residential" --used-node --write-pbf file="$(NAME)/$@"
village_green.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "landuse=village_green" --used-node --write-pbf file="$(NAME)/$@"
wetlands.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-ways "landuse=wetland" --used-node --write-pbf file="$(NAME)/$@"
cities.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "place=city" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
hamlets.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "place=hamlet" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
neighborhoods.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="place.neighborhood,place.neighbourhood" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
villages.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "place=village" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
placenames.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="place.city,place.hamlet,place.neighborhood,place.neighbourhood,place.village" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
all_roads.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="highway.unclassified,highway.tertiary,highway.residential,highway.service,highway.secondary,highway.track,highway.footway,highway.path,highway.classified,highway.primary,highway.trunk,highway.motorway,highway.construction,highway.proposed,highway.cycleway,highway.living_street,highway.steps,highway.road,highway.pedestrian,highway.construction,highway.bridleway,highway.platformhighway.proposed" --used-node --write-pbf file="$(NAME)/$@"
main_roads.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="highway.motorway,highway.trunk,highway.primary" --used-node --write-pbf file="$(NAME)/$@"
paths.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="highway.path,highway.trunk,highway.primary" --used-node --write-pbf file="$(NAME)/$@"
tracks.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="highway.track" --used-node --write-pbf file="$(NAME)/$@"
aerodromes_point.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="aeroway.aerodrome,aeroway.international" --write-pbf file="$(NAME)/$@"
aerodromes_polygon.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="aeroway.aerodrome,aeroway.international" --used-node --write-pbf file="$(NAME)/$@"
banks.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "amenity=bank" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
fire_stations.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "amenity=fire_station" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
hotels.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="tourism.hotel,amenity.hotel" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
police_stations.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="amenity.police,tourism.police" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
restaurants.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --nkv keyValueList="amenity.restaurant,amenity.restaurants" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
train_stations.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --tf accept-nodes "railway=station" --tf reject-ways --tf reject-relations --write-pbf file="$(NAME)/$@"
helipads.pbf: latest.pbf
osmosis --read-pbf-fast file="$(NAME)/$<" --wkv keyValueList="aeroway.helipad" --used-node --write-pbf file="$(NAME)/$@"
SQL_EXPORTS = buildings.sql schools_point.sql schools_polygon.sql medical_point.sql medical_polygon.sql rivers.sql riverbanks.sql lakes.sql farms.sql forest.sql grassland.sql military.sql residential.sql cities.sql hamlets.sql neighborhoods.sql villages.sql placenames.sql all_roads.sql main_roads.sql paths.sql tracks.sql aerodromes_point.sql aerodromes_polygon.sql banks.sql hotels.sql police_stations.sql restaurants.sql train_stations.sql helipads.sql # orchards.sql
EXPORTS = $(SQL_EXPORTS:.sql=)
PBF_EXPORTS = $(SQL_EXPORTS:.sql=.pbf)
POSTGIS_EXPORTS = $(SQL_EXPORTS:.sql=.postgis)
SQL_ZIP_EXPORTS = $(SQL_EXPORTS:.sql=.sql.zip)
SHP_ZIP_EXPORTS = $(SQL_EXPORTS:.sql=.shp.zip)
GEOJSON_EXPORTS = $(SQL_EXPORTS:.sql=.json)
GEOPACKAGE_EXPORTS = $(SQL_EXPORTS:.sql=.gpkg)
KML_EXPORTS = $(SQL_EXPORTS:.sql=.kml)
%.sql: %.pbf
ogr2ogr -f PGDump $(NAME)/$@ $(NAME)/$< -lco COLUMN_TYPES=other_tags=hstore --config OSM_CONFIG_FILE conf/$(basename $@).ini
%.shp: %.postgis
pgsql2shp -f $(NAME)/$(basename $@) $(DB) public.$(basename $<)
%.json: %.shp
ogr2ogr -f GeoJSON -t_srs crs:84 $(NAME)/$@ $(NAME)/$<
%.kml: %.shp
ogr2ogr -f KML -t_srs crs:84 $(NAME)/$@ $(NAME)/$<
%.shp.zip: %.shp
zip $(NAME)/$@ $(NAME)/$< $(NAME)/$(basename $<).prj $(NAME)/$(basename $<).dbf $(NAME)/$(basename $<).shx
%.gpkg: %.shp
ogr2ogr -f GPKG -t_srs crs:84 -append $(SETNAME)/$(SETNAME).gpkg $(NAME)/$<
%.sql.zip: %.sql
zip $(NAME)/$@ $(NAME)/$<
%.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) $(SQL_ZIP_EXPORTS) $(SHP_ZIP_EXPORTS) $(GEOJSON_EXPORTS) $(GEOPACKAGE_EXPORTS) $(KML_EXPORTS) stats.js mapproxy
cp index.html $(NAME)/
sed -i.bk -e 's/Fiji/$(NAME)/' $(NAME)/index.html
rm $(NAME)/index.html.bk
postgis: $(POSTGIS_EXPORTS)
stats.js:
python stats.py --name="$(NAME)" --files="$(EXPORTS)" >> $(NAME)/$@
.PHONY:
mapproxy:
cp mapnik.xml $(NAME)/
cp mapproxy.yaml $(NAME)/
sed -i.bk -e 's/REPLACEME/$(NAME)/' $(NAME)/mapnik.xml
sed -i.bk -e 's/REPLACEME/$(NAME)/' $(NAME)/mapproxy.yaml
.PHONY: clean
clean:
rm -rf $(NAME)/*.pbf
rm -rf $(NAME)/*.zip
rm -rf $(NAME)/*.sql
rm -rf $(NAME)/*.shp
rm -rf $(NAME)/*.dbf
rm -rf $(NAME)/*.shx
rm -rf $(NAME)/*.prj
rm -rf $(NAME)/*.json
rm -rf $(SETNAME)/*.gpkg
rm -rf $(NAME)/*.kml
rm -rf $(NAME)/*.cpg
rm -rf $(NAME)/stats.js
if psql -lqt | cut -d \| -f 1 | grep -w $(DB); then \
psql -f conf/clean.sql -q $(DB); \
fi