I have several polygon/multipolygon shapefile layers, and used QuickOSM's Quick query to download waterways within that polygon layer by clicking "Extent of a layer" and choosing a polygon layer. But QuickOSM not only downloaded the waterways within the polygon but also those adjacent to/outside it. It looks like QuickOSM downloaded the waterways as a box/rectangle and not as the specified polygon shape.

How could I download the waterways only within the polygon layer?

  • 1
    Extent = rectangular boundary of something, in this case your whole layer. – bugmenot123 Jul 14 '17 at 16:52
  • Ok, so I need to clip it manually then.. I had thought QuickOSM had that option. – JAT86 Jul 14 '17 at 17:55
  • @bugmenot123 please turn your comment into a full answer. – AndreJ Jul 14 '17 at 19:10
  • I wasn't 100% sure this was the issue but i see stephen posted a great answer already! – bugmenot123 Jul 15 '17 at 2:59
  • Im trying to do something similar. I want to build a model where I will type the key, value and location and it will take all the multipolygon and relation data, transform into centroids, merge with the rest of the point data and finally save as an excel. However Im having problems at the start, Im not finding an algorithm like yours. I did find an algorithm that seems to build the query based on the string inputs I have. However I dont have an algorithm that generates the layers. ![Model](i.stack.imgur.com/HaU1Q.png) This second step has an outpu – Rafael Alves Dec 28 '18 at 17:39

Thank you for asking this. I use this plugin a lot, so I had a look to see if it could be automated (as I tend to always ask for similar things like highways and buildings). It turns out that several of the plugin's algorithms have been made available through Processing. This will make things much easier - clipping isn't difficult so it never occurred to me to model it!

If you want to clip to an arbitrary polygon (like clipping your roads to the outline of a state) you can do this with a processing model

Here, I asked for a small diamond area and all the buildings in it, you'll see some of the buildings have been clipped

enter image description here

Model looks like this.... (I just processed the multipolygons, but you can add to this model to process other geometries easily). There's a 'save as image' option on the graphical modeller, makes screenshots a lot easier...

enter image description here

And here's the output after pressing the 'save as python script' button. You can generate the XML using the "generate query" button using the dialog GUI. This query asks for buildings (lines & polygons only)

##result=output vector
outputs_QUICKOSMQUERYOVERPASSAPIWITHASTRING_1=processing.runalg('quickosm:queryoverpassapiwithastring', 'http://overpass-api.de/api/','<osm-script output="xml" timeout="25">\n    <union>\n        <query type="way">\n            <has-kv k="building"/>\n            <bbox-query {{bbox}}/>\n        </query>\n        <query type="relation">\n            <has-kv k="building"/>\n            <bbox-query {{bbox}}/>\n        </query>\n    </union>\n    <union>\n        <item/>\n        <recurse type="down"/>\n    </union>\n    <print mode="body"/>\n</osm-script>',extent,None,None)
outputs_QUICKOSMOGRDEFAULT_1=processing.runalg('quickosm:ogrdefault', outputs_QUICKOSMQUERYOVERPASSAPIWITHASTRING_1['OUTPUT_FILE'],None,None,None,None,None,None,None,None)
outputs_GDALOGRCLIPVECTORSBYPOLYGON_1=processing.runalg('gdalogr:clipvectorsbypolygon', outputs_QUICKOSMOGRDEFAULT_1['multipolygons_LAYER'],clipoutline,None,result)

Tip: if you're not working in 4326, switch to 4326 in OTF. That way, when you choose the layer extents when running the model, you'll get latitude and longitude extents. Otherwise you'll get the "mismatched CRS" error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.