I have a table of lines, a single attribute in multilinestring In postgres, if I try to create a buffer on this multilinestring, I get this error message:
sqlalchemy.exc.InternalError: (psycopg2.errors.InternalError_) GEOSBuffer: TopologyException: depth mismatch at at 362700 5390300
but in qgis, the processing is done well. To stay in the postgres environment, I did this: I cut the multilinestring into a single linestring I create a buffer on each linestring I merge all the buffer polygons I get a MULTIPOLYGON I would like to create a polygon outline from the MULTIPOLYGON to have a simple polygon. I don't want MULTIPOLYGON, or geometrycollection. Here is the sql query I made.
WITH segments AS (
SELECT id, ST_AsText(ST_MakeLine(lag((pt).geom, 1, NULL) OVER (PARTITION BY id ORDER BY id, (pt).path), (pt).geom)) AS geom
FROM (SELECT id, ST_DumpPoints(wkb_geometry) AS pt FROM query_clusterdbscan_line) as dumps
),
segments_filter AS (
SELECT geom as wkb_geometry FROM segments
WHERE geom IS NOT null
and ST_GeometryType(geom) in ('ST_LineString', 'MultiLineString')
and st_length(geom :: geography) :: numeric <= 20:: numeric
),
segments_filter_buffer AS (
SELECT st_length(wkb_geometry :: geography) :: numeric ,
st_buffer(
ST_MakeValid(wkb_geometry) :: geography,
20 :: double precision,
'quad_segs=8' :: text
) :: geometry as wkb_geometry
FROM segments_filter
order by st_length(wkb_geometry :: geography) desc
),
segments_filter_buffer_to_Polygon AS (
select st_union(wkb_geometry) as wkb_geometry
from segments_filter_buffer
)
select ST_Polygonize(ST_Boundary(wkb_geometry)) AS buffer_sides
from segments_filter_buffer_to_Polygon