For a python test script I would like to loop through a MultiPolygon,
calculation the areas of the single Polygons, exteriorRing and where they
exist the interiorRing and compare the results from another source
(spatialite).

Sample code:
  test_polygon = test_geom.geometryN(index)
  self.assertEqual(test_polygon.wkbType(), QgsWKBTypes.Polygon)
  count_rings=test_polygon.numInteriorRings()
  if (count_rings > 0):
   polygon_ring_area_sum+=polygon_area
   exterior_ring = test_polygon.exteriorRing()
   print('-I-> Polygon[%d] : exteriorRing[%s] isClosed[%d] isRing[%d] '%
(index,
exterior_ring.geometryType(),exterior_ring.isClosed(),exterior_ring.isRing()))
   i_rc=exterior_ring.convertTo(QgsWKBTypes.Polygon)
   exterior_ring_area=round(exterior_ring.area(),6)

-I-> Polygon[11] : exteriorRing[LineString] isClosed[1] isRing[1]
-I-> Polygon[11] : exteriorRing[LineString] exterior_ring_area[0.000000]
rc=0

To calculate the area, the geometry must be a Polygon but I have not found
a way to do this properly.

The convertTo() method seems to only change to a Z or M type
- the documentation is a bit vague 'Converts the geometry to a specified
type.'

the next attempt:
line = QgsGeometry.fromWkt(exterior_ring.asWkt())
exterior_ring_polygon = line.convertToType(QGis.Polygon, False)

also did not bring the desired result (fails when creating 'line').

Since the returned LineString is closed and a ring, there should be no
problem.

--
A second question:

How can the srid of a geometry retrieved from a QgsVectorLayer be
determined?

Mark Johnson
_______________________________________________
Qgis-developer mailing list
[email protected]
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to