<div dir="ltr"><div dir="ltr">I use the overpass library (I think it's the one you mentioned). The resulting dictionary can be coerced to a string and written out and it should be valid geojson.</div><div dir="ltr"><pre style="color:rgb(0,0,0)"><pre style="user-select: text; top: -99px;">#!/usr/bin/python3
import overpass
api = overpass.API()
result = api.get('area[name="Granollers"][admin_level=8];(nwr["highway"](area);relation["highway"](area););')
with open('results.geojson', 'w') as fd:
    fd.write(str(result))</pre><pre style="user-select: text; top: -99px;"><br></pre></pre></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 11, 2019 at 8:04 AM Carlos Cámara Menoyo via talk <<a href="mailto:talk@openstreetmap.org">talk@openstreetmap.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Thanks for your reply, Mateusz.<br></div><div><br></div><div>I know (and use) Overpass turbo. However, what I want to do is to store a query and execute it in order to update results and store them as a file for further manipulation, so I can easily update results without the need to accessing to the interface, generate the query, run it and then download the results. I would like to achieve same functionallity but just by executing a file (which, additionally, may have more than one query).<br></div><div><br></div><div>So far, I found <a rel="nofollow" title="https://github.com/DinoTools/python-overpy" href="https://github.com/DinoTools/python-overpy" target="_blank">overpy</a>, which seems to work fine in terms of querying but has two problems for me: <br></div><ol><li>It seems to be unmaintained (last commit dates from April 2017)<br></li><li>I didn't succeed in storing the result into a geospatial file (or a geopandas data frame) (visit this jupyter lab with my current achievements: <a href="https://github.com/ccamara/osm-python/blob/master/overpy-demo.ipynb" target="_blank">https://github.com/ccamara/osm-python/blob/master/overpy-demo.ipynb</a>)<br></li></ol><div>I also have just found <a rel="nofollow" title="https://github.com/mvexel/overpass-api-python-wrapper" href="https://github.com/mvexel/overpass-api-python-wrapper" target="_blank">Overpass API wrapper</a>, but I still have to explore it and understand how does it work and how can I tame it to my needs.<br></div><div><br></div><div>You propose a third way, which is using overpass and writing a script. It is not clear to me what do you mean with that, since I thought that that was precisely what I was attempting. Could you be more specific, please? Do you have other insight?<br></div><div><br></div><div>Regards,<br></div><div>Carlos<br></div><div><br></div><div><br></div><div class="gmail-m_6020311332712263367protonmail_signature_block"><div class="gmail-m_6020311332712263367protonmail_signature_block-user"><div>Carlos Cámara-Menoyo<br></div><div><a href="https://carloscamara.es" title="https://carloscamara.es" target="_blank">https://carloscamara.es</a><br></div></div><div class="gmail-m_6020311332712263367protonmail_signature_block-proton gmail-m_6020311332712263367protonmail_signature_block-empty"><br></div></div><div><br></div><div>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br></div><div> On Monday 11 March de 2019 a les 14:15, Mateusz Konieczny <<a href="mailto:matkoniecz@tutanota.com" target="_blank">matkoniecz@tutanota.com</a>> wrote:<br></div><div> <br></div><blockquote class="gmail-m_6020311332712263367protonmail_quote" type="cite"><div><br></div><div><br></div><div><br></div><div>Mar 11, 2019, 11:18 AM by <a href="mailto:talk@openstreetmap.org" target="_blank">talk@openstreetmap.org</a>:<br></div><blockquote style="border-left:1px solid rgb(147,163,184);padding-left:10px;margin-left:5px"><div>Dear colleagues,<br></div><div><br></div><div>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.<br></div><div><p>As far as I know, there is a library called <code>overpy</code> that should be what I am looking for. After reading <a rel="noopener noreferrer" href="https://python-overpy.readthedocs.io/en/latest/example.html" target="_blank">its documentation</a> I came up with the following code:<br></p><pre><code><span>
</span><span>import</span><span> overpy

API </span><span>=</span><span> overpy</span><span>.</span><span>Overpass</span><span>()</span><span>

</span><span># Fetch highways within Granollers' city.</span><span>

result </span><span>=</span><span> API</span><span>.</span><span>query</span><span>(</span><span>"""
    area[name="Granollers"][admin_level=8];
    // query part for: “highway=*”
    (way["highway"](area);
    relation["highway"](area);
    );
    // print results
    out body;
    """</span><span>)</span><span>
</span></code><br></pre><p>The thing is that I am not familiar at all with Python and I don't know how to store <code>result</code> as a GeoJSON file (Honestly, I don't even know what kind of thing <code>result</code> is -I tried with <code>type(result)</code> and I get <code>overpy.Result</code> as an output, which doesn't mean much to my poor knowledge). I have been reading <code>overpy</code> documentation but I haven't been able to figure it out.<br></p></div><div><div>Can anyone give me a clue with this?<br></div></div></blockquote><div>Are you familiar with <a href="http://overpass-turbo.eu/" target="_blank">http://overpass-turbo.eu/</a> <a href="https://wiki.openstreetmap.org/wiki/Overpass_turbo" target="_blank">https://wiki.openstreetmap.org/wiki/Overpass_turbo</a> ?<br></div><div><br></div><div>There are two parts here<br></div><div><br></div><div>(1) using overpass itself<br></div><div>(2) writing python script<br></div><div><br></div><div>That are separate (you can call Overpass API from any program, not just python)<br></div><div><br></div><div>"I have just started to use Python" - note that it means learning two separate languages at once:<br></div><div><br></div><div>(1) Python itself<br></div><div>(2) Overpass query syntax<br></div><div><br></div><div>PS In case that Overpass is new for you my page may be of some use:<br></div><div><br></div><div><a href="https://mapsaregreat.com/geographic-data-mining-and-visualisation-for-beginners/overpass-turbo-tutorial.html" target="_blank">https://mapsaregreat.com/geographic-data-mining-and-visualisation-for-beginners/overpass-turbo-tutorial.html</a><br></div></blockquote><div><br></div>_______________________________________________<br>
talk mailing list<br>
<a href="mailto:talk@openstreetmap.org" target="_blank">talk@openstreetmap.org</a><br>
<a href="https://lists.openstreetmap.org/listinfo/talk" rel="noreferrer" target="_blank">https://lists.openstreetmap.org/listinfo/talk</a><br>
</blockquote></div></div>