Skip to content

Instantly share code, notes, and snippets.

@hfs
Last active October 15, 2023 07:10
Show Gist options
  • Save hfs/2c27f40bcf26cc599910714822c23dce to your computer and use it in GitHub Desktop.
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.
#!/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]]
]
]
}
}
]
}
'
@prologic
Copy link

Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment