I am new to postgis and I need to find intersection of three polygons. In my table named "mytable" contains large no of polygon coordinates and grouped into three categories by adding a field called "filename".I labelled the category names as part1, part2, part3 in filename . Now I need to find all polygon which spacially intersect in three categories. I write my code as:
SELECT ST_Intersection(a.geom, b.geom) as intersect_ab
FROM mytable a
INNER JOIN mytable b
ON ST_Intersects(a.geom,b.geom)
INNER JOIN mytable c
ON ST_Intersects(a.geom,c.geom)
WHERE ST_Overlaps(a.geom, b.geom)
AND ST_Overlaps(b.geom, c.geom)
AND ST_Overlaps(a.geom, c.geom)
AND ST_isvalid(a.geom)='t'
AND ST_isvalid(b.geom)='t'
AND ST_isvalid(c.geom)='t'
AND a.filename = 'part1'
AND b.filename = 'part2'
AND c.filename = 'part3');
But it returns wrong answer
POLYGON((0 0,0 1,1 1,1 0,0 0)) filename as part1..... POLYGON((0 0,0 3,3 3,3 0,0 0)) filename as part1...... POLYGON((0 0,0 2,2 2,2 0,0 0)) filename as part2......
POLYGON((0 0,0 5,5 5,5 0,0 0)) filename as part2...... POLYGON((0 0,0 3,3 3,3 0,0 0)) filename as part3...... POLYGON((0 0,0 4,4 4,4 0,0 0)) filename as part3.......
Now I need to find regions which are common in all categories.***** that is I expect the result as: POLYGON((0 0,0 1,1 1,1 0,0 0)).... POLYGON((0 0,0 2,2 2,2 0,0 0))..... POLYGON((0 0,0 3,3 3,3 0,0 0)) – A S Feb 20 '17 at 12:34
filenamecategory. Unfortunately theST_Intersectionfunction is not an aggregate function (cannot be used in aGROUP BY). If someone has an existing recipe for this, that'd be great. You will get some way there with this Q&A: http://gis.stackexchange.com/questions/83/separate-polygons-based-on-intersection-using-postgis but it does not eliminate portions of the input that only intersect with none or some (not all) features in the group. – alphabetasoup Feb 20 '17 at 20:30