Last active
March 13, 2023 06:46
-
-
Save keichan34/b193dd55dd48b92d7f4c687650aaac62 to your computer and use it in GitHub Desktop.
Shapefileが入ったディレクトリを一括で一つのmbtilesにアーカイブする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
input=${1} | |
outdir=$(mktemp -d) | |
echo "Output: $outdir" | |
for shp in $(find "$input" -name '*.shp'); do | |
name=$(basename "$shp" .shp) | |
out_geojson="${outdir}/${name}.ndgeojson" | |
s_srs_args="" | |
if [[ ! -f "${outdir}/${name}.prj" ]]; then | |
s_srs_args="-s_srs EPSG:2446 " | |
fi | |
ogr2ogr $s_srs_args -t_srs EPSG:4326 -f GeoJSONSeq "${out_geojson}" -oo "ENCODING=CP932" "${shp}" | |
out_geojson2="${outdir}/${name}.1.ndgeojson" | |
jq -cr --arg 'class' "$name" '.properties.class = $class' "$out_geojson" > "$out_geojson2" | |
done | |
merged_geojson="./out.ndgeojson" | |
find "${outdir}" -name '*.1.ndgeojson' -print0 | xargs -0 cat > "${merged_geojson}" | |
tippecanoe \ | |
-Z0 -z14 \ | |
--read-parallel \ | |
--force \ | |
--layer="main" \ | |
--output=./out.mbtiles \ | |
"$merged_geojson" | |
merged_regular_geojson="./out.geojson" | |
jq -s '{"type": "FeatureCollection", "features": .}' "$merged_geojson" > "$merged_regular_geojson" | |
rm -r "$outdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment