PostGIS - convert multipolygon to single polygon

前端 未结 3 1335
孤街浪徒
孤街浪徒 2021-02-04 01:44

Is it possible to import a shape file containing multipolygons into single polygon in PostGIS? Whenever I try importing a shape file of a polygon, it is stored as a multipolygon

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 01:58

    Import into a staging table and then use ST_DUMP to brake the multigeom into individual pieces and use that to populate the destination table.

    UPDATE

    You import all the data you need into a staging table (let's call it multi) and then use ST_DUMP to break the mutligeometry into single geometries:

    WITH multi AS(
    SELECT 1 as id, 2 as test, ST_GeomFromText('MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0)),((1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))') as poli
    )
    ,dump AS(
    SELECT  id
        ,test
        ,ST_DUMP(poli) as d
    FROM    multi)
    SELECT  id
        ,test
        ,(dump.d).path
        ,ST_AsTEXT((dump.d).geom)
    FROM dump 
    

提交回复
热议问题