oracle spatial 空間資料學習

2021-09-01 07:15:49 字數 2628 閱讀 5606

最近專案使用 空間資料庫 oracle spatial

--建立測試用表

create table spatialtest (

"id" varchar2(20) not null,

"name" varchar2(100),

"address" varchar2(200),

"telephone" varchar2(50),

"location" "mdsys"."sdo_geometry"

) --建立主鍵約束

alter table "spatialtest"

add constraint "pk_spatial" primary key("id");

--根據使用者表填寫空間元資料,建立了點資訊,與點資訊經緯度最大值,與最小值,與誤差範圍

insert into user_sdo_geom_metadata

values(

'spatialtest',

'location',

mdsys.sdo_dim_array(

mdsys.sdo_dim_element('longitude',-180,180,10),---longitude維最小,最大值和容忍度。

mdsys.sdo_dim_element('latitude',-90,90,10)-----latitude維最小,最大值和容忍度。

), 4326

);--建立空間索引 關鍵 假如不建立空間索引,速度很慢

create index spatial_idx on spatialtest(location) indextype is mdsys.spatial_index

--匯入測試資料

--1insert into spatialtest

values

('1',

'中油瑞飛',

'北京市歌華大廈',

'010-123456',

mdsys.sdo_geometry(2001,--定義的點的**

4326,--定義的座標系統**

mdsys.sdo_point_type(113.3293658, 23.14338586, 0),--定義了點的座標值

null,

null));

--匯入測試資料

--2insert into spatialtest

values

('2',

'山東',

'山東省日照市東港區',

'010-123456',

mdsys.sdo_geometry(2001,--定義的點的**

4326,

mdsys.sdo_point_type(113.2932474, 23.11883515, 0),

null,

null));

-- 關係查詢

select location from spatialtest;

select s.location.sdo_point.x langtitude from spatialtest s;

--空間分析查詢(113.2359818,23.16937253)周邊十公里資訊5條

select b.id id, b.name name, b.dist dist

from (select a.id id,

a.name name,

sdo_geom.sdo_distance(a.location,

mdsys.sdo_geometry(2001,

4326,

mdsys.sdo_point_type(113.2359818,

23.16937253,

0),null,

null),

1) dist

from spatialtest a

where sdo_within_distance(a.location,

mdsys.sdo_geometry(2001,

4326,

mdsys.sdo_point_type(113.2359818,

23.16937253,

0),null,

null),

'distance=10000') = 'true'

order by a.name) b

where rownum <= 5;

-- 空間分析查詢(113.2359818,23.16937253)附近的5條資訊

select a.id id,

a.name name,

a.location.sdo_point.x langtitude,

a.location.sdo_point.y latitude,

mdsys.sdo_nn_distance(1) distance

from spatialtest a

where sdo_nn(a.location,

mdsys.sdo_geometry(2001,

4326,

mdsys.sdo_point_type(113.2359818,

23.16937253,

0),null,

null),

'sdo_num_res=5',

1) = 'true'

oracle spatial空間型別建立

oracle spatial空間型別建立 使用oracle11g建立空間表資料,基於oracle spatial的儲存方式,通過這種儲存方式的幾何列shape的字段型別為mdsys.sdo geometry型別,個人覺得關於操作空間資料的sql語句來說,相交於postgresql ms sqlser...

Oracle spatial空間查詢的選擇度分析

接下來,我們來研究一下這個問題。建立表,並使用sdo geometry資料型別儲存向量資料。檢視表中記錄數 建立空間索引 create index tddcsde a3010 ix1 on tddcsde dltb20150705 shape indextype is mdsys spatial i...

Oracle spatial建立空間資料的字段詳解

oracle spatial oracle spatial主要通過 sdo geometry 來儲存空間資訊,主要有五個引數 sdo gtype number sdo srid number sdo point sdo point type sdo elem info mdsys.sdo elem ...