0

I want to approximate a closed polygon but PostGIS gives me not a clean linestring but multilinestring with 3 linestrings instead. All because of that tiny tail left from straight skeleton. the polygon the tail Is there any proper or good way to handle this?

Ivan Bukashkin
  • 674
  • 3
  • 11
  • Is this tail a line or two (from polyline into nowhere and back)? –  Dec 21 '18 at 13:42
  • also, would you give us a sample of such multylinestring in the form of wkt , prefferably –  Dec 21 '18 at 13:56
  • i need excactly one linestring and getting multilinestring with 3 linestrings. The main string that I am looking for is divided by this small tail linestring into 2 linestrings. Also, i have many shapes of polygons where i want to get exactly one linestring so I looking for some silver bullet algorithm. Now Im filtering out 1 smallest linestring with exactly 2 point then try to merge lines and repeat in case of failed merge. – Ivan Bukashkin Dec 25 '18 at 07:37

1 Answers1

0

You may postprocess st_approximatemedialaxis() output to filter out those tails by some criteria (number of points, for instance):

select st_astext(geom)
from (select (st_dump(x.geom)).geom
    from (values (st_geomfromtext('MULTILINESTRING( (27 80, 18 68, 29 48, 55 58, 53 76, 27 80), (55 58, 58 57))')),
    (st_geomfromtext('MULTILINESTRING( (46 34, 32 21, 44 7, 67 9, 67 29, 46 34), (46 34, 46 36))')),
    (st_geomfromtext('MULTILINESTRING( (69 66, 61 48, 75 40, 94 54, 88 68, 69 66), (61 48, 58 47))'))) as x(geom)) y
where st_npoints(geom)>2

returns

LINESTRING(27 80,18 68,29 48,55 58,53 76,27 80)
LINESTRING(46 34,32 21,44 7,67 9,67 29,46 34)
LINESTRING(69 66,61 48,75 40,94 54,88 68,69 66)
  • Thats what im doing now. I just wonder if there is some caveeats with ST_ApproximateMedialAxis and some right way to do the approximation – Ivan Bukashkin Dec 25 '18 at 07:40