Search code examples
oracle-databaseoracle-spatial

Oracle: how to check either two polygon are overlapping or not


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?

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  ;