Skip to content

How to polygonize MultiLineString? #313

Answered by RaczeQ
nshiab asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it is possible to break down multi-lines ;)
Just be careful with linestrings that aren't closed.

WITH raw_data AS (
    SELECT *
    FROM ST_Read('https://earthquake.usgs.gov/product/shakemap/official20110311054624120_30/atlas/1594161746661/download/cont_mmi.json')
),
unnested_linestrings AS (
    SELECT value, UNNEST(ST_Dump(geom), recursive := true)
    FROM raw_data
)
SELECT value, ST_MakePolygon(geom) geometry
FROM unnested_linestrings
WHERE ST_Equals(ST_StartPoint(geom), ST_EndPoint(geom))

┌────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ value  │                                                  geometry  …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nshiab
Comment options

Answer selected by nshiab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants