[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:07:32 PST 2017
Hello all
I currently create a memory layer from an existing layer as follows
('usedFields' is a subset of the original layer's attributes/fields):
newlayer = QgsVectorLayer(uri, layer.name(), 'memory')
writer = newlayer.dataProvider()
outFeat = QgsFeature()
for feature in layer.getFeatures():
if feature.geometry() is not None:
outFeat.setGeometry(feature.geometry())
attrs = [feature[f] for f in usedFields]
if attrs:
outFeat.setAttributes(attrs)
writer.addFeatures([outFeat])
What is the best way to add only features visible in the current QGIS view
of the canvas, rather than every feature in the layer?
Thanks
Tom
-----
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-tp5303218.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
More information about the Qgis-developer
mailing list