3

Probably a bit hard to explain but hopefully the image can explain better

There are 2 datasets, one is a point, the other is a line. Intended outcome is having polygons based on them

The lines form a shape around each point which I need to build a polygon out of, which I've highlighted as the shaded areas in yellow. But there can be multiple lines that can form each polygon, which I gave 2 examples in orange:

enter image description here

1 Answer 1

3

Polygonize all lines then inner join your points to them, and select distinct polygons:

with polygonized as (
select l.id, st_makepolygon((st_dump(l.geom)).geom) as geom
from test.lines as l
)
select distinct on (polygonized.id) polygonized.* from polygonized
join test.points_in_lines as p
on st_intersects(polygonized.geom, p.geom)

enter image description here

3
  • I needed to use ST_NumPoints(part_geom) >= 4 and ST_IsClosed(part_geom) otherwise it wouldn't work. But somehow it didnt work in many cases like in the below i.sstatic.net/QsN9WFIn.png
    – Luffydude
    Commented Jul 23 at 11:49
  • The polygon in your screenshot is self intersecting = invalid
    – Bera
    Commented Jul 23 at 15:01
  • Is there anyway to maybe make it at least a little bit tolerant of bad geometries? maybe like a buffer?
    – Luffydude
    Commented Jul 23 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.