Geo Fence: Find number of features (points/lines/polygons) inside a polygon using oracle spatial
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 polygo开发者_StackOverflow社区n 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
精彩评论