featureLayer中添加字段
这是我2010年11月份写的东东,现在拿出来给大家分享一下,这几个方法都是抽象出来的,可以拿过来直接使用。
说明一下:这些都是.net平台,VS2008+ArcGis9.3调试通过的
//检查fields是否有效
public IFields ValidateFieldsForWorkspace(IFields fields, IWorkspace workspace)
{
// Create a new field checker.
IFieldChecker fieldChecker = new FieldCheckerClass();
fieldChecker.ValidateWorkspace = workspace;
// Validate the fields.
IEnumFieldError enumFieldError = null;
IFields validatedFields = null;
fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
// Display the field errors.
IFieldError fieldError = null;
enumFieldError.Reset();
while ((fieldError = enumFieldError.Next()) != null)
{
IField errorField = fields.get_Field(fieldError.FieldIndex);
Console.WriteLine("Field '{0}': Error '{1}'", errorField.Name,
fieldError.FieldError);
}
// Return the validated fields.
return validatedFields;
}
//为要素类创建fields
public IFields CreateFieldsCollectionForFeatureClass(ISpatialReference
spatialReference)
{
// Use the feature class description to return the required fields in a fields collection.
IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
IObjectClassDescription cDesc = (IObjectClassDescription)fcDesc;
// Create the fields using the required fields method.
IFields fields = ocDesc.RequiredFields;
// Locate the shape field with the name from the feature class description.
int shapeFieldIndex = fields.FindField(fcDesc.ShapeFieldName);
IField shapeField = fields.get_Field(shapeFieldIndex);
// Modify the GeometryDef object before using the fields collection to create a new feature class.
IGeometryDef geometryDef = shapeField.GeometryDef;
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
// Alter the feature class geometry type to lines (default is polygons).
geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
geometryDefEdit.HasM_2 = true;
geometryDefEdit.GridCount_2 = 1;
// Set the first grid size to zero and allow ArcGIS to determine a valid grid size.
geometryDefEdit.set_GridSize(0, 0);
geometryDefEdit.SpatialReference_2 = spatialReference;
// Because the fields collection already exists, the AddField method on the IFieldsEdit interface
// will be used to add a field that is not required to the fields collection.
IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
IField incomeField = new FieldClass();
IFieldEdit incomeFieldEdit = (IFieldEdit)incomeField;
// Create a user-defined double field.
incomeFieldEdit.AliasName_2 = "Average income for 1999-2000";
incomeFieldEdit.Editable_2 = true;
incomeFieldEdit.IsNullable_2 = false;
incomeFieldEdit.Name_2 = "average_income";
incomeFieldEdit.Precision_2 = 2;
incomeFieldEdit.Scale_2 = 5;
incomeFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldsEdit.AddField(incomeField);
return fields;
}
//为table创建fields
public IFields CreateFieldsCollectionForTable()
{
// Create a new fields collection.
IFields fields = new FieldsClass();
// Cast to IFieldsEdit to modify the properties of the fields collection.
IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
// Set the number of fields the collection will contain.
fieldsEdit.FieldCount_2 = 2;
// Create the ObjectID field.
IField idField = new FieldClass();
// Cast to IFieldEdit to modify the properties of the new field.
IFieldEdit idFieldEdit = (IFieldEdit)oidField;
oidFieldEdit.Name_2 = "ObjectID";
oidFieldEdit.AliasName_2 = "FID";
oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
// Add the new field to the fields collection.
fieldsEdit.set_Field(0, oidField);
// Create the text field.
IField textField = new FieldClass();
IFieldEdit textFieldEdit = (IFieldEdit)textField;
textFieldEdit.Length_2 = 30;
// Only string fields require that you set the length.
textFieldEdit.Name_2 = "Owner";
textFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
// Add the new field to the fields collection.
fieldsEdit.set_Field(1, textField);
return fields;
}
//向要素类添加fields字段
public void AddFieldToFeatureClass(IFeatureClass featureClass, IField field)
{
ISchemaLock schemaLock = (ISchemaLock)featureClass;
try
{
// A try block is necessary, as an exclusive lock may not be available.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
// Add the field.
featureClass.AddField(field);
}
catch (Exception exc)
{
// Handle this in a way appropriate to your application.
Console.WriteLine(exc.Message);
}
finally
{
// Set the lock to shared, whether or not an error occurred.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
}
}
分享到:
相关推荐
ArcGIS for Android 获取FeatureLayer的图例
ArcGIS for Android FeatureLayer的属性更新的简单例子
android arcgis featureLayer查询
使用arcgis可能常常遇到需要在属性表里添加非常多的字段,遇到这种情况很多人使用连接的方法来解决,但是当需要添加的图层比较多的时候,就十分麻烦,于是我就开发了这款arcgis工具箱。 工具箱有三个功能: 1.从已...
ArcGIS(ArcPy)脚本excel批量添加字段
本工具是一款可以根据excel填写的参数添加字段工具,只需在excel填好参数,在arcgis导入可以全自动添加,非常快速、方便。只要是添加字段的,他都可以哦!!!
好多用户对是否可以修改字段名称很感兴趣,也有一部分用户感兴趣要素类字段的显示顺序,因为在ArcGIS10.1版本之前,字段名称还没有办法修改,那么唯一的办法就是将原字段删除掉,然后添加新名称的字段,但是这会产生...
ArcGIS for Android 显示FeatureLayer的popup,可以查看博文http://blog.csdn.net/yifei1989/article/details/11579901
用“JDBC”连接数据库,arcgis for android 读取空间数据库。
Arcgis中利用python语言对shp文件批量添加字段,注释详细,只需更改shp文件所在文件夹路径,以及相关字段名称、类型、长度等设置即可
arcgisserver中gridview隐藏字段的重要代码
ARCGIS字段计算器对字段重复内容自动编号的方法;L=[ ] def aaa(x): global L L.append(x) return(L.count(x)) aaa(!TBBH!) 确
在ARCGIS属性表中增加需要的字段,并自动赋值2009-11-20 1打开属性表,选择计算的字段,右点选择Calculate Values;2.选择“是”,进入Field Calculator; 2选择Advance选项; 3 在Pre-Logic VBA Script Code编辑框中...
ARCGIS中土地利用代码赋值,更改部分参数,即可将此代码应用于if语句赋值的各种情景。
按shp属性字段分类拆分成多个独立shp文件
python编写,arcgis批量去除多个字段数据库中空格,arcgis工具箱形式
ARCGIS 必填字段检查 对所加载图层数据进行检查,根据字段约束要求,对必填字段进行检查。
通过Arcgis字段计算器,为新建字段自动编号,提供代码参考。
在使用ArcGIS10.2.1或10.2.2及10.3以上版本时,可能会出现中文字段名称被截断,不能超过3个汉字的问题。此工具可以自动识别arcgis版本并一键写入注册表,实现arcgis可以支持导出5个汉字的字段名的shp文件。
通过FeatureLayer和HeatmapRenderer渲染热力图,不需要依赖地图服务数据,通过变量往FeatureLayer上面添加点数据,下载后可直接在浏览器预览。