I'd like to create a new, custom PostGIS function that would return a point geometry from a polygon that I can use for generating label points from a polygon, but I am not sure how to go about composing the function itself.
My goal is really simple...
- generate initial label points for all polygons using ST_Centroid,
- Test the label point to ensure that it falls on the surface of the polygon,
- For centroids not on the surface of the polygon, fall back to ST_PointOnSurface.
This would mean most label points are at the Centroid, but ensure that irregular and "C" shaped polygons would have the label point at least somewhere on the surface. I feel like the psuedo-code would look something like this:
SELECT gid, CASE WHEN ST_Intersects(ST_Centroid(x.geom), x.geom) THEN ST_Centroid(x.geom) ELSE ST_PointOnSurface(x.geom) END AS geom FROM x