[Qgis-developer] Create memory layer containing only features visible in current canvas extent

Matthias Kuhn matthias at opengis.ch
Thu Jan 12 08:41:57 PST 2017


http://www.qgis.org/api/classQgsFeatureRequest.html#ac7c734b9cab6939a706ea53040afe6b3

that might help

On January 12, 2017 5:20:07 PM GMT+01:00, Tom Chadwin <tom.chadwin at nnpa.org.uk> wrote:
>I've found this method:
>
>viewportPolygon =
>QgsGeometry().fromWkt(iface.mapCanvas().extent().asWktPolygon())
>layer = iface.activeLayer()
>
>resultlayer = QgsVectorLayer("Polygon", "result", "memory")
>resultlayer.dataProvider().addAttributes(list(layer.dataProvider().fields()))
>
>clippedFeatures = []
>for feature in layer.dataProvider().getFeatures():
>    clippedGeometry = feature.geometry().intersection(viewportPolygon)
>
>
>From http://gis.stackexchange.com/a/74471/36921
>
>However, this loops through all features. I'm concerned that this will
>struggle with large layers. Is there a more efficient method?
>
>
>
>-----
>Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon 
>--
>View this message in context:
>http://osgeo-org.1560.x6.nabble.com/Create-memory-layer-containing-only-features-visible-in-current-canvas-extent-tp5303218p5303223.html
>Sent from the Quantum GIS - Developer mailing list archive at
>Nabble.com.
>_______________________________________________
>Qgis-developer mailing list
>Qgis-developer at lists.osgeo.org
>List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170112/f7a47544/attachment.html>


More information about the Qgis-developer mailing list