Skip to content

Instantly share code, notes, and snippets.

@naogify
Last active September 13, 2024 07:13
Show Gist options
  • Save naogify/a2aa57f8f322a063a4af1f9cce300c5f to your computer and use it in GitHub Desktop.
Save naogify/a2aa57f8f322a063a4af1f9cce300c5f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -ex
find . -name "*.shp" | while read -r shpfile; do
base=$(dirname "$shpfile")/$(basename "$shpfile" .shp)
# .prj ファイルが Shift_JIS だと ogr2ogr でエラーが出るので UTF-8 に変換
if [ -f "${base}.prj" ]; then
encoding=$(nkf --guess "${base}.prj")
if [ "$encoding" = "Shift_JIS" ]; then
nkf --overwrite -w "${base}.prj"
fi
fi
# TODO cpg ファイルがあれば使うように修正
ogr2ogr -f GeoJSON -oo ENCODING=CP932 -t_srs crs:84 "${base}.geojson" "$shpfile"
echo "Convert Shape to ${base}.geojson"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment