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?
Asked
Active
Viewed 1,757 times
11
-
1Describe what that plugin would do. – user30184 Feb 12 '17 at 10:21
-
It should correct the direction of vertices: http://gis.stackexchange.com/a/227178/77061 – eclipsed_by_the_moon Feb 12 '17 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. – user30184 Feb 12 '17 at 11:33
-
There are two interpretations about the round hand rule in GIS. Would you like to have outer rings clockwise or counterclockwise? – user30184 Feb 12 '17 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_moon Feb 12 '17 at 11:48
-
Ok, that's the shapefile way. Right arm is inside the polygon when walking the path. The other rule is looking at the fingers of the right hand, they wind anticlockwise. What practical problem do you have due to not uniform windings? – user30184 Feb 12 '17 at 12:21
-
Marker lines are not placed properly: http://gis.stackexchange.com/q/227103/77061 – eclipsed_by_the_moon Feb 12 '17 at 21:38
-
what happens if you try v.clean in GRASS (using Processing)? I found it enforced shapefile windings, but your mileage may vary depending on the type of layer. – Steven Kay Feb 13 '17 at 22:23
2 Answers
9
Use QGIS expressions with force_rhr() function: simply use force_rhr( $geometry) using Menu Processing > Toolbox > Geometry by expression.
Babel
- 71,072
- 14
- 78
- 208
6
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
MrXsquared
- 34,292
- 21
- 67
- 117