Skip to content

Instantly share code, notes, and snippets.

@hfs
Last active October 15, 2023 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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]]
]
]
}
}
]
}
'
@hfs
Copy link
Author

hfs commented Jan 3, 2019

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.

@prologic
Copy link

Thanks! 🙏

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