Skip to content

Instantly share code, notes, and snippets.

@3nids
Created March 12, 2014 15:51
Show Gist options
  • Save 3nids/9509690 to your computer and use it in GitHub Desktop.
Save 3nids/9509690 to your computer and use it in GitHub Desktop.
copy/paste from/to layer
src = iface.activeLayer()
dst = QgsMapLayerRegistry.instance().mapLayer("cadastre20140312152032371")
featReq = QgsFeatureRequest().setSubsetOfAttributes([])
k = 0
features = []
nonCopied = []
for f in src.getFeatures(featReq):
k += 1
if k % 100 ==0:
print k
geom = f.geometry().convertToType( QGis.Line, False )
if geom:
f = QgsFeature()
f.setGeometry(QgsGeometry.fromWkt(geom.exportToWkt()))
f.initAttributes(2)
features.append(f)
else:
nonCopied.append(f.geometry())
dst.beginEditCommand( "Features pasted" )
print dst.addFeatures( features )
dst.endEditCommand()
print " % features" % k
print " % copied" % len(features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment