开发者社区> 橘子红了呐> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

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,如需转载请自行联系原作者



版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Java基础 ---- 随机数实现彩票模拟(不重复)
Java基础,利用随机数实现模拟彩票
49 0
[20180228]11g删除表空间的恢复2.txt
[20180228]11g删除表空间的恢复2.txt --//以前曾经做过利用传输表空间恢复数据库,连接如下: http://blog.itpub.net/267265/viewspace-2141174/ http://blog.
1017 0
通过java程序模拟实现地铁票价2+2=12
地铁票价在这周六开始就要上涨了,这几天做地铁明显感觉人比平常多了很多。大家也都在默默的等待这一刻的到来,尽管很不情愿,但是终究会来。 到时候肯定吐槽的人一抓一大把,毕竟一天上班4块的时代就要终结,一下子变成十几块,票价涨了,生活成本都在上涨,其它都没有变化,生活着实不容易啊。
701 0
3402
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载