2

I have an SDE.ST_GEOMETRY polygon FC in an Oracle 18c/10.7.1 geodatabase.

I can calculate the X and Y of the polygon centroids using the SDE.ST_GEOMETRY ST_Centroid function:

sde.st_x(sde.st_centroid(shape)) as x,
sde.st_y(sde.st_centroid(shape)) as y    

ST_Centroid takes a polygon, multipolygon, or multilinestring and returns the point that is in the center of the geometry's envelope. That means that the centroid point is halfway between the geometry's minimum and maximum x and y extents.


Unfortunately, the polygons are irregularly shaped, and therefore the centroids do not fall within the polygon boundaries:

enter image description here


Is there a way to calculate polygon center-points that fall within the polygons?

  • side note: is that definition of the centroid from the function documentation? Because "That means that the centroid point is halfway between the geometry's minimum and maximum x and y extents." is not the accepted definition of a centroid... Wow, yes it is in the docs... Hmmm. – Spacedman Apr 1 at 17:41
  • 1
  • I can think of a complicated way to get what you want...rasterize the polygon, skeletonize it, find the longest path from all the skeleton endpoints to all other skeleton endpoints, then take the middle pixel in that path as the "centroid." This would effectively be a kind of "within bounds" average position. – Jon Apr 1 at 18:11
  • 1
    You want the SDE.ST_PointOnSurface function, not SDE.ST_Centroid (remember, there was a design committee for the Simple Features standard). – Vince Apr 1 at 18:15
  • The SF standard seems to have a note No specific algorithm is specified for the Centroid function; answers may vary with implementation.. I have thought that it should be at the centre of mass as it is in PostGIS postgis.net/docs/ST_Centroid.html. – user30184 Apr 2 at 8:27
0

As @Vince suggested, this can be done with the SDE.ST_PointOnSurface function:

sde.st_x(sde.st_pointonsurface(.shape)) as x,
sde.st_y(sde.st_pointonsurface(.shape)) as y     

ST_PointOnSurface takes an ST_Polygon or ST_MultiPolygon and returns an ST_Point guaranteed to lie on its surface.

| improve this answer | |

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.