domenica 18 maggio 2014

Find overlapped polygons

The goal is "how many polygons are overlapping other polygons in a dataset ?".

The solution is a simply spatial query:
The dataset is "dbcg_dgpv". 
"pk_uid" is the primary key.
"geometry" is the geometric field (polygon).

----
select
    a.pk_uid,
    b.pk_uid
from
    dbcg_dgpv as a inner join dbcg_dgpv as b on (a.pk_uid <> b.pk_uid)
where
    ST_contains(b.geometry,a.geometry) = 1
    AND
          a.ROWID IN (
        SELECT ROWID FROM SpatialIndex
        WHERE f_table_name = 'DB=main.dbcg_dgpv'
        AND search_frame =b.geometry
    );
----


The filter
..on (a.pk_uid <> b.pk_uid)
 is to avoid to compare a polygon with itself

Nessun commento:

Posta un commento