AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
2016-08-19 15:04
465 查看
/// <summary> /// 创建多边形shp /// </summary> /// <param name="pPolygon"></param> /// <param name="shpPath"></param> public static void CreatePolygonFeatureClass(IPolygon pPolygon, string shpfolder,string shpname) { IWorkspaceFactory pWorkSpaceFac = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkSpace = pWorkSpaceFac.OpenFromFile(shpfolder,0) as IFeatureWorkspace; //创建字段集2 IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass(); IObjectClassDescription ocDescription = (IObjectClassDescription)fcDescription;//创建必要字段 IFields fields = ocDescription.RequiredFields; int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName); IField field = fields.get_Field(shapeFieldIndex); IGeometryDef geometryDef = field.GeometryDef; IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; //geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; //geometryDefEdit.SpatialReference_2 = spatialReference; geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; ISpatialReferenceFactory pSpatialRefFac = new SpatialReferenceEnvironmentClass(); IProjectedCoordinateSystem pcsSys = pSpatialRefFac.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_Zone_39); geometryDefEdit.SpatialReference_2 = pcsSys; IFieldChecker fieldChecker = new FieldCheckerClass(); IEnumFieldError enumFieldError = null; IFields validatedFields = null; //将传入字段 转成 validatedFields fieldChecker.ValidateWorkspace = (IWorkspace)pFeatureWorkSpace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); pFeatureWorkSpace.CreateFeatureClass(shpname, validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, ""); }
//删除shp
//如果已存在,那么删除 IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(shpname); if (pFCChecker != null) { IDataset pds = pFCChecker as IDataset; pds.Delete(); }
//向shp中添加要素
/// <summary> /// 向多边形shp中添加要素 /// </summary> /// <param name="pPolygon">多边形</param> /// <param name="pFeatureClass">多边形shp</param> public static void AddFeatureToFeatureClass(IPolygon pPolygon,IFeatureClass pFeatureClass) { IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = pPolygon; pFeature.Store(); }
//官方例子
public void IFeatureClass_CreateFeature_Example(IFeatureClass featureClass) { //Function is designed to work with polyline data if (featureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) { return; } //create a geometry for the features shape ESRI.ArcGIS.Geometry.IPolyline polyline = new ESRI.ArcGIS.Geometry.PolylineClass(); ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.X = 0; point.Y = 0; polyline.FromPoint = point; point = new ESRI.ArcGIS.Geometry.PointClass(); point.X = 10; point.Y = 10; polyline.ToPoint = point; IFeature feature = featureClass.CreateFeature(); //Apply the constructed shape to the new features shape feature.Shape = polyline; ISubtypes subtypes = (ISubtypes)featureClass; IRowSubtypes rowSubtypes = (IRowSubtypes)feature; if (subtypes.HasSubtype)// does the feature class have subtypes? { rowSubtypes.SubtypeCode = 1; //in this example 1 represents the Primary Pipeline subtype } // initalize any default values that the feature has rowSubtypes.InitDefaultValues(); //Commit the default values in the feature to the database feature.Store(); //update the value on a string field that indicates who installed the feature. feature.set_Value(feature.Fields.FindField("InstalledBy"), "K Johnston"); //Commit the updated values in the feature to the database feature.Store(); }
相关文章推荐
- AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
- AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
- AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
- 【20110420-01】AE中对现有FeatureClass添加字段的问题
- 添加SHP文件到SDE中指定FeatureClass中(方法一)
- 关于AE中IFeatureWorkspace接口的CreateFeatureClass方法
- 添加SHP文件到SDE中指定FeatureClass中(方法二)
- Arcgis Engine(ae)接口详解(3):featureClass的feature编辑和删除
- FeatureClass下创建要素(CreateFeature)遇到的一些问题及解决
- 创建shp文件并把feature添加到该shp文件中
- AE IFeatureClass导出SHP文件
- Code First Entity Framework基本与最佳添加(add/create),删除(delete/remove),修改(update/modify)操作
- c语言实现对传统单链表的创建、添加 遍历 删除 反转元素操作
- class_create(),class_device_create()或device_create()自动创建设备文件结点
- 查找删除Code First Entity Framework基本与最佳添加(add/create),删除(delete/remove),修改(update/modify)操作
- 【随笔记录】document.createElement创建添加属性
- 使用 SELECT 语句从表中取数据 创建新表 字段属性 向表中添加数据 删除
- SQL 创建表、 添加、删除列
- ArcEngine c# 创建shp图层,并将要素写入图层保存
- php中DOMDocument简单用法示例代码(XML创建、添加、删除、修改)