# Calculate irregular polygon center-point that falls within the polygon boundary

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: 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. Apr 1 '20 at 17:41
• 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 '20 at 18:11
• You want the `SDE.ST_PointOnSurface` function, not `SDE.ST_Centroid` (remember, there was a design committee for the Simple Features standard). Apr 1 '20 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. Apr 2 '20 at 8:27

``````sde.st_x(sde.st_pointonsurface(.shape)) as x,