Search code examples
postgresqlgispostgisqgis

Trying to figure out how to clip a vector with another vector (a rectangle box) using postgis


Technologies: PostGIS, QGIS

I have a vector box named "study_area", and another vector data "floodplain". Now I need to clip the floodplain vector data to produce a floodplain layer that is within in the study area. I am required to use postgis, writing queries for this specific job.

However, I checked the doc, it seems like the st_clip function only works for rasters.

Here is my attempt:

select r.geom as clipped
from study_area as s, usrname."Regulatory_Floodplain" as r
where st_within(r.geom, s.geom) or st_intersects(s.geom, r.geom)

The problem is that it is not entirely in the box:

enter image description here

Any alternatives? Any help will be appreciated, thanks!


Solution

  • You probably want ST_Intersection function, something like

    select st_intersection(r.geom, s.geom) as clipped
    from study_area as s, usrname."Regulatory_Floodplain" as r
    where st_intersects(s.geom, r.geom)