Last active
August 23, 2016 08:12
-
-
Save ramiroaznar/bd782915162bb1a7859f1e0ee383f538 to your computer and use it in GitHub Desktop.
Getting the overlapping geometries from the same layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH temp AS ( | |
SELECT | |
a.cartodb_id as cdbid_1, | |
b.cartodb_id as cdbid_2, | |
a.the_geom AS g1, | |
b.the_geom AS g2 | |
FROM | |
aois_minutes_esp a, aois_minutes_esp b | |
WHERE | |
a.cartodb_id > b.cartodb_id | |
AND | |
a.data_range = 60 | |
AND | |
b.data_range = 60 | |
AND | |
ST_Intersects(a.the_geom,b.the_geom) | |
) | |
SELECT | |
row_number() over () as cartodb_id, | |
ST_Intersection(g1, g2) AS the_geom, | |
ST_Area(ST_Intersection(g1, g2)) AS overlap_area, | |
cdbid_1, | |
cdbid_2 | |
FROM | |
temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment