SDE 空间表操作
1. 创建空间表(包含st_geometry属性字段)
CREATE TABLE sensitive_areas (area_id integer, name varchar(128), area_size float, type varchar(10), zone sde.st_geometry);
2. 创建空间参考
(1)查询空间参考表,是否存在
select * from SDE.ST_SPATIAL_REFERENCES
(2)创建空间参考 --这里是GCS_WGS_1984坐标系,注意 srid 不能和已有的坐标系重复
insert into SDE.ST_SPATIAL_REFERENCES (SR_NAME, SRID, X_OFFSET, Y_OFFSET, XYUNITS, Z_OFFSET, Z_SCALE, M_OFFSET, M_SCALE, MIN_X, MAX_X, MIN_Y, MAX_Y, MIN_Z, MAX_Z, MIN_M, MAX_M, CS_ID, CS_NAME, CS_TYPE, ORGANIZATION, ORG_COORDSYS_ID, DEFINITION, DESCRIPTION) values ('GCS_WGS_1984', 0, -400, -400, 1000000000, -100000, 10000, -100000, 10000, -180, 180, -90, 90, 0, 0, 0, 0, 4326, 'GCS_WGS_1984', 'GEOGRAPHIC', 'GCS_WGS_1984', null, 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]', 'Default Spatial Reference SRID 0');
3. 插入数据 (注意坐标系代码要和我们上面创建的保持一致,这里为 0)
(1)点对象
INSERT INTO SENSITIVE_AREAS (area_id, name, area_size, type, zone) VALUES (1, 'Summerhill Elementary School', 67920.64, 'school', sde.ST_PointFromText('point(112.32 22.43)',0));
(2)线对象
INSERT INTO SENSITIVE_AREAS (area_id, name, area_size, type, zone) VALUES (1, 'Summerhill Elementary School', 67920.64, 'school', sde.ST_LineFromText('linestring(112.32 22.43, 112.56 22.31, 112.62 22.78)', 0));
(3)面对象
INSERT INTO SENSITIVE_AREAS (area_id, name, area_size, type, zone) VALUES (1, 'Summerhill Elementary School', 67920.64, 'school', sde.ST_PolyFromText('polygon((112.32 22.43, 112.56 22.31, 112.62 22.78, 112.32 22.43))', 1));
4. 创建空间索引
CREATE INDEX sa_idx ON sensitive_areas(zone) INDEXTYPE IS sde.st_spatial_index PARAMETERS('st_grids=1,3,0 st_srid=0');
5. 其它数据操作
(1)更新空间字段
UPDATE sensitive_areas SET zone = sde.st_pointfromtext('point(18 57)', 1) WHERE area_id = 102;
(2)删除一条记录(和其它空间表进行空间分析)
DELETE FROM sensitive_areas WHERE names (SELECT sa.names FROM sensitive_areas sa, hazardous_sites hs WHERE sde.st_overlaps (sa.zone, sde.st_buffer (hs.location,.01)) = 1);