9

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?

8
  • 1
    Describe what that plugin would do.
    – user30184
    Feb 12 '17 at 10:21
  • It should correct the direction of vertices: gis.stackexchange.com/a/227178/77061 Feb 12 '17 at 11:01
  • 2
    I 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. Feb 12 '17 at 11:48
7

You can use QGIS expressions with force_rhr() function: simply use force_rhr( $geometry) with the "Geometry by expression".

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.