From 7b5a6e031106c3cff736208c6af485ef0ea37bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 16 Dec 2020 08:45:54 +0200 Subject: [PATCH] consolidate to one Makefile --- contours/Makefile | 59 ++++++++++++++++++++++++++++++++++++++++++ contours/Makefile.2008 | 25 +++++++----------- contours/Makefile.2017 | 2 +- contours/config.mk | 8 ++++++ 4 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 contours/Makefile create mode 100644 contours/config.mk diff --git a/contours/Makefile b/contours/Makefile new file mode 100644 index 0000000..c0aceb9 --- /dev/null +++ b/contours/Makefile @@ -0,0 +1,59 @@ +include config.mk + +OUTSIZE = $(shell awk $(addprefix -v ,$(BOUNDS)) 'BEGIN{print ymax-ymin" "xmax-xmin}' /dev/null) +XYZ = $(patsubst %.zip,%.xyz,$(wildcard 6*.zip)) +SORT = sort -n -k2 -k1 -t, + +.PHONY: all +all: smooth_2_5.gpkg smooth_5.gpkg + +smooth_%.gpkg: db/smooth_% + ogr2ogr $@ "PG:host=127.0.0.1 user=osm dbname=osm password=osm" $(basename $@) + +db/smooth_%: db/contour_% chaikin.sql + ./managedb -- --echo-all \ + -v ON_ERROR_STOP=1 \ + -v src=$(notdir $(basename $<)) \ + -v tbl=$(notdir $(basename $@)) \ + -f chaikin.sql + touch $@ + +db/contour_%: contour_%.gpkg db/.ready + ./managedb -- -c "DROP TABLE IF EXISTS $(basename $<)" + ogr2ogr -f PostgreSQL "PG:host=127.0.0.1 user=osm dbname=osm password=osm" $< + touch $@ + +contour_%.gpkg: all.tif + gdal_contour -nln $(basename $@) -i $(subst _,.,$*) -a z $^ $@ + +ifeq ($(VARIANT),2009) +all.tif: all.vrt all.xyz + gdal_grid $< $@ \ + -a nearest \ + -ot Float32 -co COMPRESS=DEFLATE -co PREDICTOR=2 \ + -outsize $(OUTSIZE) +else +ifeq ($(VARIANT),2017) +all.tif: all.vrt all.xyz + gdal_translate $< $@ \ + -ot Float32 -a_srs EPSG:3346 \ + -co COMPRESS=DEFLATE -co PREDICTOR=2 +else +$(error VARIANT must be 2009 or 2017) +endif +endif + +.INTERMEDIATE: all.xyz +all.xyz: $(XYZ) + $(SORT) -m $^ > $@ + +.INTERMEDIATE: $(XYZ) +%.xyz: %.zip + unzip -qq -c $< $@ | \ + ./clip-2009.awk $(addprefix -v ,$(BOUNDS)) | \ + $(SORT) > $@ + +db/.ready: managedb + mkdir -p db + ./managedb start + touch $@ diff --git a/contours/Makefile.2008 b/contours/Makefile.2008 index d0899e9..514fc6e 100644 --- a/contours/Makefile.2008 +++ b/contours/Makefile.2008 @@ -1,10 +1,7 @@ -#uzupis -#BOUNDS = xmin=582700 ymin=6060750 xmax=584830 ymax=6062750 #krekenava -#BOUNDS = xmin=493674 ymin=6146103 xmax=518869 ymax=6171741 -BOUNDS = xmin=504440 ymin=6154741 xmax=507410 ymax=6158941 -#OUTSIZE = $(shell awk $(addprefix -v ,$(BOUNDS)) 'BEGIN{print ymax-ymin" "xmax-xmin}' /dev/null) -OUTSIZE = $(shell awk $(addprefix -v ,$(BOUNDS)) 'BEGIN{print int((ymax-ymin)/8)" "int((xmax-xmin)/8)}' /dev/null) +BOUNDS = xmin=493674 ymin=6146103 xmax=518869 ymax=6171741 +#BOUNDS = xmin=504440 ymin=6154741 xmax=507410 ymax=6158941 +OUTSIZE = $(shell awk $(addprefix -v ,$(BOUNDS)) 'BEGIN{print ymax-ymin" "xmax-xmin}' /dev/null) XYZ = $(patsubst %.zip,%.xyz,$(wildcard 6*.zip)) SORT = sort -n -k2 -k1 -t, @@ -12,7 +9,7 @@ SORT = sort -n -k2 -k1 -t, all: smooth_2_5.gpkg smooth_5.gpkg smooth_%.gpkg: db/smooth_% - ogr2ogr $@ "PG:host=127.0.0.1 user=osm dbname=osm" $(basename $@) + ogr2ogr $@ "PG:host=127.0.0.1 user=osm dbname=osm password=osm" $(basename $@) db/smooth_%: db/contour_% chaikin.sql ./managedb -- --echo-all \ @@ -24,19 +21,17 @@ db/smooth_%: db/contour_% chaikin.sql db/contour_%: contour_%.gpkg db/.ready ./managedb -- -c "DROP TABLE IF EXISTS $(basename $<)" - ogr2ogr -f PostgreSQL "PG:host=127.0.0.1 user=osm dbname=osm" $< + ogr2ogr -f PostgreSQL "PG:host=127.0.0.1 user=osm dbname=osm password=osm" $< touch $@ contour_%.gpkg: all.tif gdal_contour -nln $(basename $@) -i $(subst _,.,$*) -a z $^ $@ -all-grid.tif: all.vrt all.xyz - gdal_grid $< $@ -ot Float32 -outsize $(OUTSIZE) - -all.tif: all-grid.tif - gdal_translate $< $@ \ - -ot Float32 -a_srs EPSG:3346 \ - -co COMPRESS=DEFLATE -co PREDICTOR=2 +all.tif: all.vrt all.xyz + gdal_grid $< $@ \ + -a nearest \ + -ot Float32 -co COMPRESS=DEFLATE -co PREDICTOR=2 \ + -outsize $(OUTSIZE) .INTERMEDIATE: all.xyz all.xyz: $(XYZ) diff --git a/contours/Makefile.2017 b/contours/Makefile.2017 index 5e7226a..a0beaf7 100644 --- a/contours/Makefile.2017 +++ b/contours/Makefile.2017 @@ -1,6 +1,6 @@ #uzupis BOUNDS = xmin=582700 ymin=6060750 xmax=584830 ymax=6062750 -XYZ = $(patsubst %.zip,%.xyz,$(wildcard 6*.zip)) +XYZ = $(patsubst %.zip,%.xyz,$(wildcard *.zip)) SORT = sort -n -k2 -k1 -t, .PHONY: all diff --git a/contours/config.mk b/contours/config.mk new file mode 100644 index 0000000..a5cf1f1 --- /dev/null +++ b/contours/config.mk @@ -0,0 +1,8 @@ +#krekenava +#BOUNDS = xmin=504440 ymin=6154741 xmax=507410 ymax=6158941 +BOUNDS = xmin=493674 ymin=6146103 xmax=518869 ymax=6171741 +VARIANT = 2009 + +#uzupis +#BOUNDS = xmin=582700 ymin=6060750 xmax=584830 ymax=6062750 +#VARIANT=2017