版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://mxf-gis.blogbus.com/logs/30457468.html
提供创建和打开各种数据集和其他workspace级别对象的成员。
IFeatureWorkspace接口用于访问和管理地理数据库中的要素的重要成分—数据集,如Tables,ObjectClasses,FeatureClasses,FeatureDatasets,和RelationshipClasses。所有的Open方法(例如OpenTable)都要以dataset的名称作为输入。在企业数据库上工作时,就需要使用完全限定名(例如,”database.owner.tablename”或”owner.tablename”).
处理地理数据库时(personal,file或ArcSDE),workspace将运行一个实例datasets的对象表。不同的opendatasets的方法返回一个对其的引用。
IFeatureWorkspace是用workspace创建和打开对象、对象类的主接口。
成员
CreateFeatureClass,CreateFeatureDataset,CreateQueryDef,CreateRelationshipClass,CreateTable,OpenFeatureClass,OpenFeatureDataset,OpenFeatureQuery,OpenRelationshipClass,OPenRelationshipQuery,OpenTable.
若干个常用的成员
IFeatureWorkspace.CreateFeatureClass方法
[Visual Basic.NET] Public Function CreateFeatureClass(ByVal Name As String,ByVal Fields As IFields,ByVal CLSID As UID,ByVal EXTCLSID As UID,ByVal FeatureType As esriFeatureType,ByVal ShapeFieldName As String,ByVal ConfigKeywork As String) As IFeatureClass
[C#] public IFeatureClass CreateFeatureClass(string Name,IFields Fields,UID CLSID,UID EXTCLSID,esriFeatureType FeatureType,string ShapeFieldName,string ConfigKeyword);
CreateFeatureClass方法可以用来创建独立的要素类。除了CreateTable所需的参数外,还要指定FeatureType参数(如esriFTsimple,esriFTComplexEdgeFeature和其他)和shapeFieldName。ShapeFieldName表示要素类几何图形字段的名称。在调用CreateFeatureClass之前,设置好GeometryDef对象的空间参考以及空间索引。
在Geodatabase wokspace中创建FeatureClass要包含一些必须的字段。从你要创建的对象类型的类描述中可以获得所需字段(IObjectClassDescription的RequiredFields字段)。
CLSID参数用来指定实例化对象的GUID。如果未传入参数,地理数据库将使用与esriGeoDatabase.Feature有关的CLSID。多数例子中该法可行。如果要素类有自定义的Feature而不是esriGeoDatabase.Feature,这时或以后调用要素类的IClassSchemaEdit接口传入GUID。
EXTCLSID可选参数指定实例化FeatureClassExtension对象的GUID。该对象至少要支持IClassExtension接口。使用configurationKeyword参数可以控制RDBMS中的表的物理布局—例如,在Oracle数据库中,configuration keyword控制表创建的空间、初始化、next extents和其他属性。ArcSDE的configurationKeyword由ArcSDE data adimistrator设置。
在9.2地理数据库之前的workspace中,GeometryDef引用一个低精度的空间参考。9.1和之前的版本只支持低精度的空间参考,9.2要求高精度的空间参考。使用IControlPrecision2::IsHighRecision来管理空间参考的精度。使用IGeodatabaseRelease接口释放geodatabase。
注意:不支持下列表和要素名称前缀:”gdb_”,”sde_”,”delta_”
Example
[Visual Basic 6.0]
Public Sub CreateShapefile()
Const strFolder As String="D:/DATA"
Const strName As String="MyShapeFile" '不要包含.shp扩展
Const strShapeFieldName As String="Shape"
'打开包含shapefile的文件夹作为workspace
Dim pFWS As IFeatureWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory=New ShapefileWorkspaceFactory
Set pFWS=pWorkspaceFactory.OpenFromFile(strFolder,0)
Dim pFields As IFields
Dim pFieldsEdit As IFieldsEdit
Set pFields=New esriGeoDatabase.Fields
Set pFieldsEdit=pFields
Dim pField As IField
Dim pFieldEdit As IFieldEdit
Set pField=New esriGeoDatabase.Field
Set pFieldEdit=pField
pFieldEdit.Name=strShapeFieldName
pFieldEdit.Type=esriFieldTypeGeometry
Dim pGeomDef As IGeometryDef
Dim pGeomDefEdit As IGeometryDefEdit
Set pGeomdef=New GeometryDef
Set pGeomDefEdit=pGeometryDef
With pGeomDefEdit
.GeometryType=esriGeometryPolygon
Set.SpatialReference=New UnknownCoordinateSystem
End With
Set pFieldEdit.GeometryDef=pGeomDef
pFieldsEdit.AddField pField
Set pField=New esriGeoDatabase.Field
Set pFieldEdit=pField
With pFieldEdit
.Length=30
.Name="MiscText"
.Type=esriFieldTypeString
End With
pFieldsEdit.AddField pField
'创建shapefile
Dim pFeatClass As IFeatureClass
Set pFeatClass=pFWS.CreateFeatureClass(strName,pFields,Nothing,Nothing,esriFTSimple,strShapeFieldName,"")
End Sub
IFeatureWorkspace.OpenFeatureClass方法
[Visual Basic.NET] Public Function OpenFeatureClass(ByVal Name As String) As IFeatureClass
[C#] public IFeatureClass OpenFeatureClass(string Name);
使用完全限定名可以打开workspace中任何已存在的要素类。地理数据库中的每一个要素类都有唯一的完全限定名,使用OpenFeatureClass可以直接打开要素类。
使用IDatabaseConnectionInfo接口确定User和Database。ISQLSyntax::QualifyTableName可以用来确定要素类的完全限定名。使用IWorkspace2接口的NameExists来确定geodatabase中的要素类是否有适当的名称。
打开参与topology或geometric network的要素类将在内存中打开所有参与的要素类。
OpenFeatureClass名称参数的一些例子。
Coverage要素类
building:polygon
Oracle 要素类(如果已经连接到要素类,则不需要owner前缀。
gdb.Buildings
SQLServer要素类
fdo_data.gdb.Buildings
Informix要素类
Bladetest2:gdb.Buildings
VPF要素类
Ks032193:veg:vgfarea(library:coverage:feature class)
VPF数据的library名称区分大小写,并且要和LAT中存储的一致(Library Attribute Table)
与Topology有关的4个表格:T_#_DirtyAreas,T_#_PolyErrors,T_#_LineErrors和T_#_PointErrors可以直接编辑。由于这个原因他们不能打开,打开时返回一个地理数据库的错误。
Example
[Visual Basic 6.0]
Public Sub OpenFeatureClass_Example()
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory=New ShapefileWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Set pFeatureWorkspace=pWorkspaceFactory.OpenFromFile("D:/Data/Esridata/USA",0)
Dim pFeatureClass As IFeatureClass
Set pFeatureClass=pFeatureWorkspace.OpenFeatureClass("States")
MsgBox"There are " & pFeatureClass.FeatureCount(Nothing) & "states"
End Sub
[C#]
//e.g.,nameOfShapefile="States";
// dataPath="D://Data//Esridata//USA"
public void IFeatureWorkspace_OpenFeatureClass_Example(string dataPath,string nameOfShapefile)
{
IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace=(IFeatureWorkspace)workspaceFactory.OpenFromFile(dataPath,0);
IFeatureClass featureClass=featureWorkspace.OpenFeatureClass(nameOfShapefile);
Console.WriteLine("There are {0} features in the {1} feature class",featureClass.FeatureCount(new QueryFilterClass()),featureClass.AliasName);
}
//适用于各种类型workspace的通用形式
//e.g.,nameOfFeatureClass="States"
//on ArcSDE use ISqlSyntax::QualifyTableName for qualified names
public IFeatureClass getIFeatureClass(IWorkspace workspace,string nameOfFeatureClass)
{
//cast for the feature workspace from the workspace
IFeatureWorkspace featureWorkspace=(IFeatureWorkspace)workspace;
//open the featureclass
return featureWorkspace.OpenFeatureClass(nameOfFeatureClass);
}