public void createVoronoiDiagram(string layername) { try { Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = false; IFeatureClass pInputFeatureClass = ChkMarkPoint.getFeatureLayer(layername).FeatureClass; MessageBox.Show("Choose the Save File of Voronoi Diagram"); AutoChooseFile acf = new AutoChooseFile(); string saveFilePath = acf.saveFullPathName(); //CreateThiessenPolygons pCTP = new CreateThiessenPolygons(pInputFeatureClass, @"F:\Voronoi Land Cover\LC Voronoi.shp"); CreateThiessenPolygons pCTP = new CreateThiessenPolygons(pInputFeatureClass, @saveFilePath); pCTP.fields_to_copy = "ALL"; IGeoProcessorResult pGPR = gp.Execute(pCTP, null) as IGeoProcessorResult; for (int i = 0; i < gp.MessageCount; i++) { ChkMarkPoint.changeText(gp.GetMessage(i)); } //IFeatureClass pOutFeatureClass = gp.Open(pGPR.ReturnValue) as IFeatureClass; //IFeatureLayer pFeatureLayer = new FeatureLayerClass(); //pFeatureLayer.Name = "Voronoi"; //pFeatureLayer.FeatureClass = pOutFeatureClass; //ChkMarkPoint.Mapcontr.Map.AddLayer(pFeatureLayer as ILayer); //ChkMarkPoint.Mapcontr.Refresh(); } catch (System.Exception e) { ChkMarkPoint.changeText(e.Message); } }
//调用gp工具创建泰森多边形 public static void CreateThiessenPolygons(IFeatureLayer in_features, string out_feature_class, string workspacename, string extent) { //IAoInitialize m_AoInitialize = new AoInitializeClass(); //esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable; //licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo); ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.OverwriteOutput = true; gp.SetEnvironmentValue("workspace", workspacename); //gp.SetEnvironmentValue("extent", extent); ESRI.ArcGIS.AnalysisTools.CreateThiessenPolygons createthiessenpolygon = new CreateThiessenPolygons(); createthiessenpolygon.in_features = in_features; createthiessenpolygon.out_feature_class = out_feature_class; createthiessenpolygon.fields_to_copy = "ALL"; gp.Execute(createthiessenpolygon, null); string strMessage = ""; for (int i = 0; i < gp.MessageCount; i++) { strMessage += gp.GetMessage(i).ToString() + "\r\n"; } //MessageBox.Show(strMessage); }
private void button6_Click(object sender, EventArgs e) { Geoprocessor gp = new Geoprocessor(); gp.AddOutputsToMap = true; gp.OverwriteOutput = true; CreateThiessenPolygons ct = new CreateThiessenPolygons(); ILayer points = GetLayerByName(map, "public_library_shp"); IFeatureClass fc = (points as IFeatureLayer2).FeatureClass; ct.in_features = fc; ct.out_feature_class = output; ILayer bounds = GetLayerByName(map, "cty00_shp"); IEnvelope envelope = bounds.AreaOfInterest.Envelope; string envelopestr = string.Format("{0} {1} {2} {3}", envelope.XMin, envelope.YMax, envelope.XMax, envelope.YMin); gp.SetEnvironmentValue("Extent", envelopestr); gp.Execute(ct, null); AddJoin joined = new AddJoin(); joined.join_table = population; joined.in_layer_or_view = "trt00_shp"; joined.in_field = "STFID2"; joined.join_field = "GEO_ID"; joined.out_layer_or_view = output + @"\joinedoutput"; gp.Execute(joined, null); Intersect intersect = new Intersect(); intersect.in_features = "marketshare" + ";" + tracts; intersect.join_attributes = "ALL"; intersect.out_feature_class = output + @"\intersect"; gp.Execute(intersect, null); AddField addedfield = new AddField(); addedfield.in_table = "intersect"; addedfield.field_name = "field"; addedfield.field_type = "FLOAT"; gp.Execute(addedfield, null); AddJoin joined2 = new AddJoin(); joined2.join_table = population; joined2.in_layer_or_view = "intersect"; joined2.in_field = "STFID2"; joined2.join_field = "GEO_ID"; joined2.out_layer_or_view = output + @"\joinedoutput"; gp.Execute(joined2, null); CalculateField calc = new CalculateField(); calc.in_table = "intersect"; calc.field = "field"; calc.expression = "!population.P001001!*!intersect.Shape_Area!/!intersect_Area!"; gp.Execute(calc, null); Dissolve dissolved = new Dissolve(); dissolved.in_features = intersect; dissolved.statistics_fields = "field"; dissolved.out_feature_class = output + @"\dissolve"; gp.Execute(dissolved, null); }