[OSM-talk] How to save Overpass query results to a GeoJSON file with Python?
Mateusz Konieczny
matkoniecz at tutanota.com
Mon Mar 11 13:15:54 UTC 2019
Mar 11, 2019, 11:18 AM by talk at openstreetmap.org:
> Dear colleagues,
>
> I have just started to use Python and I would like to make a query to Overpass and store the results in a geospatial format (e.g. GeoJSON) so I can programatically update the data.
>
> As far as I know, there is a library called > overpy> that should be what I am looking for. After reading > its documentation <https://python-overpy.readthedocs.io/en/latest/example.html>> I came up with the following code:
>
> import> overpyAPI > => overpy> .> Overpass> ()> # Fetch highways within Granollers' city.> result > => API> .> query> (> """ area[name="Granollers"][admin_level=8]; // query part for: “highway=*” (way["highway"](area); relation["highway"](area); ); // print results out body; """> )
>
> The thing is that I am not familiar at all with Python and I don't know how to store > result> as a GeoJSON file (Honestly, I don't even know what kind of thing > result> is -I tried with > type(result)> and I get > overpy.Result> as an output, which doesn't mean much to my poor knowledge). I have been reading > overpy> documentation but I haven't been able to figure it out.
>
> Can anyone give me a clue with this?
>
Are you familiar with http://overpass-turbo.eu/ <http://overpass-turbo.eu/> https://wiki.openstreetmap.org/wiki/Overpass_turbo <https://wiki.openstreetmap.org/wiki/Overpass_turbo> ?
There are two parts here
(1) using overpass itself
(2) writing python script
That are separate (you can call Overpass API from any program, not just python)
"I have just started to use Python" - note that it means learning two separate languages at once:
(1) Python itself
(2) Overpass query syntax
PS In case that Overpass is new for you my page may be of some use:
https://mapsaregreat.com/geographic-data-mining-and-visualisation-for-beginners/overpass-turbo-tutorial.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/talk/attachments/20190311/9b13a444/attachment.html>
More information about the talk
mailing list