AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素

简介:

原文 AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素

创建Shp文件

复制代码
/// <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();                
}
复制代码

 

官方的创建Shp文件的例子

复制代码
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(); }
复制代码

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。





  本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/5905389.html,如需转载请自行联系原作者



相关文章
|
5月前
|
存储 数据格式 Python
Python中arcpy栅格创建与遥感影像多景数据批量拼接Mosaic
Python中arcpy栅格创建与遥感影像多景数据批量拼接Mosaic
|
5月前
|
定位技术
ArcGIS中ArcMap创建渔网Create Fishnet:生成指定大小的格网矢量文件
ArcGIS中ArcMap创建渔网Create Fishnet:生成指定大小的格网矢量文件
|
5月前
|
存储 定位技术 计算机视觉
Python中ArcPy实现多张栅格遥感影像无效值NoData批量填充
Python中ArcPy实现多张栅格遥感影像无效值NoData批量填充
|
5月前
|
算法 定位技术 数据处理
C++中GDAL批量创建多个栅格图像文件并批量写入数据
C++中GDAL批量创建多个栅格图像文件并批量写入数据
|
5月前
|
定位技术
ArcGIS中ArcMap创建镶嵌数据集、导入栅格图像文件并修改像元数值范围的方法
ArcGIS中ArcMap创建镶嵌数据集、导入栅格图像文件并修改像元数值范围的方法
|
8月前
|
JSON 数据格式
使用Fiona创建Shapefile矢量数据
使用Fiona写入Shapefile数据,主要是构建一个Schema,然后将空间对象转为GeoJSON的形式进行写入。 这个Schema是一个字典结构,定义了Geometry的类型,属性字段的名称及其类型。
67 0
|
10月前
如何解决GEE导出影像的Nodata值在ArcGIS中无法正常显示?
如何解决GEE导出影像的Nodata值在ArcGIS中无法正常显示?
482 0
ArcMap转换shp坐标系
使用arcmap转换文件的坐标系
148 0
|
大数据 Python
matplotlib Basemap加载shp文件
matplotlib Basemap加载shp文件
117 0
|
文件存储
Shp文件格式之-dbf文件
GeoTools中处理Dbf文件、Dbf头信息组成、Dbf数据组装形式
1768 0