Curious if the following code has a blatant error that has been overlooked with respect to rotating a single polygon feature.
The *.geometry().rotate(...) returns a '0'
, indicating it was successful - yet the display and data-source do not depict any rotation; even after reload / refresh of layer, legend, and canvas.
Either the problem is in syntax, or maybe (because this is a Dev release) a not yet fully operational function?
inputShapeRef.startEditing()
featureSearch = QgsFeatureRequest().setFilterFid(int(inputShapeID))
featureRef = inputShapeRef.getFeatures(featureSearch)
for feature in featureRef:
feature.geometry().rotate(self.MaxRotation,self.baseCentroid)
inputShapeRef.commitChanges()
UPDATE: Single line of code was missing, and the following is the updated script. Sucessfully rotates the shape to the desired angle; quite rapidly!
inputShapeRef.startEditing()
featureSearch = QgsFeatureRequest().setFilterFid(int(inputShapeID))
featureRef = inputShapeRef.getFeatures(featureSearch)
for feature in featureRef:
feature.geometry().rotate(self.MaxRotation,self.baseCentroid)
inputShapeRef.changeGeometry(feature.id(),feature.geometry()) # <=== + = success
inputShapeRef.commitChanges()
FINAL THOUGHTS / QUESTIONS:
Does anyone know if this functionality carries over to an entire layer, the layers extent, or selection of multiple features? The SAGA translate processing function fulfills this need - but is data-thirsty. The low data-overhead and rapid return of this new single feature rotation would be highly beneficial for an entire layer or selection of multiple features therein.
For example, say a point array needs to be rotated in sync with an associated bounding polygon - rather then rotate each point individually, is there a means of rotating the entire array simultaneously without creating a new dataset?