0

I have MULTIPOLYGON in my PostGIS database to store countries (with islands etc.). But I need to add holes to my borders for lakes. How can I store multipolygon with holes?

I am using ST_SetSRID(ST_Multi(ST_GeomFromText('POLYGON(...)')), 4326) to create multipolygon

5

You can use ST_Difference to create the holes. It will subtract the lakes from your countries.

Let's say your lakes are in another table called lakes and you've already stored your countries. You would do something like

UPDATE countries SET geom = ST_Difference(geom, 
       (SELECT ST_Union(l.geom) FROM lakes As l 
         WHERE ST_Intersects(l.geom, countries.geom) );
| improve this answer | |
0

Solution from LR1234567 works OK, but I didnt want to create second table. At the end, I have create multipolygon with holes directly during geometry construction, using WKT.

MULTIPOLYGON (
(
   (40 40, 20 45, 45 30, 40 40)
),
(
   (20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20) 
)
)

See Wiki

| improve this answer | |
  • 1
    if you insist on creating your polygons using WKT how else could you do this? – Ian Turton Aug 9 '15 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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