/// <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中添加要素的更多相关文章

  1. Unity3D 中的面向对象设计 {游戏对象(创建、删除、获取),以及添加修改组件}

    一.创建游戏对象 游戏对象分三种:(1) 将物体模型等资源由Project工程面板拖拽到Hierarchy层次面板中 (2) 由GameObject菜单创建Unity自带的游戏对象,如Cube.Cam ...

  2. C++、GDAL创建shapefile,并向矢量文件中添加网格

    //总体来说这个过程就是构建数据源->构建层->构建要素->构建形状->关闭数据源. //要包含的GDAL头文件 #include <gdal_priv.h> #i ...

  3. ①创建项目testpackage ②在pack2.B中添加方法f ③在类A中添加如下三个成员变量:int型的私有变量i float型的变量f double型的公有变量d 在pack1.B的main方法中为对象a的成员变量f和d分别赋值为2和3 在pack2.C的main方法中为对象a的成员变量d赋值为3

    package pack1; public class A { private int i; float f; public double d; public float getF() { retur ...

  4. linux下软、硬链接的创建和删除

    linux下软.硬链接的创建和删除 在Linux系统中,内核为每一个新创建的文件分配一个Inode(索引结点),每个文件都有一个惟一的inode号.文件属性保存在索引结点里,在访问文件时,索引结点被复 ...

  5. Arcgis engine 指定图层对要素进行创建、删除等操作

    Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...

  6. SQLServer触发器创建、删除、修改、查看

    一: 触发器是一种特殊的存储过程﹐它不能被显式地调用﹐而是在往表中插入记录﹑更新记录或者删除记录时被自动地激活.所以触发器可以用来实现对表实施复杂的完整性约束. 二: SQL Server为每个触发器 ...

  7. linux命令 - ln - 创建和删除软、硬链接

    linux命令 - ln - 创建和删除软.硬链接 在Linux系统中,内核为每一个新创建的文件分配一个Inode(索引结点),每个文件都有一个惟一的inode号.文件属性保存在索引结点里,在访问文件 ...

  8. Java集合-5. (List)已知有一个Worker 类如下: 完成下面的要求 1) 创建一个List,在List 中增加三个工人,基本信息如下: 姓名 年龄 工资 zhang3 18 3000 li4 25 3500 wang5 22 3200 2) 在li4 之前插入一个工人,信息为:姓名:zhao6,年龄:24,工资3300 3) 删除wang5 的信息 4) 利用for 循

    第六题 5. (List)已知有一个Worker 类如下: public class Worker { private int age; private String name; private do ...

  9. 各种隐藏 WebShell、创建、删除畸形目录、特殊文件名、黑帽SEO作弊(转自核大大)

    其实这个问题,经常有朋友问我,我也都帮大家解决了…… 但是现在这些现象越来越严重,而且手法毒辣.隐蔽.变态,清除了又来了,删掉了又恢复了,最后直接找不到文件了,但是访问网站还在,急的各大管理员.站长抓 ...

随机推荐

  1. php正则表达式总结第1弹

    介绍几个我用到的php正则表达式 1. 一篇文章的链接,我需要去掉以 /hotels/打头的链接,可用下面正则 $content = preg_replace('/<a(.*?)href=&qu ...

  2. composer安装yii2或者laravel报错

    大概的信息就是提示让登陆github,然后就报错了 Could not fetch https://api.github.com/authorizations, enter your GitHub c ...

  3. Webserver issues | PHP manager for IIS

    4 down vote accepted In order to successfully install the PHP manager for IIS 8, you need the .NET 3 ...

  4. Repeat Header / Keep Header Visible in Tables in RS 2008

    You selected "Repeat header rows on each page" or "Keep header rows visible while scr ...

  5. Configure Database Mirroring

    使用证书配置的镜像基本安装微软次序做就可以了 http://msdn.microsoft.com/zh-cn/library/ms191140.aspx 备份还原首先要转换成完全备份模式没什么好多说的 ...

  6. HDFS命令行操作

    启动后可通过命令行使用hadoop. (1)所有命令 (先将$HADOOP_HOME/bin加入到.bashrc的$PATH变量中) [html] view plaincopy [hadoop@nod ...

  7. oracle中的loop与while循环

    Oracle中loop语句会先执行一次循环,然后再判断“exit when”关键字后面的条件表达式的值是true还是false,如果是true,那么将退出循环,否则继续循环. LOOP循环 语法如下l ...

  8. iOS中的堆(heap)和栈(stack)的理解

    操作系统iOS 中应用程序使用的计算机内存不是统一分配空间,运行代码使用的空间在三个不同的内存区域,分成三个段:“text segment “,“stack segment ”,“heap segme ...

  9. php 彩票类 lottery

    <?php /* * For the full copyright and license information, please view the LICENSE * file that wa ...

  10. 我的cnblogs设置代码

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...