Skip to content

Instantly share code, notes, and snippets.

@fitnr
Last active March 23, 2018 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitnr/e11bd6c2084fd030cdb22a68af110692 to your computer and use it in GitHub Desktop.
Save fitnr/e11bd6c2084fd030cdb22a68af110692 to your computer and use it in GitHub Desktop.
SHELL = bash
raster = elevation/ned/ned.vrt
vector = water/WBD/WBD.gdb
layer = 10
# ids = $(shell ogrinfo build basins -q -fields=YES -geom=NO | grep HUC$(layer) | cut -d = -f 2 | xargs)
ids = 0202000503 0202000504 0202000505 0202000506 0202000507 0202000601 0202000602 0202000603 0202000604 0202000605 0202000607 0202000608 0202000609 0202000611 0202000703 0202000704 0202000705 0202000706 0202000801 0202000802 0202000803 0202000804 0202000805 0203010101 0203010202 0203020101 0203020102 0203020103 0203020104 0203010405 0203020202 0203020203 0203020204 0203020205 0203020206 0203020207 0203020208 0203020209 0204010101 0204010102 0204010105 0204010201 0204010202 0204010203 0204010204 0204010205 0204010401 0204010402 0205010101 0205010102 0205010103 0205010104 0205010105 0205010106 0205010107 0205010108 0205010109 0205010110 0205010111 0205010112 0205010201 0205010202 0205010203 0205010204 0205010205 0205010206 0205010207 0205010208 0205010301 0205010303 0205010304 0205010305 0205010306 0205010401 0205010402 0205010403 0205010404 0205010501 0205010502 0205010503 0205010504 0205010505 0204020400 0204020504 0413000101 0413000102 0413000103 0413000202 0413000204 0413000205 0413000208 0413000209 0413000210 0413000301 0413000302 0413000303 0413000304 0413000305 0413000306 0413000307 0414010101 0414010102 0414010103 0414010104 0414010105 0414010106 0414010107 0414010201 0414010202 0414010203 0414010204 0414010205 0414010206 0414010207 0414010208 0414010209 0414010210 0414020101 0414020102 0414020103 0414020104 0414020105 0414020106 0414020107 0414020108 0414020109 0414020110 0414020111 0414020112 0414020113 0414020114 0414020115 0414020116 0414020201 0414020202 0414020203 0414020204 0414020205 0414020206 0414020207 0414020208 0414020209 0414020301 0414020302 0415010101 0415010102 0415010103 0415010104 0415010105 0415010106 0415010107 0415010108 0415010109 0415010110 0415010111 0415010112 0415010113 0415010201 0415010202 0415010203 0415010204 0415030201 0415030202 0415030203 0415030205 0415030206 0415030207 0204010301 0204010302 0204010303 0204010304 0204010305 0204010306 0204010404 0204010406 0204010408 0204010409 0204010503 0204010507 0204010601 0204010602 0204010603 0204010604 0204010605 0204010606 0204010607 0204010608 0204020102 0204020103 0204020301 0204020302 0204020303 0204020304 0204020305 0204020306 0204020307 0204020308 0204020309 0204020310 0204020501 0204020502 0205010406 0205010407 0205010601 0205010602 0205010603 0205010604 0205010605 0205010606 0205010607 0205010608 0205010609 0205010610 0205010611 0205010612 0205010613 0205010614 0205010701 0205010702 0205010703 0205010704 0205010705 0205010706 0205010707 0205010708 0205010709 0205010710 0205020105 0205020107 0415030208 0415030209 0415030210 0415030301 0415030302 0415030303 0415030304 0415030305 0415030401 0415030402 0415030403 0415030404 0415030405 0415030501 0415030502 0415030503 0415030504 0415030505 0415030506 0415030507 0415030601 0415030602 0415030603 0415030604 0415030701 0415030702 0415030801 0415040101 0415040401 0415040402 0415040403 0415040601 0415040602 0415040603 0415040604 0415040605 0415040801 0415040802 0415040806 0415040807 0415040813 0415040814 0415040816 0415030802 0415030803 0415030804 0415040815 0110000505 0203010102 0203010201 0202000606 0202000610 0203010104 0204010103 0205010405 0413000203 0202000301 0202000309 0205020204 0205020205 0205020301 0205020302 0205020303 0205020304 0205020401 0205020402 0205020403 0205020404 0205020501 0205020502 0205020503 0205020504 0205020505 0205020506 0205020601 0205020602 0205020603 0205020604 0205020605 0205020606 0205020607 0205020608 0205020609 0205020610 0205020611 0205020612 0205030101 0205030102 0205030103 0205030104 0205030105 0205030106 0205030107 0205030108 0205030109 0205030110 0205030204 0205030206 0205030207 0205030208 0205030307 0205030308 0205030401 0205030402 0205030403 0205030404 0205030405 0205030406 0205030407 0205030408 0205030409 0205030410 0205030411 0205030412 0205030501 0205030502 0205030503 0205030504 0205030505 0205030506 0205030507 0205030508 0205030509 0205030510 0205030602 0205030603 0205030604 0205030605 0205030606 0205030608 0205030609 0205030610 0205030611 0205030614 0207000407 0207000404 0207000409 0207000703 0205030601 0205030607 0205030613 0205030615 0205030617 0207000403 0207000406 0207000408 0207000410 0207000902 0204020503 0204010506 0204020203 0204020205 0204020206 0204010104 0204010106 0205010113 0205010302 0207000701 0207000803 0207000805 0207000806 0207000807 0107000501 0107000502 0108020302 0108020305 0108020401 0108020402 0108020403 0108020404 0108020601 0108020602 0109000106 0109000301 0109000403 0110000501 0108020501 0110000102 0202000306 0202000308 0109000302 0109000404 0109000407 0108020303 0108020304 0205030616 0206000100 0206000201 0206000205 0206000206 0206000301 0206000302 0206000303 0206000305 0206000306 0206000307 0206000308 0206000309 0206000310 0206000311 0206000312 0206000401 0206000402 0206000403 0206000501 0206000601 0206000602 0206000603 0206000604 0207000801 0207000802 0207000804 0207000808 0207000904 0207000905 0207000906 0207000907 0207001001 0206000203 0206000304 0207000901 0207000903 0206000202 0207000411 0207000809 0207000810 0207000405 0101000201 0101000202 0101000203 0101000204 0101000205 0101000206 0101000207 0101000301 0101000302 0101000303 0101000304 0101000401 0101000402 0101000403 0101000404 0101000405 0101000406 0101000407 0101000408 0101000409 0101000410 0101000501 0101000601 0101000701 0101000704 0101000707 0101000801 0102000103 0102000104 0102000105 0102000106 0102000107 0102000108 0102000109 0102000110 0102000201 0102000202 0102000204 0102000205 0102000301 0102000302 0102000303 0102000304 0102000305 0102000306 0102000307 0102000401 0102000402 0102000403 0102000404 0102000405 0102000406 0102000501 0102000502 0102000503 0102000504 0102000505 0102000506 0102000507 0102000508 0102000509 0102000510 0103000104 0103000105 0103000106 0103000202 0103000203 0103000205 0103000301 0103000302 0103000303 0103000304 0103000305 0103000306 0103000307 0103000308 0103000309 0103000310 0103000311 0103000312 0103000313 0103000314 0103000315 0103000316 0103000317 0103000318 0103000319 0103000320 0103000321 0103000322 0103000323 0103000324 0207000702 0415040103 0415040201 0415040202 0415040203 0415040204 0415040205 0415040301 0415040302 0415040303 0415040304 0415040305 0415040306 0415040307 0415040501 0415040502 0415040503 0415040703 0415040704 0415040705 0415040706 0415040804 0415040805 0415040808 0415040809 0415050001 0415050002 0415050003 0415040701 0415040812 0108020301 0415050000 0202000302 0202000307 0415040102 0105000103 0105000104 0105000105 0105000106 0105000201 0105000202 0105000203 0105000204 0105000205 0105000206 0105000207 0105000208 0105000209 0105000210 0105000211 0105000212 0105000213 0105000214 0105000215 0105000216 0105000217 0105000218 0105000219 0105000301 0105000302 0105000303 0105000304 0105000305 0105000306 0105000404 0105000405 0105000406 0105000409 0106000101 0106000102 0106000103 0106000104 0106000105 0106000106 0101000411 0101000502 0101000503 0101000907 0101001000 0101001002 0101001100 0102000101 0102000102 0103000102 0103000103 0103000201 0103000204 0105000107 0415060000 0101000803 0101000806 0101000807 0101000808 0101000809 0101000810 0101000901 0101000902 0101000903 0101000904 0101000905 0101001101 0105000102 0105000401 0105000403 0105000408 0415030806 0415030807 0101000602 0101000603 0101000702 0101000703 0101000705 0101000706 0101000802 0101000804 0101000805 0101000811 0101000906 0101001001 0103000101 0105000101 0105000108 0415010114 0415030204 0205030612 0204010410 0205010307 0110000502 0415040803 0105000407 0105000410 0415020001 0415020002 0415030805 0415040900 0415040702 0415040810 0415040811 0415050004 0415050005 0415050006 0105000402 0203010504 0204020201 0202000406 0205010408 0205010409 0205010506 0413000201 0501000102 0501000103 0109000405 0109000406 0109000502 0109000504 0109000409 0202000701 0203010303 0203010304 0203010305 0203010306 0203010307 0203010308 0203010401 0203010403 0203010404 0203010501 0203010502 0203010503 0203010505 0204010501 0204010502 0204010504 0204010505 0204010508 0204020101 0204020202 0204020601 0204020602 0204020603 0204020604 0204020605 0204020606 0204020607 0204030101 0204030102 0204030103 0204030104 0204030105 0204030106 0204030107 0204030108 0204030201 0204030202 0204030203 0204030204 0204030205 0202000702 0203010301 0203010302 0203010309 0203010402 0204010403 0204010405 0204010407 0204010509 0204020104 0204020204 0202000101 0202000102 0202000103 0202000104 0202000105 0202000106 0202000107 0202000201 0202000202 0202000203 0202000204 0202000205 0202000206 0202000207 0202000303 0202000304 0202000305 0202000310 0202000311 0202000401 0202000402 0202000403 0202000404 0202000405 0202000407 0202000408 0202000409 0202000410 0202000411 0202000501 0202000502 0108020502 0108020503 0108020504 0108020505 0108020506 0108020507 0108020508 0108020509 0108020701 0108020704 0108020705 0108020706 0110000104 0110000106 0110000107 0110000201 0110000202 0110000203 0110000301 0110000302 0110000303 0110000401 0110000402 0110000403 0110000503 0110000507 0110000508 0110000509 0110000510 0110000511 0110000512 0110000513 0110000601 0110000602 0110000603 0108020603 0108020702 0108020703 0110000101 0110000103 0110000504 0110000506 0110000604 0203010103 0203020300 0109000501 0109000503 0110000105 0207001002 0204020506 0204020507 0204020508 0204020701 0204020702 0204020703 0204020704 0204020705 0204020505 0206000204 0206000502 0108020107 0108020106 0107000402 0107000401 0107000613 0107000403 0108020105 0108020202 0107000404 0108020201 0107000610 0108020104 0107000611 0107000612 0107000609 0108020103 0106000308 0108020102 0107000607 0107000301 0107000608 0108010704 0108010705 0107000606 0106000310 0108010701 0106000307 0106000309 0107000302 0107000303 0108020101 0108010702 0108010606 0107000603 0108010703 0107000605 0107000306 0106000311 0107000304 0108010607 0107000602 0106000303 0107000601 0106000304 0106000306 0107000604 0106000301 0107000305 0108010605 0108010604 0106000302 0106000305 0107000107 0108010603 0107000202 0107000108 0108010602 0107000106 0106000207 0106000210 0108010404 0107000105 0108010601 0107000201 0108010505 0106000211 0106000209 0106000208 0106000206 0108010403 0107000104 0108010402 0107000103 0108010501 0106000202 0108010504 0108010502 0108010503 0106000205 0108010307 0107000102 0107000101 0108010401 0106000203 0104000210 0108010303 0106000201 0106000204 0108010305 0108010306 0104000208 0108010304 0104000209 0108010301 0104000207 0104000201 0108010302 0108010204 0108010108 0104000202 0104000206 0108010109 0108010203 0108010202 0108010106 0108010201 0104000203 0104000205 0104000106 0108010107 0104000102 0104000204 0104000105 0108010105 0108010104 0104000104 0108010103 0108010101 0108010102 0104000101 0104000103 0102000203 0109000207 0109000206 0109000205 0109000204 0109000203 0109000402 0109000408 0109000202 0109000401 0109000201 0109000108 0109000109 0109000107 0109000105 0109000104 0109000110 0109000102 0109000103 0109000101 0109000410 0415030901 0415030904 0415030905 0415030903 0415030902 0415030906 0415031001 0415031002 0415031003 0415031004 0415031005 0415031006 0107000614 0415030703 0415031007
build/maxes.geojson: $(foreach x,$(ids),build/max/$x.geojson)
ogrmerge.py -f geojson -nln maxes -overwrite_ds -single -o $@ \
$^
.PRECIOUS: build/max/%.geojson
.INTERMEDIATE: build/poly/%.geojson build/mask/%.tiff build/cut/%.vrt
build/max/%.geojson: build/poly/%.geojson | build/max
ogr2ogr -f geojson $@ $< -nlt POINT -dialect sqlite \
-sql "SELECT ST_Centroid(Geometry) Geometry, '$*' basin, DN height \
FROM polygons WHERE DN = (SELECT MAX(DN) FROM polygons)"
build/poly/%.geojson: build/cut/%.vrt build/mask/%.tiff | build/poly
gdal_polygonize.py -q -f geojson -mask $(filter %.tiff,$^) $< $@ polygons
build/mask/%.tiff: build/cut/%.vrt | build/mask
gdal_calc.py --quiet -A $< --outfile $@ \
--calc 'amax(A)==A' --NoDataValue 0 --type Byte \
--creation-option COMPRESS=DEFLATE --creation-option NBITS=1
build/cut/%.vrt: $(raster) build/basins.shp | build/cut
gdalwarp -q -of VRT -overwrite -cutline $(filter %.shp,$^) \
-cl basins -cwhere "id = '$*'" -crop_to_cutline \
$< $@
build/basins.shp: $(vector) $(raster) | build
ogr2ogr $@ $< -lco ENCODING=UTF-8 -dialect sqlite \
-sql "select ST_Buffer(SHAPE, 0) Geometry, HUC$(layer) id, NAME FROM WBDHU$(layer)" \
-spat $(shell \
gdalinfo -norat -nomd -json $(raster) | \
jq -r '.cornerCoordinates | .lowerLeft + .upperRight | .[]' | \
xargs -n 4)
build build/mask build/cut build/poly build/max: ; mkdir -p $@
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment