1

I need to get gid, area and geometry of table1 which are intersecting with 200 buffer of table2. I tried to structure the query. Please refer below:

create table SMI_1 as 
SELECT ST_Buffer(geom, 200) from table2;

create table SAH_2 as 
SELECT a.gid,a.shape_area, a.geom 
FROM table1 a 
INNER JOIN SMI_1 b ON ST_Intersects(a.geom, b.st_buffer);

With this I am not getting desired output. It is not clipping the features of table1 with the shape of the table2.

2
  • 3
    Your query doesn't ask for the clipped pieces, just the overlapping ones. Break out some documentation and review the difference between ST_Intersects and ST_Intersection.
    – Vince
    Commented Mar 18, 2017 at 20:30
  • 1
    Thank you for the suggestion. I used ST_Intersection to get the result
    – nandini
    Commented Mar 27, 2017 at 21:38

1 Answer 1

1

This query will return geometries from SAH_2 which are intersecting with geometries from SMI_1. If you need a geometry of this intersection you need to use ST_Intersection function:

create table SAH_2 as (
  WITH SMI_1 as ( 
    SELECT ST_Buffer(geom, 200) from table2)
  SELECT a.gid,a.shape_area, ST_Intersection(a.geom, b.st_buffer) as geom
  FROM table1 a 
  INNER JOIN SMI_1 b ON ST_Intersects(a.geom, b.st_buffer));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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