[Qgis-developer] Create memory layer containing only features visible in current canvas extent
Tom Chadwin
tom.chadwin at nnpa.org.uk
Thu Jan 12 08:20:07 PST 2017
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.
More information about the Qgis-developer
mailing list