ArcGIS10已经推出快一年的时间了,在去年的用户大会上关于Geodatabase10的新特性上描述我们的相关Schema也发生了本质的变化,从原来的30多张表,变成现在的6张,那么最本质的变化就是相关的对象使用XML进行存储,这对我们开发者来说是一个好消息,因为我们可以通过XML结构来得知每一个对象是怎么定义的,而且我们也可以使用SQL来读取XML的值而不用使用ArcObject来读取。
关于Geodatabase10新特性可以参考:http://wenku.baidu.com/view/94721478168884868762d668.html
那么今天就给大家介绍一下怎么使用C#来访问这些值,其实抛开ArcGIS的知识,一个纯IT的开发人员只要了解XML的都会很容易的来获得这些信息。
首先看一下一个要素类为DLTB的XML格式
<DEFeatureClassInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:typens="http://www.esri.com/schemas/ArcGIS/10.0" xsi:type="typens:DEFeatureClassInfo"> <CatalogPath>/sde.SDE.czdj/sde.SDE.dltb</CatalogPath> <Name>sde.SDE.dltb</Name> <ChildrenExpanded>false</ChildrenExpanded> <DatasetType>esriDTFeatureClass</DatasetType> <DSID>8</DSID> <Versioned>false</Versioned> <CanVersion>false</CanVersion> <ConfigurationKeyword /> <HasOID>true</HasOID> <OIDFieldName>OBJECTID</OIDFieldName> <GPFieldInfoExs xsi:type="typens:ArrayOfGPFieldInfoEx"> <GPFieldInfoEx xsi:type="typens:GPFieldInfoEx"> <Name>OBJECTID</Name> <ModelName>OBJECTID</ModelName> <FieldType>esriFieldTypeOID</FieldType> <IsNullable>false</IsNullable> <Required>true</Required> <Editable>false</Editable> </GPFieldInfoEx> <GPFieldInfoEx xsi:type="typens:GPFieldInfoEx"> <Name>Shape</Name> <ModelName>Shape</ModelName> <FieldType>esriFieldTypeGeometry</FieldType> <IsNullable>true</IsNullable> <Required>true</Required> </GPFieldInfoEx> <GPFieldInfoEx xsi:type="typens:GPFieldInfoEx"> <Name>Shape.area</Name> <ModelName>Shape.area</ModelName> <FieldType>esriFieldTypeDouble</FieldType> <IsNullable>false</IsNullable> <Required>true</Required> <Editable>false</Editable> </GPFieldInfoEx> <GPFieldInfoEx xsi:type="typens:GPFieldInfoEx"> <Name>Shape.len</Name> <ModelName>Shape.len</ModelName> <FieldType>esriFieldTypeDouble</FieldType> <IsNullable>false</IsNullable> <Required>true</Required> <Editable>false</Editable> </GPFieldInfoEx> </GPFieldInfoExs> <CLSID>{52353152-891A-11D0-BEC6-00805F7C4268}</CLSID> <EXTCLSID /> <RelationshipClassNames xsi:type="typens:Names" /> <AliasName /> <ModelName /> <HasGlobalID>false</HasGlobalID> <GlobalIDFieldName /> <RasterFieldName /> <ExtensionProperties xsi:type="typens:PropertySet"> <PropertyArray xsi:type="typens:ArrayOfPropertySetProperty" /> </ExtensionProperties> <ControllerMemberships xsi:type="typens:ArrayOfControllerMembership"> <ControllerMembership xsi:type="typens:TopologyMembership"> <TopologyName>sde.SDE.czdj_Topology</TopologyName> <Weight>5</Weight> <XYRank>1</XYRank> <ZRank>1</ZRank> <EventNotificationOnValidate>false</EventNotificationOnValidate> </ControllerMembership> </ControllerMemberships> <FeatureType>esriFTSimple</FeatureType> <ShapeType>esriGeometryPolygon</ShapeType> <ShapeFieldName>Shape</ShapeFieldName> <HasM>false</HasM> <HasZ>false</HasZ> <HasSpatialIndex>true</HasSpatialIndex> <AreaFieldName>Shape.area</AreaFieldName> <LengthFieldName>Shape.len</LengthFieldName> <Extent xsi:type="typens:EnvelopeN"> <XMin>506464.78390000015</XMin> <YMin>3842861.5803999994</YMin> <XMax>516750</XMax> <YMax>3849454.2771000005</YMax> <SpatialReference xsi:type="typens:ProjectedCoordinateSystem"> <WKT>PROJCS["Xian_1980_3_Degree_GK_CM_111E",GEOGCS["GCS_Xian_1980",DATUM["D_Xian_1980",SPHEROID["Xian_1980",6378140.0,298.257]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Gauss_Kruger"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",111.45],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]</WKT> <XOrigin>-5123200</XOrigin> <YOrigin>-10002100</YOrigin> <XYScale>10000</XYScale> <ZOrigin>0</ZOrigin> <ZScale>1</ZScale> <MOrigin>0</MOrigin> <MScale>1</MScale> <XYTolerance>0.001</XYTolerance> <ZTolerance>0.001</ZTolerance> <MTolerance>0.001</MTolerance> <HighPrecision>true</HighPrecision> </SpatialReference> </Extent> <SpatialReference xsi:type="typens:ProjectedCoordinateSystem"> <WKT>PROJCS["Xian_1980_3_Degree_GK_CM_111E",GEOGCS["GCS_Xian_1980",DATUM["D_Xian_1980",SPHEROID["Xian_1980",6378140.0,298.257]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Gauss_Kruger"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",111.45],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]</WKT> <XOrigin>-5123200</XOrigin> <YOrigin>-10002100</YOrigin> <XYScale>10000</XYScale> <ZOrigin>-100000</ZOrigin> <ZScale>10000</ZScale> <MOrigin>-100000</MOrigin> <MScale>10000</MScale> <XYTolerance>0.001</XYTolerance> <ZTolerance>0.001</ZTolerance> <MTolerance>0.001</MTolerance> <HighPrecision>true</HighPrecision> </SpatialReference> </DEFeatureClassInfo>
我们可以看到,这个XML定义了要素类的名称、字段(字段的相关属性)、投影信息、范围等信息
------------------------Oracle----------------------------------------------------------------
在Oracle数据库中的存储并不是直接存储在Defination里面
而且需要使用sde.sdexmltotext操作符来转换一下
参考示例代码
using System.Xml.Linq; using System.Xml; using System.Xml.XPath; using (OracleConnection connection = new OracleConnection()) { connection.ConnectionString = "User Id=sde;Password=sde;Data Source=orcl;"; connection.Open(); OracleCommand cmd = new OracleCommand(); string sql = "SELECT sde.sdexmltotext(d1.xml_doc) as definition " + "FROM GDB_ITEMS LEFT OUTER JOIN SDE_XML_DOC1 d1 ON " + "GDB_ITEMS.definition = d1.sde_xml_id where name='TEST.dltb'"; cmd.CommandText = sql; cmd.Connection = connection; using (OracleDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { string def = System.Convert.ToString(dr.GetValue(0)); XDocument xd = XDocument.Parse(def); StringBuilder str = new StringBuilder(); int i = 1; foreach (XElement ele in xd.Descendants("GPFieldInfoEx")) { string name = ele.Element("Name").Value; string code = ele.Element("FieldType").Value; str.Append(i+":"+name + "," + code+"/n"); i++; } LSCommonHelper.MessageBoxHelper.ShowMessageBox(str.ToString()); } }
----------------------------------------------SQL Server----------------------------------
在SQL Server中,完全使用SQL语句直接对XML进行获得值,而不需要引用C#的类库
select definition.value('(/DEFeatureClassInfo/Name)[1]','nvarchar(max)') as "要素类名称", definition.value('(/DEFeatureClassInfo/DatasetType)[1]','nvarchar(max)') as "要素类类型", definition.value('(/DEFeatureClassInfo/GPFieldInfoExs/GPFieldInfoEx/Name)[1]','nvarchar(max)') as "字段1", definition.value('(/DEFeatureClassInfo/GPFieldInfoExs/GPFieldInfoEx/Name)[2]','nvarchar(max)') as "字段2", definition.value('(/DEFeatureClassInfo/GPFieldInfoExs/GPFieldInfoEx/Name)[3]','nvarchar(max)') as "字段3" FROM [sde].[sde].[GDB_ITEMS] WHERE Name='test.DBO.zd'
----------------------------------------------Oracle----------------------------------
SELECT EXTRACTVALUE(XMLType(Definition), '/DEWorkspace/MajorVersion') AS "Major version", EXTRACTVALUE(XMLType(Definition), '/DEWorkspace/MinorVersion') AS "Minor version", EXTRACTVALUE(XMLType(Definition), '/DEWorkspace/BugfixVersion') AS "Bug fix version" FROM sde.gdb_items_vw items INNER JOIN (SELECT UUID FROM sde.gdb_itemtypes WHERE Name = 'Workspace') itemtypes ON items.Type = itemtypes.UUID;
---------------------------------------File Geodatabase---------------------------------
如果用户使用FGDB,那么可以使用FileGDB API来获得相关的信息