-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
194 lines (150 loc) · 5.8 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
# moatp: workflow for creating many maps combining PostGreSQL and OSM geodata
# Copyright (C) 2016 Neil Freeman
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 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, see <http://www.gnu.org/licenses/>.
SHELL = bash
include config.ini
base = $(notdir $(basename $1))
# ogr2ogr flags and settings
PGPASSFILE ?= $(abspath .pgpass)
export PGPASSFILE
OSM_CONFIG_FILE ?= osm.ini
OSM_USE_CUSTOM_INDEXING = NO
export OSM_CONFIG_FILE OSM_USE_CUSTOM_INDEXING
HOST = $(shell cut -d : -f 1 $(PGPASSFILE))
DATABASE = $(shell cut -d : -f 3 $(PGPASSFILE))
USER = $(shell cut -d : -f 4 $(PGPASSFILE))
CONNECTION ?= dbname=$(DATABASE) host=$(HOST) user=$(USER)
OGRFLAGS = -f 'ESRI Shapefile' -lco ENCODING=UTF-8 -overwrite -skipfailures
BUFFER ?= 2640
SLUG ?= slug
GEOM ?= geom
NAME ?= name
# SVGIS flags and settings
PADDING ?= 1200
SCALE ?= 10
CSS ?= style.css
CLASSFIELDS ?= highway,railway,amenity,landuse,cycleway,bicycle,tunnel,building
DRAWFLAGS = --no-viewbox \
--inline \
--clip \
--crs file \
--scale $(SCALE) \
--padding $(PADDING) \
--precision 0 \
--simplify 90 \
$(CLASSFIELDSFLAG)
MODULATE ?= 80,80
DENSITY ?= 144
ifdef CLASSFIELDS
CLASSFIELDSFLAG = --class-fields $(CLASSFIELDS)
endif
# curl flags and settings
API ?= http://overpass-api.de/api/interpreter
OSMS = $(foreach x,$(call base,$(POINT_QUERIES) $(LINE_QUERIES) $(AREA_QUERIES)),osm/$x.osm)
# Query files, by geometry
BGS = $(foreach x,\
$(addprefix multipolygons/,$(call base,$(AREA_QUERIES)))\
$(addprefix lines/,$(call base,$(LINE_QUERIES)))\
$(addprefix points/,$(call base,$(POINT_QUERIES))),\
bg/$x.shp)
# Targets:
.PHONY: info bgs pngs shps rawshp svgs $(POLYGONS) $(POINTS) slugs
svgs pngs shps: $(foreach x,$(POLYGONS) $(POINTS),slug/$x.csv)
cat $^ | \
sed 's,^,$(@:s=)/,;s,$$,.$(@:s=),g'| \
xargs $(MAKE)
info:
@echo CONNECTION= $(CONNECTION)
@echo PSQL_PROJECTION= $(PSQL_PROJECTION)
@echo OUTPUT_PROJECTION= $(OUTPUT_PROJECTION)
@echo BBOX= $(BBOX)
@echo POLYGONS= $(POLYGONS)
@echo POINTS= $(POINTS)
@echo QUERIES= $(call base,$(POINT_QUERIES) $(LINE_QUERIES) $(AREA_QUERIES))
rawshps: $(foreach x,$(POINTS) $(POLYGONS),shp/$x.shp)
bgs: $(BGS)
osms: $(OSMS)
slugs: $(foreach x,$(POINTS) $(POLYGONS),slug/$x.csv)
# General rule for each table
$(POLYGONS) $(POINTS): %: slug/%.csv
sed 's,^,png/,;s,$$,.png,' $< | xargs $(MAKE)
.SECONDEXPANSION:
png/%.png: svg/%.svg mask/%.png names/%.csv | $$(@D)
convert \
\( -size 600x75 -pointsize 30 -font 'Helvetica.dfont' -gravity center -fill black \
caption:"$(shell grep -w $(basename $(@F)) names/$(*D).csv | csvcut -c 2 | sed -e s/\"//g)" \) \
\( -density $(DENSITY) $< -mask $(filter mask/%,$^) -modulate $(MODULATE) \
+mask $(CONVERTFLAGS) \) \
-append \
$@
composite -gravity SouthWest -geometry +20+20 logo_transparent.png \
$@ \
$@
svg/%.svg: $(CSS) $(BGS) $(MORE_GEODATA) shp/%.shp | $$(@D)
svgis draw -o $@ $(filter-out %.css,$^) $(DRAWFLAGS) --style $(CSS) --bounds $$(svgis bounds $(lastword $^))
mask/%.png: mask/%.svg
convert -density $(DENSITY) $< -negate $@
mask/%.svg: shp/%.shp | $$(@D)
svgis draw -o $@ $< $(DRAWFLAGS) --style 'polygon,.polygon{fill:black;stroke:none}' --bounds $$(svgis bounds $<)
slug/%.csv: shp/%.shp | slug
ogr2ogr /dev/stdout $< -f CSV -select $(SLUG) | \
tail -n+2 | sed -E 's,^,$*/,' > $@
shp/%.shp: $$(@D).shp | $$(@D)
ogr2ogr $@ $< $(OGRFLAGS) -t_srs $(OUTPUT_PROJECTION) \
-where "$(SLUG)='$(basename $(@F))'"
### Download place names
names/%.csv: $$(@D).csv | $$(@D)
grep $(*F) $< | cut -d, -f 2 > $@
$(foreach x,$(POLYGONS) $(POINTS),names/$x.csv): names/%.csv: shp/%.shp | names
ogr2ogr -f CSV $@ $< -select $(SLUG),$(NAME)
### Download PostGreSQL data
# POINTS and POLYGONS separately
$(foreach x,$(POINTS),shp/$x.shp): | $$(@D)
ogr2ogr $@ PG:"$(CONNECTION)" $(OGRFLAGS) -a_srs $(PSQL_PROJECTION) \
-sql "SELECT ST_Buffer($(GEOM), $(BUFFER), 120) $(GEOM), $(SLUG), $(NAME) FROM $(basename $(@F))"
$(foreach x,$(POLYGONS),shp/$x.shp): | $$(@D)
ogr2ogr $@ PG:"$(CONNECTION)" $(basename $(@F)) \
$(OGRFLAGS) -a_srs $(PSQL_PROJECTION) -select $(SLUG),$(NAME),$(GEOM)
### Download OSM data
$(BGS): bg/%.shp: osm/$$(*F).osm | $$(@D)
ogr2ogr $@ $^ $(*D) $(OGRFLAGS) -t_srs $(OUTPUT_PROJECTION)
.PRECIOUS .INTERMEDIATE: $(OSMS)
$(OSMS): osm/%.osm: osm/%.overpassql | osm
curl $(API) $(CURLFLAGS) -o $@ --data @$<
osm/%.overpassql: queries/%.overpassql | osm
sed "s/{{[bB][bB][oO][xX]}}/$(BBOX)/g;s,//.*$$,,;s/ *//;s,//.*$$,,g" $< | \
tr -d '\n' | \
sed 's,/\*.*\*/,,g' > $@
bg/lines bg/points bg/multipolygons osm slug \
$(foreach x,mask names png shp svg,$x $(addprefix $x/,$(POLYGONS) $(POINTS))):
mkdir -p $@
### install
.PHONY: install-osx install-ubuntu install-centos check
PIP = $(shell which pip)
PIPINSTALL = $(PIP) install --upgrade 'svgis[clip,simplify]>=0.4.0'
ifneq "$(notdir $(PIP))" "pip"
$(info pip not installed. Visit https://pip.pypa.io/en/stable/installing/)
endif
install-osx:
- brew install gdal --with-postgres
- brew install imagemagick --with-fontconfig --with-ghostscript
- brew install geos
sudo $(PIPINSTALL)
install-ubuntu:
apt-get -q update
apt-get -q install -y g++ libgdal1-dev gdal-bin libgeos-dev imagemagick python-dev postgresql
$(PIPINSTALL)
check:
ogr2ogr --version
ogr2ogr --formats | grep Post # Next line should say -> "PostgreSQL" (read/write)
svgis --version
convert -version