[postgis-users] clip polygons

959 views
Skip to first unread message

Marta Debolini

unread,
Jan 14, 2013, 12:01:02 PM1/14/13
to postgi...@lists.osgeo.org
Hi,
I am a new postgis user, so sorry if my request seems trivial for someone.

I have to clip a polygon with another polygon file. I was used to do this operation with the simple comand "clip" in GRASS or QGIS.
How can I do the same operation in postgis? I tried with sy_intersect, but it takes also the polygons outside my area, which simply intersect the border.
The request I wrote is:


CREATE TABLE w_md.x
AS (SELECT area, a.the_geom
    FROM oc a, co b
    WHERE st_intersects(a.the_geom, b.the_geom));
   
    ALTER TABLE w_md.x_1999 ADD column ggid1 serial;
     ALTER TABLE w_mdi.x_1999 ADD PRIMARY KEY (ggID1);

Thank you for your help,

Marta

Nicolas Ribot

unread,
Jan 14, 2013, 12:13:51 PM1/14/13
to PostGIS Users Discussion
Hi,

You also have to perform the actual intersection if you want to clip your data, not only the intersect test:

SELECT area, st_intersection(a.the_geom, b.geom) as geom

    FROM oc a, co b
    WHERE st_intersects(a.the_geom, b.the_geom)

Nicolas


_______________________________________________
postgis-users mailing list
postgi...@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users


Francisco Salas

unread,
Jan 14, 2013, 12:22:57 PM1/14/13
to PostGIS Users Discussion

Martha ,

I think that you must use in the select sentence st_intersects(a.the_geom, b.the_geom) as the_geom , instead of a.the_geom

 

Francisco Salas

Tim-Hinnerk Heuer

unread,
Jan 14, 2013, 8:14:32 PM1/14/13
to PostGIS Users Discussion

I think Nicolas is more correct. St_Intersection sounds like a function that gets a geometry while St_Intersects returns a Boolean.

Martin Davis

unread,
Jan 14, 2013, 11:41:34 PM1/14/13
to postgi...@lists.osgeo.org

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.2805 / Virus Database: 2637/6000 - Release Date: 12/31/12
Internal Virus Database is out of date.


Francois Hugues

unread,
Jan 15, 2013, 2:16:54 AM1/15/13
to PostGIS Users Discussion
Hello,

To complete these answers about the usage st_intersection in combination with st_intersects, if you want to avoid to clip features "which simply intersect the border" you should try to add st_touches(a.geom, b.geom) = 'f' in the where clause.

Hugues



--



Hugues FRANÇOIS

IR - UR DTM



Cemagref - IRSTEA Grenoble

2, rue de la papeterie

Domaine universitaire

38402 Saint-Martin-d'Hères CEDEX



04.76.76.27.44

06.77.66.21.31



hugues....@irstea.fr



________________________________

Marta Debolini

unread,
Jan 15, 2013, 4:25:32 AM1/15/13
to PostGIS Users Discussion
Thank you all!
I followed your instructions and fixed the problem.

Marta
Reply all
Reply to author
Forward
0 new messages