IFeatureClass接口使用

IFeatureClass 用于访问控制要素类行为和属性的成员
IFeatureClass接口是获取和设置要素类属性的主要接口。例如,使用IFeatureClass接口获取要素类类型、获取满足查询条件的要素数目或在要素类中创建新要素。IFeatureClass接口继承了IObjectClass接口。
成员
AddField
向这个类中添加一个字段。
AddIndex
向这个类中添加一个索引。
AliasName
这个类的别名。
AreaField
几何区域字段
CLSID
与这个对象类实例相关的组件类的GUID
CreateFeature
创建一个新要素,系统自动分配一个ID,没有属性值。
DeleteField
从对象类中删除字段。
DeleteIndex
从对象类中删除索引。
EXTCLSID
与这个要素类的扩展类相关的组件类的GUID
Extension
这个对象类的扩展。
ExtensionProperties
这个对象类的扩展属性。
FeatureClassID
要素类的唯一标识符。
FeatureCount
指定查询获得的要素数目。
FeatureDataset
包含要素类的要素数据集。
FeatureType
要素类中的要素类型。
Fields
要素类的字段集合。
FindField
指定名称的字段索引。
GetFeature
根据对象ID获得要素。
GetFeatures
由一系列ID获得Rows的指针。
HasOID
指出要素类是否是否有一个要素表示字段(OID)。
Indexes
要素类的索引集合。
Insert
返回一个可以插入新要素的指针。
LengthField
图形长度字段。
ObjectClassID
对象类的唯一标识符。
OIDFieldName
OID相关的字段名称。
RelationshipClasses
该类参与的关系类。
Search
根据指定的查询返回要素的指针。
Select
根据查询返回包含对象ID的选择集合。
ShapeFieldName
默认Shape字段的名称。
ShapeType
要素类中默认Shape的类型。
Update
按照查询返回一个更新要素的指针。
继承的接口
IObjectClass
获得对象类的信息。
IClass
获得类的信息和管理类。
实现IFeatureClass的类
FeatureClass
FeatureClass
对象。
NAClassNetworkAnalyst)网络分析中将要素输入,以及产生输出要素。
NetCDFFeatureClassDataSourceNetCDF)内存中呈现的NetCDF要素类。
RasterCatalog
Geodatabase
表中的栅格数据集合。
RelQueryTable
用于连接有相同数据的两个数据集。
RouteEventSourceLocationRoute event source对象。
TemporalFeatureClassTrackingAnalyst  控制时态要素类的设置。
XYEventSource
XY event source
对象。
[C#]
//e.g., nameOfFeatureClass=”states”;
//on
ArcSDE use ISqlSyntax:ualifyTableName
的完全限定表名。
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);

}
几个常用的成员 [C#] //e.g.,fieldName=”MyField”
Public void IClass_DeletField(IFeatureClass featureClass,string fieldname)
{

//The following sample code demonstrates one methodology for deleting


//a field using DeleteFields


IFields fields=featureClass.Fields;


IField field=fields.get_Field(fields.FindField(fieldname));

//IFeatureClass interface inherits from IClass

featureClass.DeleteField(field);

}
IFeatureClass.CreateFeature Method
[Visual Basic.NET]
Public Function CreateFeature() As IFeature

[C#]
public IFeature CreateFeature();

CreateFeature在要素类中创建一个新要素。这个要素仅分配一个唯一的对象IDOID),没有其他属性值。使用IFeature::Store方法将这个要素存储到database中。当工作在版本要素类上时,CreateFeature应当在edit时期调用。调用IWorkspaceEdit::StartEditing可以开始edit session。对TopologyGeometric Network要素的编辑要在edit阶段进行,并且要包含edit operation
调用CreateFeature之后,并不自动设置默认的子类型,也不初始化默认值。如果要素没有子类型,调用IRowSubtypes::InitDefaultValues来初始化默认值。可以调用IRowSubtypes::SubtypeCode来设置要素的要素的子类型。
在要素类上调用CreateFeature方法(通过IFeatureClass接口)同调用CreateRow方法(通过ITable接口)的效果相同,不过IFeatureClass的方法返回一个row对象昂的IFeature接口。
创建一个新要素的步骤是:
1)
创建要素
2)
为要素创建几何图形。
3)
在要素中存储几何图形。
4)
存储要素。
IFeatureClass.CreateFeatureBuffer Method
创建一个要素的缓冲区
[VisualBasic.NET]
Public Function CreateFeatureBuffer() As IFeatureBuffer

