/**********************************************************************************************、
informix gis 數據處理
/**********************************************************************************************、
一 Oracle Spatial中SDO_Geometry詳細說明
1 Oracle Spatial 定義的SDO_GEOMETRY類型爲:
CREATE TYPE sdo_geometry AS OBJECT (
SDO_GTYPE NUMBER, //前面字符串爲字段名;後面字符串爲字段類型
SDO_SRID NUMBER,
SDO_POINT SDO_POINT_TYPE,
SDO_ELEM_INFO SDO_ELEM_INFO_ARRAY,
SDO_ORDINATES SDO_ORDINATE_ARRAY);
其中sdo_geometry AS OBJECT ,標識該類型爲對象類型。開始我們可以想想它爲ArcObjects中的Geometry對象(本來要素的shape字段中的對象就是Geometry),
而不要理解他是怎麼樣組織的。至於該類型中的SDO_POINT_TYPE、SDO_ELEM_INFO_ARRAY、SDO_ORDINATE_ARRAY也是Oracle Spatial自定義的類型和 sdo_geometry 是一樣的。
現在對sdo_geometry 類型中的各個參數簡單的介紹:
1、SDO_GTYPE :表示要存儲的幾何類型,如點線面。它是通過 NUMBER類型來表達的;
2、SDO_SRID :幾何的空間參考座標系,類型也爲 NUMBER;
3、SDO_POINT :如果幾何類型點類型的話,就是存儲點座標,否則爲空。oracle自定義的SDO_POINT_TYPE類型;
4、SDO_ELEM_INFO :定義要如何理解SDO_ORDINATES中的座標串的;
5、SDO_ORDINATES :存儲實際座標的,以X、Y以及不同點之間都是逗號隔開;
下面將詳細介紹這些字段參數的含義
一、SDO_GTYPE
SDO_GTYPE 值是有四位數字組成的,它們的格式爲:dltt 。
其中,d 表示幾何的維數。如二維、三維對應的d=2和d=3;
l 定義了LRS。一般l=0;
tt 定義了地理對象的類型。現在使用從00到07,如tt=01代表爲單點;
SDO_GTYPE 2001 代表單點POINT 類型
二、SDO_SRID
SDO_SRID定義了空間座標參考系統。如果SDO_SRID爲null,則沒有指定座標系統,如果SDO_SRID不爲null,
那麼它的值必須在MDSYS.CS_SRS 表中的 SRID 列有對應的值,而且它的值必須插入USER_SDO_GEOM_METADATA視圖中
MDSYS.CS_SRS 表: SRID 空間參考ID
CS_NAME 座標系統名稱
SQL> select cs_name from MDSYS.CS_SRS where srid=4326;
CS_NAME
--------------------------------------------------------------------------------
WGS 84
二 informix spatial 說明
1 informix 的座標系
> select srid,description from spatial_references where srid=4326;
srid description
4326 EPSG 4326, version 8.1.1
2 informix spatial 功能加載(以root 用戶執行)
[root@xxgkdb1 gbase]# tar -xvf spatial8.21.FC7.tar -C /home/informix/gbase/extend/
echo "VPCLASS bts,num=1">>$INFORMIXDIR/etc/$ONCONFIG
數據庫重新啓動後,可以創建空間類型的表(而且系統中自動建立了17張與空間 有關的表)
2 ST_Point 函數
ST_Point(X double precision, Y double precision, SRID integer)
三 如何將 ORACLE 中的數據導入到 INFORMIX 中
1 oracle 端:
1) 表結構
create table HB_SJCJ_QY_JCXX_DIAN
(
OBJECTID VARCHAR2(50),
SHAPE MDSYS.SDO_GEOMETRY,
OBJECTTYPE VARCHAR2(50)
)
;
2) 具體數據如下:
SQL> select shape from HB_SJCJ_QY_JCXX_DIAN;
SHAPE(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
--------------------------------------------------------------------------------
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.48823, 39.87494, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.39039, 39.85949, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.37185, 39.85296, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.40378, 39.89828, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.37185, 39.85296, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.37185, 39.85296, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.45905, 39.89279, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.4412, 39.91751, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(116.40378, 39.89828, NULL), NULL, NULL)
3)創建中間表
> create table a(
OBJECTID VARCHAR2(50) ,GTYPE VARCHAR2(50), SRID VARCHAR2(50),
POINT_x VARCHAR2(50), POINT_y VARCHAR2(50), POINT_z VARCHAR2(50),
OBJECTTYPE VARCHAR2(50));
4) 創建存儲過程
create or replace procedure get_shape
is
v_OBJECTID varchar2(50);
v_shape MDSYS.SDO_GEOMETRY;
v_objecttype varchar2(50);
v_SDO_GTYPE varchar2(50);
v_SDO_SRID varchar2(50);
v_SDO_POINT_x varchar2(50);
v_SDO_POINT_y varchar2(50);
v_SDO_POINT_z varchar2(50);
v_SDO_POINT SDO_POINT_TYPE;
begin
for v_tab in(select OBJECTID,shape ,OBJECTTYPE
from HB_SJCJ_QY_JCXX_DIAN) loop
v_shape:=v_tab.shape;
v_SDO_GTYPE:=v_shape.SDO_GTYPE;
v_SDO_SRID:=v_shape.SDO_SRID;
v_SDO_POINT:=v_shape.SDO_POINT;
v_SDO_POINT_x:=v_SDO_POINT.x;
v_SDO_POINT_y:=v_SDO_POINT.y;
v_SDO_POINT_z:=v_SDO_POINT.z;
insert into a values(v_tab.OBJECTID,v_SDO_GTYPE,v_SDO_SRID,v_SDO_POINT_x,v_SDO_POINT_y,
v_SDO_POINT_z,v_tab.OBJECTTYPE);
end loop;
commit;
end;
/
5) 執行存儲過程,將數據導入到中間表
truncate table a;
exec get_shape();
select OBJECTID,GTYPE,SRID,POINT_x,POINT_Y from a;
objectid D157D75BD42B47F5A59AB5ADAC9A6EF0
gtype 2001
srid 4326
point_x 116.40034
point_y 39.90343
295 row(s) retrieved.
2 INFORMIX 端 建立中間表
create table a(
OBJECTID VARCHAR(50) ,GTYPE VARCHAR(50), SRID VARCHAR(50),
POINT_x VARCHAR(50), POINT_y VARCHAR(50), POINT_z VARCHAR(50),
OBJECTTYPE VARCHAR(50));
3 通過KETTLE 將數據導入到INFORMIX 端
4 INFORMIX 端將數據從中間表導入到 正式表
insert into HB_SJCJ_QY_JCXX_DIAN
select OBJECTID,ST_Point( POINT_x, POINT_y,4326),OBJECTTYPE from a;
5 3d,4d 數據如何寫入
例子:UPDATE points_of_interest SET thepoint_lonlat = PointFromText('POINT(' || longitude || ' ' || latitude || ')',4326)
1) 將一個表中的 x,y.z,m 座標寫入 空間表
-- 創建空間表
create table a
(
OBJECTID LVARCHAR(50),
SHAPE ST_Geometry,
OBJECTTYPE LVARCHAR(50)
)
;
--存有x,y.z,m 座標的表
create table b(x decimal(10,2),y decimal(10,2),z decimal(10,2),m decimal(10,2));
--x,y,z,m 座標 數據
insert into b values(112,44,111,2);
insert into b values(132.4,59,222,3);
insert into b values(172.56,86,444,5);
insert into b values(152,44.9,666,7);
> select * from b;
x y z m
112.00 44.00 111.00 2.00
132.40 59.00 222.00 3.00
172.56 86.00 444.00 5.00
152.00 44.90 666.00 7.00
4 row(s) retrieved.
--x,y 座標 數據
> select st_PointFromText('POINT (' || x || ' ' || y ||')',4326) from b;
(expression) 4326 POINT (112 44)
(expression) 4326 POINT (132.4 59)
(expression) 4326 POINT (172.56 86)
(expression) 4326 POINT (152 44.9)
4 row(s) retrieved.
--x,y,z 座標 數據
> select st_PointFromText('POINT z(' || x || ' ' || y ||' ' ||z ||')',4326) from b;
(expression) 4326 POINT Z (112 44 111)
(expression) 4326 POINT Z (132.4 59 222)
(expression) 4326 POINT Z (172.56 86 444)
(expression) 4326 POINT Z (152 44.9 666)
4 row(s) retrieved.
4 row(s) retrieved.
--x,y,z,m 座標 數據
> select st_PointFromText('POINT zm(' || x || ' ' || y ||' ' ||z ||' ' ||m ||')',4326) from b;
(expression) 4326 POINT ZM (112 44 111 2)
(expression) 4326 POINT ZM (132.4 59 222 3)
(expression) 4326 POINT ZM (172.56 86 444 5)
(expression) 4326 POINT ZM (152 44.9 666 7)
4 row(s) retrieved.
--將x,y 空間數據寫入
insert into a select 'aa',st_PointFromText('POINT(' || x || ' ' || y || ')',4326),'dfadf' from b;
> select * from a;
objectid aa
shape 4326 POINT (112 44)
objecttype dfadf
objectid aa
shape 4326 POINT (132.4 59)
objecttype dfadf
objectid aa
shape 4326 POINT (172.56 86)
objecttype dfadf
objectid aa
shape 4326 POINT (152 44.9)
objecttype dfadf
4 row(s) retrieved.
--將x,y,z 空間數據寫入
> insert into a select 'aa',st_PointFromText('POINT z(' || x || ' ' || y || ' ' || z ||')',4326),'dfadf' from b;
objectid aa
shape 4326 POINT Z (112 44 111)
objecttype dfadf
objectid aa
shape 4326 POINT Z (132.4 59 222)
objecttype dfadf
objectid aa
shape 4326 POINT Z (172.56 86 444)
objecttype dfadf
objectid aa
shape 4326 POINT Z (152 44.9 666)
objecttype dfadf
8 row(s) retrieved.
--將x,y,z,m 空間數據寫入
> insert into a select 'aa',st_PointFromText('POINT zm(' || x || ' ' || y || ' ' || z ||' ' || m ||')',4326),'dfadf' from b;
objectid aa
shape 4326 POINT ZM (112 44 111 2)
objecttype dfadf
objectid aa
shape 4326 POINT ZM (132.4 59 222 3)
objecttype dfadf
objectid aa
shape 4326 POINT ZM (172.56 86 444 5)
objecttype dfadf
objectid aa
shape 4326 POINT ZM (152 44.9 666 7)
objecttype dfadf
12 row(s) retrieved.
--空間表數據
> select * from a;
objectid aa
shape 4326 POINT (112 44)
objecttype dfadf
objectid aa
shape 4326 POINT (132.4 59)
objecttype dfadf
objectid aa
shape 4326 POINT (172.56 86)
objecttype dfadf
objectid aa
shape 4326 POINT (152 44.9)
objecttype dfadf
objectid aa
shape 4326 POINT Z (112 44 111)
objecttype dfadf
objectid aa
shape 4326 POINT Z (132.4 59 222)
objecttype dfadf
objectid aa
shape 4326 POINT Z (172.56 86 444)
objecttype dfadf
objectid aa
shape 4326 POINT Z (152 44.9 666)
objecttype dfadf
objectid aa
shape 4326 POINT ZM (112 44 111 2)
objecttype dfadf
objectid aa
shape 4326 POINT ZM (132.4 59 222 3)
objecttype dfadf
objectid aa
shape 4326 POINT ZM (172.56 86 444 5)
objecttype dfadf
objectid aa
shape 4326 POINT ZM (152 44.9 666 7)
objecttype dfadf
--得到空間數據(點) 的X,Y,Z,M 座標值
> select st_x(shape::st_point),st_y(shape::st_point),st_z(shape::st_point),st_m(shape::st_point) from a;
(expression) (expression) (expression) (expression)
112.0000000000 44.00000000000
132.4000000000 59.00000000000
172.5600000000 86.00000000000
152.0000000000 44.90000000000
112.0000000000 44.00000000000 111.0000000000
132.4000000000 59.00000000000 222.0000000000
172.5600000000 86.00000000000 444.0000000000
152.0000000000 44.90000000000 666.0000000000
112.0000000000 44.00000000000 111.0000000000 2.000000000000
132.4000000000 59.00000000000 222.0000000000 3.000000000000
172.5600000000 86.00000000000 444.0000000000 5.000000000000
152.0000000000 44.90000000000 666.0000000000 7.000000000000
12 row(s) retrieved.
--根據條件取得空間數據(點) 的X,Y,Z,M 座標值
> select st_x(shape::st_point),st_y(shape::st_point),st_z(shape::st_point),st_m(shape::st_point) from a where st_x(shape::st_point)>150;
(expression) (expression) (expression) (expression)
172.5600000000 86.00000000000
152.0000000000 44.90000000000
172.5600000000 86.00000000000 444.0000000000
152.0000000000 44.90000000000 666.0000000000
172.5600000000 86.00000000000 444.0000000000 5.000000000000
152.0000000000 44.90000000000 666.0000000000 7.000000000000
6 row(s) retrieved.
--增加一條 多邊型 空間數據
> INSERT INTO a VALUES('1111',ST_PolyFromText('polygon((10.01 20.03,10.52 40.11,30.29 41.56,31.78 10.74,10.01 20.03))',4326),'111');
objectid aa
shape 4326 POINT ZM (152 44.9 666 7)
objecttype dfadf
objectid 1111
shape 4326 POLYGON ((10.01 20.03, 31.78 10.74, 30.29 41.56, 10.52 40.11,
10.01 20.03))
objecttype 111
13 row(s) retrieved.
--取得 空間座標的 x,y,z,m 的最大,最小值 (此值是每個空間對象,每行的 最大最小值)
>select st_minx(shape) minx,st_miny(shape) miny,st_minz(shape) minz,st_minm(shape) minm,st_maxx(shape) maxx,st_maxy(shape) maxy,st_maxz(shape) maxz,st_maxm(shape) maxm from a;
minx 152.0000000000
miny 44.90000000000
minz 666.0000000000
minm 7.000000000000
maxx 152.0000000000
maxy 44.90000000000
maxz 666.0000000000
maxm 7.000000000000
minx 10.01000000000
miny 10.74000000000
minz
minm
maxx 31.78000000000
maxy 41.56000000000
maxz
maxm
13 row(s) retrieved.
--取得 空間座標的 x 的 最小值 (此值是每個空間對象,每行的 最小值)
> select st_minx(shape) minx from a;
minx
112.0000000000
132.4000000000
172.5600000000
152.0000000000
112.0000000000
132.4000000000
172.5600000000
152.0000000000
112.0000000000
132.4000000000
172.5600000000
152.0000000000
10.01000000000
13 row(s) retrieved.
--取得 所有空間對象的 最小X 值
> select min(st_minx(shape)) minx from a;
minx
10.01000000000
1 row(s) retrieved.
--取得SRID
> select st_srid(shape) maxx from a;
maxx
4326
4326
4326
4326
4326
4326
4326
4326
4326
4326
4326
4326
4326
13 row(s) retrieved.
--將空間對象用TEXT 形式存放到表bb 中 (如果爲多類型,導入到空間表時會發生從錯誤,如同時 存在點和 多邊型。需要按不同類型導入)
create table bb
(
OBJECTID LVARCHAR(50),
SHAPE LVARCHAR(32000),
OBJECTTYPE LVARCHAR(50)
)
;
> insert into bb select objectid ,st_astext(shape)::lvarchar(32000),objecttype from a;
13 row(s) inserted.
> select * from bb;
objectid aa
shape POINT (112 44)
objecttype dfadf
objectid aa
shape POINT (132.4 59)
objecttype dfadf
objectid aa
shape POINT (172.56 86)
objecttype dfadf
objectid aa
shape POINT (152 44.9)
objecttype dfadf
objectid aa
shape POINT Z (112 44 111)
objecttype dfadf
objectid aa
shape POINT Z (132.4 59 222)
objecttype dfadf
objectid aa
shape POINT Z (172.56 86 444)
objecttype dfadf
objectid aa
shape POINT Z (152 44.9 666)
objecttype dfadf
objectid aa
shape POINT ZM (112 44 111 2)
objecttype dfadf
objectid aa
shape POINT ZM (132.4 59 222 3)
objecttype dfadf
objectid aa
shape POINT ZM (172.56 86 444 5)
objecttype dfadf
objectid aa
shape POINT ZM (152 44.9 666 7)
objecttype dfadf
objectid 1111
shape POLYGON ((10.01 20.03, 31.78 10.74, 30.29 41.56, 10.52 40.11, 10.01
20.03))
objecttype 111
13 row(s) retrieved.
--將bb 表中的數據 導入到空間數據表cc
create table cc
(
OBJECTID LVARCHAR(50),
SHAPE ST_Geometry,
OBJECTTYPE LVARCHAR(50)
)
;
--導入點數據
insert into cc select OBJECTID,ST_PointFromText(shape,4326), OBJECTTYPE from bb;
--導入多邊型數據
insert into cc select OBJECTID,ST_PolyFromText(shape,4326), OBJECTTYPE from bb;
6 附錄:空間數據表名
> > select tabname from systables where tabid>99;
tabname sysblderrorlog
tabname sysbldobjects
tabname sysbldobjdepends
tabname sysbldobjkinds
tabname sysbldregistered
tabname sysbldirequired
tabname sysbldiprovided
tabname bld_registered
tabname bldi_required
tabname bldi_provided
tabname spatial_references
tabname geometry_columns
tabname spatial_ref_sys
tabname se_metadatatable
tabname st_units_of_measure
tabname se_views
tabname spatial_references_expand
17 row(s) retrieved.
informix gis 數據處理
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
informix 多實例安裝
/***********************************************************************/i
yutonging2016
2020-06-16 03:20:13
informix 分頁
yutonging2016
2018-08-28 13:47:19
informix 分片表
yutonging2016
2018-08-28 13:47:14
informix-trigger
/*************************************************************************
yutonging2016
2020-06-16 03:20:14
informix-exists error ??
yutonging2016
2018-08-28 13:47:19
informix-通過系統視圖查詢
yutonging2016
2018-08-28 13:47:14
informix-procedure
yutonging2016
2018-08-28 13:47:13
informix 自定義聚集函數
yutonging2016
2018-08-28 13:47:12
informix ontape
/***********************************************************************/i
yutonging2016
2020-06-16 03:20:14
informix LIST
yutonging2016
2020-06-16 03:20:13
informix-安裝
yutonging2016
2020-02-24 02:07:08
informix-dbexport-dbimport
yutonging2016
2020-02-24 02:07:07
informix 外部表
yutonging2016
2018-08-28 13:47:21
informix sds 搭建
yutonging2016
2018-08-28 13:47:19
informix-dbschema
yutonging2016
2018-08-28 13:47:14