Geo Fence: Find number of features (points/lines/polygons) inside a polygon using oracle spatial

StackOverflow https://stackoverflow.com/questions/4611944

  •  26-09-2019
  •  | 
  •  

문제

How do i write a SQL query (using Oracle Spatial) to find the number of features available inside a polygon (geofence);

The features could be either points, lines or a polygon itself.

Thanks.

도움이 되었습니까?

해결책

Try that statement:

select count(*) from geometry_table t where SDO_RELATE(t.geom_column, geofence, 'mask=INSIDE') = 'TRUE'
/

It is mandetory that the first parameter of SDO_RELATE is the geometry column with a spatial index.

다른 팁

Update: Disregard this suggestion completely, Albert Godfrind said it is repeating what is already being done internally. So it is inefficient and slow:

To add to Tims answer, it is good practice to combine SDO_FILTER and SDO_RELATE for performance reasons. SDO_FILTER is fast but returns too many geometries, it will give you all geometries whose minimum bounding rectangle (MBR) intersects with your fence's geometry. SDO_RELATE is exact but slow. So combine both:

select count(*) 
from geometry_table t 
where SDO_FILTER(t.geom_column, geofence) = 'TRUE' and SDO_RELATE(t.geom_column, geofence, 'mask=INSIDE') = 'TRUE' 

Regards, Chris

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top