So, I am publishing my new experimental improved function ST_CentraLAxisLongestLineFromVoronoiDiagrams, to try to make you a little happier :-), and for JAVA programmers to try to implement this approach based on the Voronoi Diagrams function.
Create a function:
CREATE OR REPLACE FUNCTION ST_CentraLAxisLongestLineFromVoronoiDiagrams(
geom GEOMETRY,
n integer)
RETURNS GEOMETRY AS
$BODY$
WITH
tbla AS (SELECT (ST_Dump(geom)).geom),
tblb AS (SELECT ST_ExteriorRing(geom) geom1, ST_Buffer(ST_ExteriorRing(geom), 0.000001) geom2 FROM tbla),
tblc AS (SELECT line1, line2, line3 FROM (SELECT ST_MakeLine((ST_PointN(ST_Boundary(ST_OrientedEnvelope(geom1)),1)),
(ST_PointN(ST_Boundary(ST_OrientedEnvelope(geom1)),2))) AS line1, ST_MakeLine((ST_PointN(ST_Boundary(ST_OrientedEnvelope(geom1)),3)),
(ST_PointN(ST_Boundary(ST_OrientedEnvelope(geom1)),4))) AS line2, ST_MakeLine((ST_PointN(ST_Boundary(ST_OrientedEnvelope(geom1)),1)),
(ST_PointN(ST_Boundary(ST_OrientedEnvelope(geom1)),4))) AS line3 FROM tblb) AS moo),
tbld AS (SELECT (ST_Dump(ST_Difference(a.geom2, ST_Union(b.geom)))).geom AS geom FROM tblb a CROSS JOIN LATERAL
(SELECT ST_Buffer(line1, 0.00001) geom FROM tblc UNION SELECT ST_Buffer(line2, 0.00001) geom FROM tblc) b GROUP BY a.geom2),
tble AS (SELECT (a.geom) geom FROM tbld a JOIN tblc b ON ST_Intersects(a.geom, b.line3)),
tblf AS (SELECT generate_series (0, n) as steps),
tblg AS (SELECT steps AS stp, ST_LineInterpolatePoint(geom1, steps/(SELECT count(steps)::float-1 FROM tblf)) geom FROM tblb, tblf GROUP BY tblf.steps, geom),
tblh AS (SELECT ((ST_Dump(ST_VoronoiPolygons(ST_Collect(geom)))).geom) geom FROM tblg),
tbli AS (SELECT ST_ExteriorRing(ST_Union(a.geom)) geom FROM tblh a JOIN tble b ON ST_Intersects(a.geom, b.geom))
SELECT ST_Intersection(a.geom, b.geom) geom FROM tbli a JOIN tbla b ON ST_Intersects(a.geom, b.geom);
$BODY$
LANGUAGE SQL;
Run the function on polygons and check the result.
SELECT ST_CentraLAxisLongestLineFromVoronoiDiagrams(geom, 789) geom FROM <polygon_table>
To improve the result, you can apply ST_Simplify(), as increasing the number of points also improves the result, but negatively affects the performance...
For example:
SELECT ST_Simplify(geom, 0.01) geom FROM (SELECT ST_CentraLAxisLongestLineFromVoronoiDiagrams(geom, 789) geom FROM <polygon_table>) foo
You may need to adjust the operation of the geo-tool, with ST_Buffer().
I've been playing around with the data in WGS84.
The main thing is all...
Original spatial solutions :-)