Created
March 12, 2014 15:51
-
-
Save 3nids/9509690 to your computer and use it in GitHub Desktop.
copy/paste from/to layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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