The following Python code is very helpful to reverse the direction of lines in QGIS:
layer = qgis.utils.iface.mapCanvas().currentLayer() for feature in layer.selectedFeatures(): geom = feature.geometry() nodes = geom.asPolyline() nodes.reverse() newgeom = QgsGeometry.fromPolyline(nodes) layer.changeGeometry(feature.id(),newgeom)
Unfortunately, the code doesn't work for polygons. Replacing
fromPolygon(nodes) hasn't helped. Is there a Python code that works for polygons?
if layer.geometryType() == 2: # ?
For PostGIS and most likely some other data providers it's possible to digitize polygons clockwise and counter-clockwise. Creating a marker line symbology (e.g. triangle) for such layer may result in inward and outward rotated markers. So I want to reverse the direction of the anti-clockwise digitized polygons through the Python console.