使用SQL操作FeatureClass

1、数据插入:数据插入直接使用insert语句完成,这里主要讲存储类型为ST_Geometry的要素类

INSERT INTO sensitive_areas (area_id , name, area_size, type , zone,fid)
VALUES (1, 'Summerhill Elementary School', 67920.64, 'school', sde.ST_PolyFromText('polygon
((52 28,58 28,58 23,52 23,52 28))', 0));

ps: zone字段属于ST_Geometry类型,构造ST_Geometry的时候可以通过两种方法来完成:

1)使用WKT编码

2)使用WKB编码

上面两种编码都是OGC规范的编码方式,分别通过ST_PolyFromText()和ST_PointFromWKB() 以及一系列类似函数还完成从WKT或WKB到ST_Geometry转换。

下面为所有相关ST函数:

ST_GeomFromText—Creates an ST_Geometry from a text representation of any geometry type

ST_PointFromText—Creates an ST_Point from a point text representation

ST_LineFromText—Creates an ST_LineString from a linestring text representation

ST_PolyFromText—Creates an ST_Polygon from a polygon text representation

ST_MPointFromText—Creates an ST_MultiPoint from a multipoint representation

ST_MLineFromText—Creates an ST_MultiLineString from a multilinestring representation

ST_MPolyFromText—Creates an ST_MultiPolygon from a multipolygon representation

ST_AsText—converts an existing geometry into a text representation

ST_GeomFromWKB—Creates an ST_Geometry from a WKB representation of any geometry type

ST_PointFromWKB—Creates an ST_Point from a point WKB representation

ST_LineFromWKB—Creates an ST_LineString from a linestring WKB representation

ST_PolyFromWKB—Creates an ST_Polygon from a polygon WKB representation

ST_MPointFromWKB—Creates an ST_MultiPoint from a multipoint WKB representation

ST_MLineFromWKB—Creates an ST_MultiLineString from a multilinestring WKB representation

ST_MPolyFromWKB—Creates an ST_MultiPolygon from a multipolygon WKB representation

ST_AsBinary—converts an existing geometry value into well-known binary representation.

2、数据更新:

UPDATEsensitive_areas
SET zone= sde.st_pointfromtext('polygon ((52 30,58 30,58 23,50 23,50 28))', 0))
WHERE area_id = 1;
3、数据删除:

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);
4、数据查询:

在进行空间查询的时候会用到索引,其中infomix使用R树索引,PostgreSQ使用Generalized Search Tree (GiST) R-tree索引, oracle和 DB2 使用网格索引。
在oracle中进行查询会执行下面的步骤:
1)首先比较grid和查询范围,找出在查询范围内的所有grid。
2)找出在这些grid内的所有要素。
3)将这些要素的外包络矩形和查询范围比较,找出所有在查询范围内以及和查询范围相交的要素。
4)使用ST函数进行最终过滤(一般使用ST_Intersects或ST_Contains),找到完全符合条件的要素。
下面是一个进行空间查询的例子:
SELECT sa.name "Sensitive Areas", hs.name "Hazardous Sites"
FROM sensitive_areas sa, hazardous_sites hs
WHERE sde.st_overlaps (sa.zone, sde.st_buffer(hs.location,.01)) = 1;
3创建索引
CREATE INDEX sa_idx ON sensitive_areas(zone)
INDEXTYPE IS sde.st_spatial_index
PARAMETERS('st_grids=1,3,0 st_srid=0');
4创建空间参考系
ESRI建议最好使用ArcGIS Desktop来进行空间参考系的创建,但也可以使用SQL语句进行空间参考系的创建。执行下面的sql语句:
INSERT INTO SDE.ST_SPATIAL_REFERENCES VALUES (
GCS_North_American_1983,
1,
-400,
-400,
1000000000,
-100000,
10000,
-100000,
10000,
9.999E35,
-9.999E35,
9.999E35,
-9.999E35,
9.999E35,
-9.999E35,
9.999E35,
-9.999E35,
4269,
'GCS_North_American_1983',
'PROJECTED',
NULL,
'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID
["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT
["Degree",0.0174532925199433]]',
'ArcSDE SpRef'
);
本篇文章来源于 GIS空间站 转载请以链接形式注明出处 网址:http://www.gissky.net/Article/1785.htm

你可能感兴趣的:(使用SQL操作FeatureClass)