I have a layer containing linestrings and want to move those that are too close to each other.
I seem to be missing something in the moving part though:
layer = iface.activeLayer()def moveFeature (fId,dx,dy): layer.startEditing() layerUtil = QgsVectorLayerEditUtils( layer ) result = layerUtil.translateFeature(fId,dx,dy) layer.commitChanges() layer.triggerRepaint() return resultsince the coordinates of the first point of any feature before and after move are the same (thoug the feature is moved in the map view) ie the piece of code:
for feature in layer.getFeatures(): if feature.attribute("IDR_LIT") == "EGUZOL71RUEYR": print feature.attribute("IDR_LIT") print "before move coordinates: %d;%d"%(feature.geometry().asPolyline()[0][0],feature.geometry().asPolyline()[0][1]) moveFeature(feature.id(), 1111,1111) layer.updateFeature(feature) print "after coordinates: %d;%d"%(feature.geometry().asPolyline()[0][0],feature.geometry().asPolyline()[0][1])prints:
EGUZOL71RUEYRbefore move coordinates: 675392;6408936after coordinates: 675392;6408936Does anyone has a hint about this?Thanks
أكثر...
I seem to be missing something in the moving part though:
layer = iface.activeLayer()def moveFeature (fId,dx,dy): layer.startEditing() layerUtil = QgsVectorLayerEditUtils( layer ) result = layerUtil.translateFeature(fId,dx,dy) layer.commitChanges() layer.triggerRepaint() return resultsince the coordinates of the first point of any feature before and after move are the same (thoug the feature is moved in the map view) ie the piece of code:
for feature in layer.getFeatures(): if feature.attribute("IDR_LIT") == "EGUZOL71RUEYR": print feature.attribute("IDR_LIT") print "before move coordinates: %d;%d"%(feature.geometry().asPolyline()[0][0],feature.geometry().asPolyline()[0][1]) moveFeature(feature.id(), 1111,1111) layer.updateFeature(feature) print "after coordinates: %d;%d"%(feature.geometry().asPolyline()[0][0],feature.geometry().asPolyline()[0][1])prints:
EGUZOL71RUEYRbefore move coordinates: 675392;6408936after coordinates: 675392;6408936Does anyone has a hint about this?Thanks
أكثر...