2

I try to compute the centroid of polygons with holes on qgis. I did not manage to do it directly, I had to make a conversion to convex hulls before extraction.

I crashed my pgsql server trying to extract theses using ST_Centroid()

Is there a better way to do it?

  • Are you looking for a PostGIS solution or can it be done using QGIS? – Joseph Apr 11 '16 at 11:51
  • For PostGIS solution see here: gis.stackexchange.com/questions/724/…. For general math see: math.stackexchange.com/a/623849 – zehpunktbarron Apr 11 '16 at 12:01
  • There may be invalid geometries in your data. PostGIS should handle polygons with holes just fine SELECT ST_AsText( ST_Centroid( ST_GeomFromText( 'POLYGON (( 523 228, 523 238, 535 238, 535 228, 523 228 ), ( 527 231, 531 231, 531 235, 527 235, 527 231 ))') )) – user30184 Apr 11 '16 at 13:06
  • In Qgis (that you tagged as well) the Extension "Real Centroids" does what you want i think. It moves the centroid when it lies outside the polygon itself, what would be the case when it is in a hole. The calculations going on in the background are probably the same as in postgis, as this is mentioned in the extension. – Matte Apr 11 '16 at 14:29
  • What version of PostGIS? Can you post an example of the geometry that crashed the server? – Mike T Apr 11 '16 at 21:50

Your Answer

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

Browse other questions tagged or ask your own question.