2014-05-09 74 views
0

我測量了一個陸地面積(地塊),並使用GPS設備捕獲了其4個角落的GPS座標。 現在我有兩個問題Oracle:如何檢查兩個多邊形是否重疊

  1. 如何保存這是Oracle數據庫。 (it seems answer of first point. is it?
  2. 保存之後我想檢查一下是否有任何陰謀與 (部分或全部)重疊到數據庫中另一個現有陰謀?
+0

請閱讀Oracle Spatial文檔並嘗試一下。 http://docs.oracle.com/cd/E11882_01/appdev.112/e11830/toc.htm – Rene

+0

1 - 是的。 2 - 嘗試sdo_geom.sdo_relate(詳情請參閱文檔)。 – Ben

回答

1

我得到了雷內和本非常有幫助的評論。 和基於我已經解決了我的問題..

--------------------------- 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; 

位置數據

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; 

要獲得這些互相交叉

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 ; 
0

好圖(多邊形) ,您可以對SDO_GEOM.SDO_INTERSECTION()函數的結果調用SDO_GEOM.SDO_AREA()。

然而,這不會給你有意義的結果:你的幾何圖形(大概是這樣)以大地座標WGS84座標(即十進制度數),但是你沒有指定任何座標系就加載它們。因此,任何面積計算都會返回平方度的結果,這是一個毫無意義且無法使用的結果。

你應該載入您的兩個幾何這樣的:

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; 

最後的辦法只能是因爲你只有兩個幾何玩。只要你開始處理真實的數據,查詢就會執行得非常糟糕:它需要計算每個形狀與所有其他形狀之間的交集。對於一組10,000個形狀,這意味着100,000,000個計算(實際上99,990,000,因爲避免了與幾何體相交)。

正確的方法是通過利用空間索引來檢測相交的形狀。適當的方法是使用SDO_JOIN()過程。