[C#]
public void AddField(IField Field)
IFeatureClass.AddField(Field) 方法,增加一个属性字段到这个要素类,其中传入的参数为一个IField接口的变量,此变量可以由其他要素类获得并赋值给要操作的要素类,可用IFeilds接口的Field属性来获得。
返回的错误
-2147220649-FDO_E_TABLE_DUPLICATE_COLUMN 表中已存在指定名称的字段。
-2147220961-FDO_E_NO_SCHEMA_LICENSE
无权修改要素类的结构。使用ArcView的license,向参与集合网络、拓扑和混合关系类(feature-linked annotation)的要素类添加字段能引发这个错误。
15.2、IFeatureClass.DeleteField 方法
[C#]
public void DeleteField(IField Field);
IFeatureClass.DeleteField(Field) 方法,删除一个属性字段,其中传入的参数为一个IField接口的变量。
返回的错误
-2147219878-FDO_E_FIELD_CANNOT_DELETE_WEIGHT_FIELD 不能删除geometric network中与权重相关的字段。
-2147219877-FDO_E_FIEID_CANNOT_DELETE_REQUIRED_FIELD
不能删除所要求的字段。如果字段设为required,可以使用IFieldEdit::Required属性移除required状态,然后就可以删除field了。
-2147220961-FDO_E_NO_SCHEMA_LICENSE
无权修改要素类的结构。使用ArcView的license,向参与集合网络、拓扑和混合关系类(feature-linked annotation)的要素类添加字段能引发这个错误。 -2147215862-FDO_E_SE_DBMS_DOES_NOT_SUPPORT 不能从DB2中删除字段。
DeleteField从从表、对象类或要素类中删除指定字段。Geodatabase需要的和不能删除的字段包括:OBJECTID字段、SHAPE和shape依赖的字段例如SHAPE_Length、网络要素类激活的AncillaryRole和Weight字段、亚字段-如果要删除一个subtype字段,必须以subtype字段删除。 [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); }
15.3、IFeatureClass.CreateFeature 方法
[C#]
public IFeature CreateFeature();
CreateFeature在要素类中创建一个新要素。这个要素仅分配一个唯一的对象ID(OID),没有其他属性值。使用IFeature::Store方法将这个要素存储到database中。当工作在版本要素类上时,CreateFeature应当在edit时期调用。调用IWorkspaceEdit::StartEditing可以开始edit session。对Topology或Geometric Network要素的编辑要在edit阶段进行,并且要包含edit operation。
调用CreateFeature之后,并不自动设置默认的子类型,也不初始化默认值。如果要素没有子类型,调用IRowSubtypes::InitDefaultValues来初始化默认值。可以调用IRowSubtypes::SubtypeCode来设置要素的要素的子类型。
在要素类上调用CreateFeature方法(通过IFeatureClass接口)同调用CreateRow方法(通过ITable接口)的效果相同,不过IFeatureClass的方法返回一个row对象昂的IFeature接口。 创建一个新要素的步骤是: 1) 创建要素
2) 为要素创建几何图形。 3) 在要素中存储几何图形。 4) 存储要素。
15.4、IFeatureClass.CreateFeatureBuffer 方法
[C#]
public IFeatureBuffer CreateFeatureBuffer();
CreateFeatureBuffer方法创建一个feature缓冲区,并返回IFeatureBuffer类型的变量,然后再对这个变量进行操作。结合insert cursor可以使用这个方法在要素类中创建新要素。调用IFeatureClass的
CreateFeatureBuffer方法和调用ITable中的CreateRowBuffer的作用相同,只是IFeatureClass的方法返回一个row buffer的IFeatureClass指针。
15.5、IFeatureClass.FeatureCount 方法
[C#]
public int FeatureCount(IQueryFilter QueryFilter);
FeatureCount返回满足某些属性或IQueryFilter指定的空间查询的要素的数量。如果没有指定IQueryFilter,返回要素类中所有要素的数量。
15.6、IFeatureClass.FeatureDataset 属性
这个只读属性返回包含该要素类的数据集的IFeatureDataset接口。如果要素类是一个独立的要素类(无dataset),那么这个动能将会返回一个null值。一个coverage要素类返回指向自身的IFeatureDataset接口。Shapefiles返回一个null指针。
15.7、IFeatureClass.GetFeature 方法
[C#]
public IFeature GetFeature(int ID)
通过给定的对象ID(OID)返回要素的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(\of{1}\}
15.8、IFeatureClass.GetFeatures 方法
[C#]
public IFeatureCursor GetFeatures(object fids,bool Recycling);
GetFeatures返回包含要素类所有要素OID的IFeatureCursor。这个方法可以用来遍历已知OID的要素集。 调用IFeatureClass的GetFeatures方法和调用ITable的GetRows方法效果相同,只是返回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[] 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(\{1}\ feature=featureCursor.NextFeature(); } }
15.9、IFeatureClass.Search 方法
[C#]
public IFeatureCursor Search(IQueryFilter filter, bool Recycling);
Search返回满足条件的IFeatureCursor。如果IQueryFilter没有给定值,feature cursor返回要素类的所有要素。再用IfeatureCursor的NextFeature的方法依次得到每一个Feature。
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在空间上限制搜索。