[Qgis-developer] Definition of Perimeter for polygons with holes

Hugo Mercier hugo.mercier at oslandia.com
Thu Jul 30 00:16:08 PDT 2015


Hi Marco,

On 28/07/2015 10:38, Marco Hugentobler wrote:
> Hi
> 
> While working on QgsDistanceArea, I noticed the definition of perimeter
> in QGIS is not the same as in PostGIS. PostGIS returns the length of
> outer and inner rings, while QGIS expects the length of the outer ring
> only:
> 
> test_distancearea.py:
> 
> polygon = QgsGeometry.fromPolygon(
>             [
>                 [ QgsPoint(0,0), QgsPoint(3,0), QgsPoint(3,3),
> QgsPoint(0,3), QgsPoint(0,0) ],
>                 [ QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2),
> QgsPoint(1,2), QgsPoint(1,1) ],
>             ]
>         )
> 
> perimeter = da.measurePerimeter(polygon)
> assert perimeter == 12, "Expected:\n%f\nGot:\n%f\n" % (12, perimeter)
> 
> 
> Using the following in PostGis returns 16 (length of inner and outer
> rings):
> 
> SELECT ST_Perimeter( ST_GeomFromText( 'POLYGON(( 0 0, 3 0, 3 3, 0 3, 0
> 0),(1 1, 2 1, 2 2, 1 2, 1 1))', -1 ) );
> 
> What is your opinion? Is it okay to change it in QGIS to also consider
> the length of inner rings or are there any strong arguments against that?

Good question ! :)
I don't know if there is one ideal definition of the perimeter of inner
rings. After all, we may decide to see the inner perimeter as a negative
one ... as it is for the area.
So, just a proposition: let the user decide what to do with the two
perimeters (outer and inner), adding an option to retrieve separately
the inner perimeter ?



More information about the Qgis-developer mailing list