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

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

  •  16-04-2021
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top