arcengine要素转点文件

有一个将标注文件(Annotation)以重心转换为点文件的任务,方法一:要素转点

public void FeatureToPointCollection(IMap pMap)
        {
            IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature pFeature = pFeatureCursor.NextFeature();
            IPointCollection pPointCollection = new MultipointClass();
            object o = Type.Missing;
            while (pFeature != null)
            {
                IGeometry pGeometry = pFeature.Shape;
                IArea pArea = pGeometry as IArea;
                IPoint pPoint = pArea.Centroid;
                pPointCollection.AddPoint(pPoint, ref o, ref o);
                pFeature = pFeatureCursor.NextFeature();
            }
            IGeoDataset pGeoDataset = pFeatureLayer as IGeoDataset;
            ISpatialReferenceFactory pSRFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
            PointCollToShpFile(pPointCollection, "C:/Users/Administrator/Desktop/testfolder/test.shp", pSpatialReference);
        }
public IFeatureLayer PointCollToShpFile(IPointCollection pPointCollection, string filePath, ISpatialReference pReference)
        {
            //利用IWorkspaceFactory打开工作空间
            int index = filePath.LastIndexOf('/');
            string folder = filePath.Substring(0, index);
            string shapeName = filePath.Substring(index + 1);
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(folder, 0);

            //创建字段编辑所需要的接口
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit;
            pFieldsEdit = (IFieldsEdit)pFields;

            //给字段属性、类型赋值
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef pGeometryDef = new GeometryDefClass();
            IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef;
            pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            //设置坐标系
            pGDefEdit.SpatialReference_2 = pReference;

            pFieldEdit.GeometryDef_2 = pGeometryDef;
            pFieldsEdit.AddField(pField);

            IFeatureClass pFeatureClass;
            pFeatureClass = pFWS.CreateFeatureClass(shapeName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            IPoint pPoint = new PointClass();
            for (int j = 0; j < pPointCollection.PointCount; j++)
            {
                pPoint = pPointCollection.get_Point(j);
                IFeature pFeature = pFeatureClass.CreateFeature();
                pFeature.Shape = pPoint;
                pFeature.Store();
            }
        }

还有一种思路应该比这个简单,正在~~~~~,记录一下

转载于:https://www.cnblogs.com/clgis/p/9938714.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值