Sophox / sophox

A collection of services exposing OSM data, metadata, and other microservices
Apache License 2.0
31 stars 5 forks source link

GeoJSON export #20

Open 1ec5 opened 4 years ago

1ec5 commented 4 years ago

The Download menu offers JSON as an export format, but that format represents geodata as WKT strings, whereas many OSM-related tools consume GeoJSON. It would be handy to be able to export GeoJSON directly from Sophox. Like the Map view, the features could come from the first WKT-formatted column, and all the other columns could become properties of those features.

1ec5 commented 4 years ago

A workaround is to transform the JSON into GeoJSON on the command line using a tool like jq. For instance, this command creates GeoJSON (with formatting compatible with the simplestyle specification) from a query that was formatted to work with the Map view:

jq '{type: "FeatureCollection", features: map({type: "Feature", properties: {name: .name, type: .layer, "marker-size": "small", "marker-color": ("#" + .rgb)}, geometry: {type: "Point", coordinates: (.coordinates | match("Point\\(([-.\\d]+) ([-.\\d]+)\\)").captures | map(.string | tonumber))}})}' query.json > query.geojson
1ec5 commented 4 years ago

@nonoumasy pointed out that csv2geojson is another command-line tool that can transform Sophox’s CSV output into GeoJSON.