Skip to content

Commit

Permalink
add helpers scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Dec 19, 2023
1 parent e51df90 commit 7d5b3d7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/generate_cog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
generate_cog () {
local MASK=$(mktemp .cog.XXXXXXX.tif -p .)
local NORMALIZED=$(mktemp .cog.XXXXXXX.tif -p .)
local RGBA=$(mktemp .cog.XXXXXXX.tif -p .)

gdal_translate -co NUM_THREADS=ALL_CPUS -scale 1 4 255 255 $1 $MASK
gdal_translate -co NUM_THREADS=ALL_CPUS -scale 1 4 0 255 $1 $NORMALIZED
gdal_merge.py -separate -o $RGBA -of GTiff -co NUM_THREADS=ALL_CPUS $NORMALIZED $NORMALIZED $NORMALIZED $MASK
gdal_translate $RGBA $1.cog -of COG -co NUM_THREADS=ALL_CPUS -co TARGET_SRS=EPSG:3857 -co ADD_ALPHA=NO -co COMPRESS=LZW -co LEVEL=9
rm $MASK $NORMALIZED $RGBA
}

generate_color_cog () {
local RGBA=$(mktemp .cog.XXXXXXX.tif -p .)

gdaldem color-relief $1 $2 $RGBA -alpha
gdal_translate $RGBA $1.cog -of COG -co TARGET_SRS=EPSG:3857 -co ADD_ALPHA=NO -co COMPRESS=LZW -co LEVEL=9
rm $RGBA
}
21 changes: 21 additions & 0 deletions scripts/generate_style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pathlib
import sys
import json

BASE = pathlib.Path('.')

SOURCES = {}

for filepath in BASE.iterdir():
if not filepath.is_dir() and 'cog' in filepath.suffix:
name, first_dot, rest = filepath.name.partition('.')
SOURCES[name] = {
"type": "raster",
"url": f"cog:///datasets/{BASE.absolute().parent.name}/{BASE.absolute().name}/{filepath}"
}


print(json.dumps({
"sources": SOURCES,
"layers": [{"id": k, "type": "raster", "source": k} for k in SOURCES.keys()]
}))

0 comments on commit 7d5b3d7

Please sign in to comment.