[GIS] Intersecting polygons in Oracle

intersectionoracle-spatial

Have a polygon in table 2 with its id, no and geometry. In table 1 I have polygons with the same fields. The polygon in table in intersects with a few polygons from table 1.What I am trying to do is clip of the polygons which overlap polygon from table 2 and insert the same fields and geometry in table 3

insert into table 3  
select a.store_id,b.store_id,a.store_number,a.client_id,sdo_geom.sdo_intersection(b.geometry,a.geo metry,0.005)  
from table_1 a, table_2 b  
where b.store_id=34746  
and sdo_anyinteract(b.geometry,a.geometry)='True';  

When I do run this I dont get any output. Where would I be going wrong

Best Answer

This query will fail with ann error like this:

ORA-29902: error in executing ODCIIndexStart() routine
ORA-13207: incorrect use of the [SDO_ANYINTERACT] operator

You need to write "= 'TRUE' " instead of " = 'True' " (notice the capitals).

Apart from that, the query is also incorrectly written: since you lookup table A using a window from table B, then you need to specify the columns in that order in the spatial predicate, so write sdo_anyinteract(a.geometry,b.geometry) instead of sdo_anyinteract(b.geometry,a.geometry)

So the proper way to write your query is this:

insert into table 3  
select a.store_id, b.store_id, a.store_number, a.client_id, 
  sdo_geom.sdo_intersection(b.geometry,a.geometry,0.005)  
from table_1 a, table_2 b  
where b.store_id=34746  
and sdo_anyinteract(a.geometry,b.geometry)='TRUE'; 

That may still return no rows. It all depends on the actual data you are using.