I am trying to find a single external boundary either polygon or line from the multipolygon using
st_boundary in PostGIS query. The function doesn't work. What could be the issue?
I do not understand your question a little and therefore I will offer you two possible answers, use the one that answers your question
Option 1 - to find all boundaries, run the query:
SELECT ST_ExteriorRing((ST_Dump(geom)).geom) as geom FROM geo_gem_05;
Option 2 - to find only a common external boundary, run the query:
SELECT ST_ExteriorRing((ST_Dump(ST_Union(geom))).geom) as geom FROM geo_gem_05;
for experiment you can replace "ST_ExteriorRing" for "ST_Boundary"
Good luck ...
What do you mean by "The function doesn't work"? It does work for me.
SELECT ST_AsText(ST_Boundary(ST_GeomFromText('MULTIPOLYGON ((( 340 520, 400 460, 200 420, 340 520 )), (( 420 420, 520 300, 340 320, 420 420 )))'))); Result: MULTILINESTRING((340 520,400 460,200 420,340 520),(420 420,520 300,340 320,420 420))
The result is a multilinestring with two closed linestrings, one for each member in the multipolygon. That is the correct result by the definition of a boundary https://postgis.net/docs/ST_Boundary.html. Please explain if you are after something else.