博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
阅读量:6259 次
发布时间:2019-06-22

本文共 4387 字,大约阅读时间需要 14 分钟。

///         /// 创建多边形shp        ///         ///         ///         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中添加要素

///         /// 向多边形shp中添加要素        ///         /// 多边形        /// 多边形shp        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();                }

 

转载地址:http://gqqsa.baihongyu.com/

你可能感兴趣的文章
导出一个数据库中的表中的某一条数据
查看>>
JQuery初体验
查看>>
全球顶级黑客对决AI GeekPwn2017黑客大赛看点全面曝光
查看>>
浅析前端开发中的 MVC/MVP/MVVM 模式
查看>>
toString、equals和hashCode重写
查看>>
sizeof 和strlen的区别
查看>>
Python与C++引用分析
查看>>
误删一个用户 引起数据不准确问题
查看>>
一场失败的拔河比赛
查看>>
IOS开发工程师欢迎你加入宏略信息
查看>>
java 判断当前时间符合cron时间表达式
查看>>
Telnet协议的实现
查看>>
我的友情链接
查看>>
(一)指南一、初学者指南1、简介2、安装
查看>>
约瑟夫·奈:透视网络空间
查看>>
我的友情链接
查看>>
大数据入门基础:Hadoop简介
查看>>
jdk1.7新特性
查看>>
smarty 模板编译和变量调节器 模板引入
查看>>
一个小的运维管理平台
查看>>