It seems that there isn't a plugin to perform the right-hand-rule on a layer or selected features. Can this be done by using some Python code? Is there a function that works in the same way as ST_ForceRHR?
-
1Describe what that plugin would do.– user30184Feb 12, 2017 at 10:21
-
It should correct the direction of vertices: gis.stackexchange.com/a/227178/77061– eclipsed_by_the_moonFeb 12, 2017 at 11:01
-
2I would guess that saving the layer would correct the direction. Winding rules in shapefiles and for example in GeoJSON are just opposite, though. What QGIS does internally may be yet another story.– user30184Feb 12, 2017 at 11:33
-
There are two interpretations about the round hand rule in GIS. Would you like to have outer rings clockwise or counterclockwise?– user30184Feb 12, 2017 at 11:36
-
Outer ring vertices should go clockwise and inner ring vertices should go counterclockwise. Scratch layers are not corrected automatically when saving edits.– eclipsed_by_the_moonFeb 12, 2017 at 11:48
2 Answers
Use QGIS expressions with force_rhr()
function: simply use force_rhr( $geometry)
using Menu Processing > Toolbox > Geometry by expression.
Since QGIS 3.4.3 there is QgsGeometry().forceRHR()
as Python equivalent. You can use it as follows:
polygons = QgsProject.instance().mapLayersByName('polygon')[0]
with edit(polygons):
for feature in polygons.getFeatures():
rhrgeom = feature.geometry().forceRHR() # forceRHR() returns a geometry
feature.setGeometry(rhrgeom) # To actually change the geometry, use setGeometry
polygons.updateFeature(feature) # Dont forget to "save" these changes