Last active
October 15, 2023 07:10
-
-
Save hfs/2c27f40bcf26cc599910714822c23dce to your computer and use it in GitHub Desktop.
Convert a GPS coordinate bounding box into GeoJSON using jq to display it e.g. on geojson.io.
This file contains hidden or 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/sh | |
jq -nR ' | |
{ | |
"type": "FeatureCollection", | |
"features": [ | |
inputs | select(length>0) | sub("[()]"; ""; "g") | split(", *"; "") | map(tonumber) | | |
{ | |
"type": "Feature", | |
"properties": {}, | |
"geometry": { | |
"type": "Polygon", | |
"coordinates": | |
[ | |
[ | |
[.[0], .[1]], | |
[.[2], .[1]], | |
[.[2], .[3]], | |
[.[0], .[3]], | |
[.[0], .[1]] | |
] | |
] | |
} | |
} | |
] | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
echo "(10.03779643865779, 53.479793558961745, 10.10029643865779, 53.51930475416199)" | bbox2geojson
You can enter several bounding boxes on separate lines and they become several rectangles in a single GeoJSON file.