IPoilygon转IPoint
1 private void 河流面转点ToolStripMenuItem_Click(object sender, EventArgs e) 2 { 3 ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory(); 4 IWorkspace ws = wsf.OpenFromFile(@"F:\1-水利项目\安徽水利\0826处理", 0); 5 6 IFeatureClass autoStation = (ws as IFeatureWorkspace).OpenFeatureClass("淮河干流面"); 7 IFeatureClass f1 = (ws as IFeatureWorkspace).OpenFeatureClass("河道范围点"); 8 9 int num = autoStation.FeatureCount(null); 10 int k = 0; 11 string file = @"F:\1-水利项目\安徽水利\ANSL20120808\ANSL\OutPut\淮河干流\hedaopolygon.txt"; 12 if (File.Exists(file)) 13 { 14 File.Delete(file); 15 } 16 StreamWriter writer = new StreamWriter(file, true); 17 string strpt = ""; 18 for (int i = 0; i < num; i++) 19 { 20 IPolygon pg = autoStation.GetFeature(i).Shape as IPolygon; 21 22 IPointCollection ptc = pg as IPointCollection; 23 for (int j = 0; j < ptc.PointCount; j++) 24 { 25 IPoint pt = ptc.get_Point(j); 26 k++; 27 IFeature fea = f1.CreateFeature(); 28 fea.Shape = pt; 29 fea.set_Value(fea.Fields.FindField("Id"), k); 30 fea.set_Value(fea.Fields.FindField("longi"), pt.X); 31 fea.set_Value(fea.Fields.FindField("latit"), pt.Y); 32 fea.Store(); 33 34 strpt=strpt+pt.X+","+pt.Y+","+"0,"; 35 } 36 strpt = strpt + ptc.get_Point(0).X + "," + ptc.get_Point(0).Y + "," + "0,"; 37 } 38 writer.Write(strpt); 39 writer.Close(); 40 }
IPolygon转换为IPoint,且点的坐标值写入txt中。