-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from abettermap/27.slim-geojson
Optimize GeoJSON
- Loading branch information
Showing
2 changed files
with
38 additions
and
209 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
|
||
# ----------------------------- | ||
# shp-to-geojson.sh | ||
# Convert shapefiles to GeoJSON | ||
# ----------------------------- | ||
|
||
SOURCE_SHP="${1:-cerp/static/VoterPrecinct.shp}" | ||
DEST_GEOJSON="${2:-cerp/static/VoterPrecinct.geojson}" | ||
FIELDS_TO_KEEP="PRECINCT,SENATEDIST,HOUSEDIST,COMMDIST,UPDATEDATE" | ||
TOLERANCE=0.00015 # smaller decimal = higher precision | ||
|
||
# ogr2ogr cannot overwrite GeoJSON? | ||
rm -f $DEST_GEOJSON | ||
|
||
# Convert shp to geojson | ||
ogr2ogr \ | ||
-f "GeoJSON" \ | ||
-lco COORDINATE_PRECISION=5 \ | ||
-simplify $TOLERANCE \ | ||
-select $FIELDS_TO_KEEP \ | ||
"$DEST_GEOJSON.tmp" \ | ||
$SOURCE_SHP | ||
|
||
# Check if `json-minify` exists, install if not | ||
if ! type json-minify &> /dev/null; then | ||
npm i -g json-minify | ||
fi | ||
|
||
# Minify GeoJSON | ||
json-minify "$DEST_GEOJSON.tmp" > $DEST_GEOJSON | ||
|
||
# Delete temp file | ||
rm "$DEST_GEOJSON.tmp" | ||
|
||
# topojson example | ||
# topojson $DEST_GEOJSON > "$DEST_GEOJSON.topojson" -p |
Oops, something went wrong.