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

Marco Hugentobler marco.hugentobler at sourcepole.ch
Tue Jul 28 01:38:05 PDT 2015


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?


Regards,
Marco


-- 
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Weberstrasse 5, CH-8004 Zürich, Switzerland
marco.hugentobler at sourcepole.ch http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee



More information about the Qgis-developer mailing list