标签:创建 pac des enc pre 应该 sub cursor def
有一个将标注文件(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(); } }
还有一种思路应该比这个简单,正在~~~~~,记录一下
标签:创建 pac des enc pre 应该 sub cursor def
原文地址:https://www.cnblogs.com/clgis/p/9938714.html