Question

I have measured a land area (plot) and captured its 4 corner's GPS co-ordinates using a GPS device. Now I have two Questions

  1. How to save this is Oracle Database. (it seems answer of first point. is it?)
  2. After saving it I wanna check whether any plot is overlapping (partially or full) to another existing plot in database or not?
Was it helpful?

Solution

I got very helpful comments by Rene and Ben. and based on i have solved my issues..

    ---------------------------  CREATING TABLE --------------------------

create table tbl_location(
id int constraint id_pk primary key,
unit_code char(2) not null,
plot_id number(15) not null,
season_cntrl number(2),
Ryot_code varchar2(9),
share_or_perc_val number(2) not null,
plot_no varchar2(18) not null,
total_area decimal(5,5),
a1 varchar2(15),
b1 varchar2(15),
a2 varchar2(15),
b2 varchar2(15),
a3 varchar2(15),
b3 varchar2(15),
a4 varchar2(15),
b4 varchar2(15),
location sdo_geometry
);

--------------------------- CREATING SEQUENCE FOR ID ---------------------------
create sequence location_sequence
start with 1
increment by 1
nocache
nocycle;
/


--- createing a trigger for auto-incrementation of ID ------------------------------
Create or replace trigger id_increment
before insert on tbl_location
for each row
begin
select location_sequence.nextval into :new.id from dual;
end; 

for column location data

update tbl_location set location =  SDO_GEOMETRY(2003,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY( '80.16181','27.8682866666666','80.1616516666666','27.8681266666666','80.161215','27.867975','80.1613933333333','27.8685933333333','80.16181','27.8682866666666' )) where id =2;
update tbl_location set location =  SDO_GEOMETRY(2003,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY( '80.1538483333333','27.88376','80.15354','27.8841166666666','80.1529499999999','27.8834933333333','80.1532','27.8832566666666','80.1538483333333','27.88376' )) where id =3;

To get plots (polygon) which are intersecting each other

select a.id as id1, b.id as id2,a.unit_code, a.ryot_code,a.share_or_perc_val, 
sdo_geom.sdo_intersection(a.location, b.location, 0.005) location,
a.plot_no, a.total_area  
from tbl_location a
Inner Join tbl_location b on
a.id < b.id and sdo_geom.sdo_intersection(a.location, b.location,0.005) is not null  ;

OTHER TIPS

Well, you can just call the SDO_GEOM.SDO_AREA() on the result of the SDO_GEOM.SDO_INTERSECTION() function.

However that will not give you meaningful results: your geometries are (so it seems) in geodetic WGS84 coordinates (i.e. in decimal degrees), but you load them without specifying any coordinate system. As a result, any area calculation will return a result in square degrees, a meaningless and unusable result.

You should load your two geometries like this:

update tbl_location set location =  SDO_GEOMETRY(2003,4326,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY( 80.16181,27.8682866666666,80.1616516666666,27.8681266666666,80.161215,27.867975,80.1613933333333,27.8685933333333,80.16181,27.8682866666666 )) where id =2;
update tbl_location set location =  SDO_GEOMETRY(2003,4326,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY( 80.1538483333333,27.88376,80.15354,27.8841166666666,80.1529499999999,27.8834933333333,80.1532,27.8832566666666,80.1538483333333,27.88376 )) where id =3; 

Finally your approach only works because you only play with two geometries. As soon as you start dealing with real data, the query will perform very badly: it requires computing the intersection between each shape and all the others. For a set of 10,000 shapes, that means 100,000,000 computations (well actually 99,990,000 since you avoid intersecting a geometry with itself).

The proper approach is to detect the shapes that intersect by taking advantage of spatial indexing. The appropriate approach is to use the SDO_JOIN() procedure for that.

There is a much more simple way to do that.

Your Problem seems to use the SDO_GEOM.RELATE function. This function Returns the relationship between two or more Polygons.

In the following example all relations to the other polygons in your table are shown to the polygon with the 1

SELECT c.id,
SDO_GEOM.RELATE(c.polygon, 'determine', c_b.polygon, 0.005) relationship 
FROM my_polygon_table c, my_polygon_talbe c_b WHERE c_b.id = 1;

The result is one of the opsibile relationships: ANYINTERACT; CONTAINS; COVEREDBY; COVERS; DISJOINT; EQUAL; INSIDE; ON; OVERLAPBDYDISJOINT; OVERLAPBDYINTERSECT; TOUCH;

Care also about the Right Keyword:

If you pass the DETERMINE keyword in mask, the function returns the one relationship keyword that best matches the geometries.

If you pass the ANYINTERACT keyword in mask, the function returns TRUE if the two geometries are not disjoint.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top