[C#]
public IFeatureBuffer CreateFeatureBuffer();

CreateFeatureBuffer方法创建一个feature缓冲区,并返回IFeatureBuffer接口。结合insert cursor可以使用这个方法在要素类中创建新要素。调用IFeatureClassCreateFeatureBuffer方法和调用ITable中的CreateRowBuffer的作用相同,只是IFeatureClass的方法返回一个row bufferIFeatureClass指针。
IFeatureClass.FeatureCount Method
[Visual Basic.NET]
Public Function FeatureCount(ByVal QueryFilter As IQueryFilter) As Integer

[C#]
public int FeatureCount(IQueryFilter QueryFilter);

FeatureCount返回满足某些属性或IQueryFilter指定的空间查询的要素的数量。如果没有指定IQueryFilter,返回要素类中所有要素的数量。
IFeatureClass.FeatureDataset Property
[Visual Basic.NET]
Public ReadOnly Property FeatureDataset As IFeatureDataset

这个只读属性返回包含该要素类的数据集的IFeatureDataset接口。如果要素类是一个独立的要素类(无dataset),那么这个动能将会返回一个null值。一个coverage要素类返回指向自身的IFeatureDataset接口。Shapefiles返回一个null指针。
IFeatureClass.GetFeature Method
[Visual Basic.NET]
Public Function GetFeature(ByVal ID As Integer) As IFeature

[C#]
public IFeature GetFeature(int ID)

通过给定的对象IDOID)返回要素的IFeature接口。适用于通过OID寻找提顶要素。使用cursor可以遍历要素类中所有要素。
调用要素类的GetFeature方法(使用IFeatureClass接口)同调用GetRow方法(使用要素类的ITable接口)的效果相同,只是IFeatureClass返回IFeature接口。
[C#]//e.g, nameOfField=”City_Name”
public void IFeatureClass_GetFeature(IFeatureClass featureClass,string nameOfField)
{

//get the index of the field we are interested in


int fieldIndexValue=featureClass.FindField(nameOfField);


//get feature with OID 11,because it is known to exist


//This method is typically used to get a feature by know OID


//If you wish to loop through a series of features,use a Cursor.


IFeature
feature=featureClass.GetFeature(1);


Console.WriteLine("The {0} field conains a value of{1}",nameOfField,feature.get_Value(fieldIndexValue));

}
IFeatureClass.GetFeatures Method
[Visual Basic.NET]
Public Function GetFeatures(ByVal fids As Object,ByVal Recycling As Boolean) As IFeatureCursor

[C#]
public IFeatureCursor GetFeatures(object fids,bool Recycling)

GetFeatures返回包含要素类所有要素OIDIFeatureCursor。这个方法可以用来遍历已知OID的要素集。
调用IFeatureClassGetFeatures方法和调用ITableGetRows方法效果相同,只是返回IFeatureCursor接口。
[C#]
//e.g,nameOfField=”Symbol”
public void IFeatureClass_GetFeatures(IFeatureClass featureClass,string nameOfField)
{

//get the index of the field we are interested in


int fieldIndexValue=featureClass.FindField(nameOfField);

      

System.Collections.Generic.List<int> constructoidList=new System.Collections.Generic.List<int>();


constructoidList.Add(1);


constructoidList.Add(2);


constructoidList.Add(3);


constructoidList.Add(4);


constructoidList.Add(10);


int[] oidList=constructoidList.ToArray();


IFeatureCursor featureCursor=featureClass.GetFeatures(oidList,false);


IFeature feature=featureCursor.NextFeature();


//loop through the returned features and get the value for the field


while(feature!=null)


{


//do something with each feature(ie update geometry or attribute)


Console.WriteLine("The {0} field contains a value of {1}",nameOfField,feature.get_Value(fieldIndexValue));


feature=featureCursor.NextFeature();


}

}

 

 

IFeatureClass.Search Method

返回搜索的对象指针。

[Visual Basic.NET]        Public Function Search(ByVal filter As IQueryFilter, ByVal Recycling As Boolean) As IFeatureCursor

[C#]                             public IFeatureCursor Search(IQueryFilter filter, bool Recycling);

Search返回满足条件的IFeatureCursor。如果IQueryFilter没有给定值,feature cursor返回要素类的所有要素。

Recycling参数控制row的allocation行为。每次调用简单要素对象时,Recycling cursors可以rehydrate该对象,并可以最优化只读访问,例如在绘图时。多次调用cursor的NextFeature,维持recycling cursor返回的引用并不合法。不能修改要素对象返回的recycling cursor。使用Non-recycling cursor每次返回一个单独的要素。non-recycling返回的要素可以修改、存储各种行为。Geodatabase保证在编辑阶段non-recycling要素的唯一语义。如果搜索的要素已经被应用程序引用,将返回一个要素的地址。

Search方法返回的non-recycling要素指针并不用来更新cursor中的要素。Update方法返回的feature cursor可以用来更新要素。

[C#]

//下面的例子使用属性查询和空间查询获得要素的子集。

//在要素类中,遍历所有要素,并计算它们的的总面积。

public void IFeatureClass_Search(IFeatureClass featureClass)

{

       //在这个函数中将使用空间过滤器,并结合属性查询进行搜索。

       //在搜索中不必执行两种过滤类型,可以单独使用每一种。

      

       //创建一个envelope在空间上限制搜索。

       //(注意:只有高级geometries、envelopes和geometrybags可以使用)

       ESRI.ArcGIS.Geometry.IEnvelope envelope=new ESRI.ArcGIS.Geometry.EnvelopeClass();

       envelope.PutCoords(508786,681196,513033,684341);

      

       //创建一个空间查询

       ISpatialFilter spatialFilter=new SpatialFilterClass();

      

       //指定一个查询的的几何图形

       spatialFilter.Geometry=(ESRI.ArcGIS.Geometry.IGeometry)envelope;

      

       //确定在要素类上查询的几何字段

       string shpFld=featureClass.ShapeFieldName;

       spatialFilter.GeometryFiled=shpFld;

      

       //指定要使用的空间操作

       spatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelIntersects;

      

       //创建where表达式,这里只要要素

       //在envelope中有一个子类型"COM"

       spatialFilter.WhereClause="subtype='COM'";

      

       //将spatial filter赋给IQueryFilter接口

       IQueryFilter queryFilter=new QueryFilterClass();

       queryFilter=(IQueryFilter)spatialFilter;

      

       //在要素类上进行搜索,使用cursor保存结果

       IFeatureCursor featureCursor=featureClass.Search(queryFilter,false);

      

       //第一个返回的要素

       IFeature feature=featureCursor.NextFeature();

      

       //获得“Area”字段

       IFields fields=featCursor.Fields;

       int areaIndex=fields.FindField("Area");

      

       //保存总面积的变量

       double searchedArea=0;

      

       //遍历所有要素计算总面积

       while(feature!=null)

       {

              searchedArea=searcheArea+(double)feature.get_Value(areaIndex);

              feature=featureCursor.NextFeature();

       }

       Console.WriteLine("The total area of searched features is {0}",searchedArea);

       System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);

}

IFeatureClass.Select Method

返回包含对象IDs的选择。

[Visual Basic.NET]        Public Function Select(ByVal QueryFilter As IQueryFilter,ByVal selType As esriSelectionType, ByVal selOption As esriSelectonOption, ByVal selectionContainer As IWorkspace) As ISelectionSet

[C#]                             public ISelectionSet Select(IQueryFilter QueryFilter, esriSelectionType selType, esriSelectionOption selOption, IWorkspace selectionContainer);

Select返回一个满足条件的ISelectionSet。如果IQueryFilter中无值,将选择要素类的所有要素。调用IFeatureClass的Select方法同调用ITable中的相应方法效果相同。调用Select时,selectionContainer不需要参数。实参应为Null(C#,VB.Net)或者Nothing(VB6)。(注意:提供workspace类型的selectionContainer只读参数将会失败,因为Select会将选择的结果写入workspace。

IFeatureClass Select Example

[Visual Basic 6.0]

下面的例子使用属性查询选择要素类的子集。

Dim pFeatcls As IFeatureClass

Dim pFeatLayer As IFeatureLayer

Dim pDoc As IMxDocumentDim pMap As IMap  

Set pDoc=ThisDocument

Set pMap=pDoc.Maps.Item(0)

Set pFeatLayer=pMap.Layer(0)

Set pFeatcls=pFeatLayer.FeatureClass

'创建一个query过滤器,并赋予一个where从句。

Dim pQFilt As IQueryFilter

Set pQFilt=New QueryFilter

pQFilt.WhereClause="Shape_Area>77000"


'使用query过滤器选择要素

Dim pSelectionSet As ISelectionSet

'当调用Select时,不需要selectionContainer参数,在VB6中应赋nothing

Set pSelectionSet=pFeatcls.Select(pQFilt,esriSelectionTypeIDSet,esriSelectionOptionNormal,Nothing)

'计算选中的数目

MsgBox pSelectionSet.Count

[C#]

public void IFeatureClass_Select_Example(IFeatureClass featureClass)

{

       //创建查询过滤器并附予一个where从句

       IQueryFilter queryFilter=new QueryFilterClass();

       queryFilter.WhereClause="Shape_Area>77000";

       //使用query过滤器选择要素

       //调用Select时不需要selectionContainer参数。在C#和VB.Net中赋给其Null值

       ISelectionSet selectionSet=featureClass.Select(queryFilter,esriSelectionType.esriSelectionTypeIDSet,esriSelectionOption.esriSelectionOptionNormal,null);

       //计算选择的要素数目

       Console.WriteLine("{0}features where selected from{1} with where clause {2}",selectionSet.Count,featureClass.AliasName,queryFilter.WhereClause);

}


IObjectClass.RelationshipClasses Property

这个对象类参与的关系类。

[Visual Basic.NET]        Public Function get_RelationshipClasses(ByVal Role As esriRelRole) As IEnumRelationshipClass

[C#]                             public IEnumRelationshipClass get_RelationshipClasses(esriRelRole Role);

返回对象类参与的关系类的枚举。

geodatabase的对象类可能参与多个关系类。esriRelRole定义了对象类的角色(origin、destination或两者都有),RelationshipClasses属性根据其角色获得关系类的列表。这个属性返回一个IEnumRelationshipClass接口,使用它可以遍历返回的关系类。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值