private void btnUygula_Click(object sender, EventArgs e) { if (cmbXColumn.SelectedIndex < 0) { MessageBox.Show("X değeri belirlenmeden işlem yapılamaz."); return; } if (cmbYColumn.SelectedIndex < 0) { MessageBox.Show("Y değeri belirlenmeden işlem yapılamaz."); return; } AppSingleton.Instance().CreateWorkspacePath(); var name = Path.GetFileNameWithoutExtension(txtExcel.Text); ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.ConversionTools.ExcelToTable excelToTable = new ESRI.ArcGIS.ConversionTools.ExcelToTable(); excelToTable.Input_Excel_File = txtExcel.Text; excelToTable.Output_Table = AppSingleton.Instance().WorkspacePath + "\\" + name; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(excelToTable, null); ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer makeLayer = new ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer(); makeLayer.table = excelToTable.Output_Table; makeLayer.in_x_field = cmbXColumn.SelectedItem.ToString(); makeLayer.in_y_field = cmbYColumn.SelectedItem.ToString(); makeLayer.out_layer = excelToTable.Output_Table + "_layer"; makeLayer.spatial_reference = "WGS 1984"; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(makeLayer, null); }
public string RasterCalculatorNKS(string nN, string nP, string Y, string S, string gS) { try { ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rasterCalculator = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); if (nP == "12") { rasterCalculator.expression = "('" + Y + "' * '" + nN + "' * 12) / ('" + S + "' * '" + gS + "' + 15 )"; } else { rasterCalculator.expression = "('" + Y + "' * '" + nN + "' * '" + nP + "') / ('" + S + "' * '" + gS + "' + 15)"; } ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); rasterCalculator.output_raster = AppSingleton.Instance().WorkspacePath + "\\nks"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(rasterCalculator, null); return(rasterCalculator.output_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
private bool PolygonToRaster(ILayer selectedLayer, string inputType, string valueField, string priorityField) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.ConversionTools.PolygonToRaster polygonToRaster = new ESRI.ArcGIS.ConversionTools.PolygonToRaster(); polygonToRaster.in_features = selectedLayer; polygonToRaster.value_field = valueField;//"distance"; polygonToRaster.out_rasterdataset = AppSingleton.Instance().WorkspacePath + "\\Poly_Raster_" + selectedLayer.Name; polygonToRaster.cell_assignment = "MAXIMUM_AREA"; polygonToRaster.cellsize = AppSingleton.Instance().CellSize; if (priorityField != "") { polygonToRaster.priority_field = priorityField; //"priority"; } IFeatureLayer fLayer = AppSingleton.Instance().SinirLayer as IFeatureLayer; IEnvelope env = fLayer.AreaOfInterest.Envelope; gp.SetEnvironmentValue("Extent", env.XMin.ToString() + " " + env.YMin.ToString() + " " + env.XMax.ToString() + " " + env.YMax.ToString()); gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(polygonToRaster, null); return(true); } catch (Exception ex) { return(false); } }
public string RasterClipLayer(object selectedLayer, IFeatureLayer sinirLayer, string outputName) { try { IFeatureWorkspace fWorkspace = AppSingleton.Instance().PersonalWorkspace as IFeatureWorkspace; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.SpatialAnalystTools.ExtractByRectangle rastClip = new ESRI.ArcGIS.SpatialAnalystTools.ExtractByRectangle(); rastClip.in_raster = selectedLayer;//Kriging rastClip.extraction_area = "INSIDE"; rastClip.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + outputName; IFeatureLayer fLayer = sinirLayer; IEnvelope env = fLayer.AreaOfInterest.Envelope; string geo = env.XMin.ToString() + " " + env.YMin.ToString() + " " + env.XMax.ToString() + " " + env.YMax.ToString(); rastClip.rectangle = geo; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(rastClip, null); return(rastClip.out_raster.ToString()); //return clip.out_feature_class.ToString(); } catch (Exception ex) { return(string.Empty); } }
private bool RasterClipLayer(ILayer selectedLayer, string type) { try { IFeatureWorkspace fWorkspace = AppSingleton.Instance().PersonalWorkspace as IFeatureWorkspace; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.SpatialAnalystTools.ExtractByRectangle rastClip = new ESRI.ArcGIS.SpatialAnalystTools.ExtractByRectangle(); rastClip.in_raster = AppSingleton.Instance().WorkspacePath + "\\" + selectedLayer.Name + "_" + type;//Kriging rastClip.extraction_area = "INSIDE"; rastClip.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + type + "Clip_" + selectedLayer.Name; IFeatureLayer fLayer = AppSingleton.Instance().SinirLayer as IFeatureLayer; IEnvelope env = fLayer.AreaOfInterest.Envelope; //<<<<<<< .mine //string geo = env.XMin.ToString() + " " + env.YMin.ToString() + " " + env.XMax.ToString() + " " + env.YMax.ToString(); // rastClip.clipping_geometry = geo; //======= string geo = env.XMin.ToString() + " " + env.YMin.ToString() + " " + env.XMax.ToString() + " " + env.YMax.ToString(); rastClip.rectangle = geo; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(rastClip, null); return(true); //return clip.out_feature_class.ToString(); } catch (Exception ex) { return(false); } }
private bool Reclassify(ILayer selectedLayer, string FieldName, string reclassMap, string inputType, string outputType) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.Analyst3DTools.Reclassify reclass = new ESRI.ArcGIS.Analyst3DTools.Reclassify(); reclass.in_raster = AppSingleton.Instance().WorkspacePath + "\\" + inputType + selectedLayer.Name; //RingBuffered_ reclass.reclass_field = FieldName; //"Value"; reclass.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + outputType + selectedLayer.Name; //Reclassified_ reclass.remap = reclassMap; // "50 1;50 100 2;100 150 3;NODATA 0"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(reclass, null); if (outputType == "Reclassified_") { reclassList.Add(reclass.out_raster.ToString()); } return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// 使用AE的GP工具实现图层到图层的转换 /// </summary> /// <param name="sourcePath">源数据路径,shape为全路径。数据库路径以mdb为例:C:\测试\test.mdb\zyxb</param> /// <param name="tarPath">源数据路径,shape为全路径。数据库路径以mdb为例:C:\测试\test.mdb\zyxbtar</param> /// <param name="msgLog"></param> /// <returns></returns> public static bool GPFeatToFeat(string sourcePath, string tarPath, string filter, out string msgLog) { msgLog = string.Empty; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); string out_path = tarPath.Substring(0, tarPath.LastIndexOf('\\')); string out_name = tarPath.Substring(tarPath.LastIndexOf('\\') + 1); try { //复制到更新小班图层 ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass pFeatToFeat1 = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass(); pFeatToFeat1.in_features = sourcePath; pFeatToFeat1.out_path = out_path; //zyxbFeatClass.Workspace.InnerObject as ESRI.ArcGIS.Geodatabase.IWorkspace; pFeatToFeat1.out_name = out_name; pFeatToFeat1.where_clause = filter; gp.Execute(pFeatToFeat1, null); if (!ReturnErrMessage(gp, ref msgLog)) { return(false); } } catch (Exception) { ReturnErrMessage(gp, ref msgLog); return(false); } finally { gp = null; } msgLog = ""; return(true); }
public static void ExportLayerToShapefile(string shapePath, string shapeName, ILayer source) { try { // cast the selected/requested layer into a feature layer ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (IFeatureLayer)source; // create a new feature class to feature class converter utility ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fc2fc = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass(); // set the input feature layer fc2fc.in_features = featureLayer; // set the output path and Shapefile name fc2fc.out_path = shapePath; fc2fc.out_name = shapeName + ".shp"; // create a new GeoProcessor ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); // execute the FeatureClassToFeatureClass geoprocessor.Execute(fc2fc, null); // export a copy of the layer file definition too for upload/style at a later time ESRI.ArcGIS.DataManagementTools.SaveToLayerFile saveToLayerFile = new ESRI.ArcGIS.DataManagementTools.SaveToLayerFile(); saveToLayerFile.in_layer = source; saveToLayerFile.out_layer = shapePath + "\\" + shapeName + ".lyr"; // execute the FeatureClassToFeatureClass geoprocessor.Execute(saveToLayerFile, null); } catch (Exception ex) { // an error occured System.Windows.Forms.MessageBox.Show("Error: " + ex.Message); } }
/// <summary> /// Runs the Calculate Statistics tool from ArcMap. /// </summary> /// <param name="pRDS"></param> private void CalcStats(IRasterDataset pRDS) { IGeoProcessorResult result = null; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.OverwriteOutput = true; gp.AddOutputsToMap = false; ESRI.ArcGIS.DataManagementTools.CalculateStatistics statTool = new ESRI.ArcGIS.DataManagementTools.CalculateStatistics(); statTool.in_raster_dataset = pRDS; result = (IGeoProcessorResult)gp.Execute(statTool, null); }
/// <param name="pFeatureClass1">相交要素1</param> /// <param name="pFeatureClass2">相交要素2</param> /// <param name="gdbPath">数据库路径</param> private IFeatureClass Intersect(IFeatureClass pFeatureClass1, IFeatureClass pFeatureClass2, string gdbPath) { IFeatureClass pOutFeatureClass = null; try { //调用GP ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.OverwriteOutput = true; //多个对象的输入:使用IGpValueTableObject接口,该接口可以设置 IGpValueTableObject vtobject = new GpValueTableObjectClass(); object pFeature1 = pFeatureClass1; object pFeature2 = pFeatureClass2; vtobject.SetColumns(2); vtobject.AddRow(ref pFeature1); vtobject.AddRow(ref pFeature2); ESRI.ArcGIS.AnalysisTools.Intersect pIntersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); pIntersect.in_features = vtobject; pIntersect.out_feature_class = System.Environment.CurrentDirectory + @"\temp\" + "temp.shp"; pIntersect.output_type = "Input"; IGeoProcessorResult2 result = (IGeoProcessorResult2)gp.Execute(pIntersect, null); if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) { MessageBox.Show("操作失败!"); return(null); } else { //获取结果; IFeatureClass resultFClass = gp.Open(result.ReturnValue) as IFeatureClass; IDataset pDataset = resultFClass as IDataset; //目标数据库; IWorkspaceFactory factory = new FileGDBWorkspaceFactoryClass(); IWorkspace objectWorkspace = factory.OpenFromFile(gdbPath, 0); string fileName = pFeatureClass1.AliasName + "_" + pFeatureClass2.AliasName; pOutFeatureClass = IFeatureDataConverter_ConvertFeatureClass(pDataset.Workspace, objectWorkspace, pDataset.Name, fileName); } } catch (System.Exception ex) { MessageBox.Show("操作失败!"); return(null); } return(pOutFeatureClass); }
private string InterSect(string flayer, string kadastroLayer) { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); intersect.in_features = flayer + ";" + kadastroLayer; intersect.out_feature_class = AppSingleton.Instance().WorkspacePath + "\\Final"; intersect.join_attributes = "All"; intersect.output_type = "INPUT"; gp.AddOutputsToMap = true; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(intersect, null); return(intersect.out_feature_class.ToString()); }
private string RasterToPolygon(object rasterlayer) { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.ConversionTools.RasterToPolygon rasterToPolygon = new ESRI.ArcGIS.ConversionTools.RasterToPolygon(); rasterToPolygon.in_raster = rasterlayer; rasterToPolygon.out_polygon_features = AppSingleton.Instance().WorkspacePath + "\\RasterToPolygon"; rasterToPolygon.simplify = "SIMPLIFY"; rasterToPolygon.raster_field = "Value"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(rasterToPolygon, null); return(rasterToPolygon.out_polygon_features.ToString()); }
public string RasterCalculatorKKS(string nKS) { try { ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rasterCalculator = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); rasterCalculator.expression = "1 / '" + nKS + "'"; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); rasterCalculator.output_raster = AppSingleton.Instance().WorkspacePath + "\\kks"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(rasterCalculator, null); return(rasterCalculator.output_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
private bool Combine(string layerNames) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.SpatialAnalystTools.Combine combine = new ESRI.ArcGIS.SpatialAnalystTools.Combine(); combine.in_rasters = layerNames; combine.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + "Ekolojik_Sit_Alani"; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(combine, null); return(true); } catch (Exception ex) { return(false); } }
public string RasterCalculatorYillik(string P, string T, string layerName) { try { ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rasterCalculator = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); rasterCalculator.expression = "'" + P + "'/('" + T + "' + 10)"; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); rasterCalculator.output_raster = AppSingleton.Instance().WorkspacePath + "\\" + layerName; gp.AddOutputsToMap = true;//AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(rasterCalculator, null); return(rasterCalculator.output_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
public string Int(string layerName, string outName) { try { ESRI.ArcGIS.SpatialAnalystTools.Int intRaster = new ESRI.ArcGIS.SpatialAnalystTools.Int(); intRaster.in_raster_or_constant = layerName; intRaster.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + outName; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(intRaster, null); return(intRaster.out_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
private string CopyFeatureClass(object featureClass) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.DataManagementTools.CopyFeatures copyFeatures = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(); copyFeatures.in_features = featureClass; copyFeatures.out_feature_class = AppSingleton.Instance().WorkspacePath + "\\" + "Copy"; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(copyFeatures, null); return(copyFeatures.out_feature_class.ToString()); } catch (Exception ex) { return(string.Empty); } }
public string RasterCalculatorKi(string d, string etp, string layerName) { try { ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rasterCalculator = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator(); rasterCalculator.expression = "((100 * '" + d + "') / '" + etp + "')*10"; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); rasterCalculator.output_raster = AppSingleton.Instance().WorkspacePath + "\\" + layerName; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(rasterCalculator, null); return(rasterCalculator.output_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
private string Combine(string layerNames, string outLayerName) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.SpatialAnalystTools.Combine combine = new ESRI.ArcGIS.SpatialAnalystTools.Combine(); combine.in_rasters = layerNames; combine.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + outLayerName; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(combine, null); return(combine.out_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
public static void ExportLayerToUploadableRaster(string outputFilePath, string name, ILayer source) { try { // cast the selected/requested layer into a raster layer ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = (IRasterLayer)source; // create a new raster to raster converter utility ESRI.ArcGIS.DataManagementTools.CopyRaster raster2raster = new ESRI.ArcGIS.DataManagementTools.CopyRaster(); // set the input raster layer raster2raster.in_raster = rasterLayer; // set the output path and Shapefile name /* The name and location of the raster dataset to be created. * .bil—Esri BIL * .bip—Esri BIP * .bmp—BMP * .bsq—Esri BSQ * .dat—ENVI DAT * .gif—GIF * .img—ERDAS IMAGINE * .jpg—JPEG * .jp2—JPEG 2000 * .png—PNG * .tif—TIFF * no extension for Esri Grid */ raster2raster.out_rasterdataset = outputFilePath + "\\" + name + ".tif"; // create a new GeoProcessor ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); // execute the RasterToOtherFormat geoprocessor.Execute(raster2raster, null); } catch (Exception ex) { // an error occured System.Windows.Forms.MessageBox.Show("Error: " + ex.Message); } }
public IRasterCatalog CreateRasterCat(string name, string sdePath) { ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); CreateRasterCatalog createRasterCatalog = new CreateRasterCatalog(); IGPCoordinateSystem rSR = new GPCoordinateSystemClass(); IGPSpatialReference gSR = new GPSpatialReferenceClass(); rSR.SpatialReference = new UnknownCoordinateSystemClass(); gSR.SpatialReference = new UnknownCoordinateSystemClass(); createRasterCatalog.out_path = sdePath; createRasterCatalog.out_name = name; createRasterCatalog.raster_spatial_reference = (object)rSR; createRasterCatalog.spatial_reference = (object)gSR; geoProcessor.Execute(createRasterCatalog, null); IRasterCatalog rastercat = ((IRasterWorkspaceEx)this.m_workSpace).OpenRasterCatalog(name); return(rastercat); }
private string Divide(string yagisLayer, string sicaklikLayer) { try { ESRI.ArcGIS.SpatialAnalystTools.Divide divide = new ESRI.ArcGIS.SpatialAnalystTools.Divide(); divide.in_raster_or_constant1 = yagisLayer; divide.in_raster_or_constant2 = sicaklikLayer; divide.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + "sonucLayer"; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(divide, null); return(divide.out_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
private bool JoinField(object table, string inField, string joinTable, string joinField) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.DataManagementTools.JoinField join = new ESRI.ArcGIS.DataManagementTools.JoinField(); join.in_data = table; join.in_field = inField; join.join_table = joinTable; join.join_field = joinField; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(join, null); return(true); } catch (Exception ex) { return(false); } }
private bool ClipLayers(ILayer selectedLayer) { try { IFeatureWorkspace fWorkspace = AppSingleton.Instance().PersonalWorkspace as IFeatureWorkspace; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.AnalysisTools.Clip clip = new ESRI.ArcGIS.AnalysisTools.Clip(); clip.in_features = selectedLayer; clip.clip_features = AppSingleton.Instance().SinirLayer; clip.out_feature_class = AppSingleton.Instance().WorkspacePath + "\\Clip_" + selectedLayer.Name; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(clip, null); //return clip.out_feature_class.ToString(); return(true); } catch (Exception ex) { return(false); } }
private bool CreateTin(ILayer selectedLayer, EnterpoleGrid grid) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.Analyst3DTools.CreateTin createTin = new ESRI.ArcGIS.Analyst3DTools.CreateTin(); createTin.out_tin = AppSingleton.Instance().Path + "\\TIN_" + selectedLayer.Name; //RingBuffered_ //erdinç createTin.in_features = AppSingleton.Instance().WorkspacePath + "\\Clip_" + selectedLayer.Name + " " + grid.FieldName + " hardline <None>"; // 10.1 Hard_Line ; 10.0 hardline createTin.constrained_delaunay = "DELAUNAY"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(createTin, null); return(true); } catch (Exception ex) { return(false); } }
private bool Reclassify(string selectedLayer) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.SpatialAnalystTools.Reclassify reclass = new ESRI.ArcGIS.SpatialAnalystTools.Reclassify(); reclass.in_raster = selectedLayer;//RingBuffered_ reclass.reclass_field = "Value"; reclass.out_raster = AppSingleton.Instance().WorkspacePath + "\\Reclassifiedlayer"; reclass.remap = "0 8 1;8 15 2;15 23 3;23 40 4;40 55 5;55 10000 6;NODATA 0"; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(reclass, null); return(true); } catch (Exception ex) { return(false); } }
private bool CalculateField(ILayer selectedLayer) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.DataManagementTools.CalculateField calculateField = new ESRI.ArcGIS.DataManagementTools.CalculateField(); calculateField.in_table = AppSingleton.Instance().WorkspacePath + "\\RingBuffered_" + selectedLayer.Name; calculateField.field = "priority"; calculateField.expression = "1/Sqr ( [distance] )"; calculateField.expression_type = "VB"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(calculateField, null); return(true); } catch (Exception ex) { return(false); } }
private bool RingBuffer(ILayer selectedLayer, string distances) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer ringBuffer = new ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer(); ringBuffer.Input_Features = AppSingleton.Instance().WorkspacePath + "\\Clip_" + selectedLayer.Name; ringBuffer.Output_Feature_class = AppSingleton.Instance().WorkspacePath + "\\RingBuffered_" + selectedLayer.Name; ringBuffer.Distances = distances;//"50;100;150"; ringBuffer.Buffer_Unit = "Meters"; ringBuffer.Dissolve_Option = "NONE"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(ringBuffer, null); return(true); } catch (Exception ex) { return(false); } }
private bool AddField(ILayer selectedLayer, string fieldName, string type) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField(); addField.in_table = AppSingleton.Instance().WorkspacePath + "\\" + type + selectedLayer.Name; addField.field_name = fieldName; addField.field_type = "DOUBLE"; addField.field_is_nullable = "NULLABLE"; addField.field_is_required = "NON_REQUIRED"; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(addField, null); return(true); } catch (Exception ex) { return(false); } }
private string IDW(ILayer selectedLayer, string FieldName) { try { ESRI.ArcGIS.SpatialAnalystTools.Idw idw = new ESRI.ArcGIS.SpatialAnalystTools.Idw(); idw.cell_size = AppSingleton.Instance().CellSize; idw.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + selectedLayer.Name + "_IDW_" + FieldName; idw.in_point_features = selectedLayer; idw.z_field = FieldName; idw.power = 3; idw.search_radius = AppSingleton.Instance().IDWYaricap; ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(idw, null); return(idw.out_raster.ToString()); } catch (Exception ex) { return(string.Empty); } }
private IFeatureLayer DissolveLineLayer(IFeatureLayer InFeatureLayer) { try{ ITable dissolveTable = (ITable)InFeatureLayer; IDataset dataset = (IDataset)InFeatureLayer; ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.DataManagementTools.Dissolve d = new ESRI.ArcGIS.DataManagementTools.Dissolve(); d.in_features = dissolveTable; d.out_feature_class = System.IO.Path.Combine(dataset.Workspace.PathName, "doodie"); d.dissolve_field = "SHAPE"; //d.statistics_fields = ""; d.multi_part = "MULTI_PART"; geoprocessor.Execute(d, null); return d.out_feature_class as IFeatureLayer ; //ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); //ESRI.ArcGIS.DataManagementTools.Dissolve d = new ESRI.ArcGIS.DataManagementTools.Dissolve(); //ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Result; //IFeatureLayer pOutFeatureLayer = new FeatureLayer(); //try //{ // geoprocessor.AddOutputsToMap = false; // geoprocessor.OverwriteOutput = true; // d.in_features = InFeatureLayer.Name ; // d.dissolve_field = InFeatureLayer.FeatureClass.ShapeFieldName; // d.out_feature_class = "Dissolve"; // Result = geoprocessor.Execute(d, null) as IGeoProcessorResult; // pOutFeatureLayer.FeatureClass = geoprocessor.Open("Dissolve") as IFeatureClass; // return pOutFeatureLayer; //IFeatureLayer OutFeatureLayer = new FeatureLayer(); //IGxCatalogDefaultDatabase Defaultgdb = ArcMap.Application as IGxCatalogDefaultDatabase; //string g = Defaultgdb.DefaultDatabaseName.PathName; //ITable dissolveTable = (ITable)InFeatureLayer; //IDataset dataset = (IDataset)InFeatureLayer; //ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); //ESRI.ArcGIS.DataManagementTools.Dissolve d = new ESRI.ArcGIS.DataManagementTools.Dissolve(); //d.in_features = dissolveTable; //d.out_feature_class = Defaultgdb.DefaultDatabaseName.PathName + "\\diss"; //d.dissolve_field = InFeatureLayer.FeatureClass.ShapeFieldName; ////d.statistics_fields = ""; ////d.multi_part = "MULTI_PART"; //geoprocessor.Execute(d, null); //OutFeatureLayer.FeatureClass = d.out_feature_class as IFeatureClass; //return OutFeatureLayer; ////return d.out_feature_class as IFeatureClass; } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); return null; } }
/// <summary> /// Run the Geoprocessing model /// </summary> /// <param name="modelParametersHybridDictionary">A HybridDictionary that contains all of the arguments to run the model</param> /// <returns>A message of how well the model executed</returns> /// <remarks></remarks> public static System.String ExecuteCustomGeoprocessingFunction(System.Collections.Specialized.HybridDictionary modelParametersHybridDictionary) { try { // Create a Geoprocessor object ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); // Set the OverwriteOutput setting to True gp.OverwriteOutput = true; // Create a new instance of our custom model MYCUSTOMTOOLBOX.GolfFinder myModel = new MYCUSTOMTOOLBOX.GolfFinder(); // Set the custom models parameters. myModel.BufferDistance = modelParametersHybridDictionary["BufferDistance"]; myModel.AIRPORT = modelParametersHybridDictionary["Airports"]; myModel.GOLF = modelParametersHybridDictionary["Golf"]; myModel.AirportBuffer = modelParametersHybridDictionary["AirportBuffer"]; myModel.Golf_Courses_Near_Airports = modelParametersHybridDictionary["GolfNearAirports"]; // Execute the model and obtain the result from the run ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult geoProcessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(myModel, null); if (geoProcessorResult == null) { // We have an error running the model. // If the run fails a Nothing (VB.NET) or null (C#) is returned from the gp.Execute object sev = 2; string messages = gp.GetMessages(ref sev); return messages; } else { // The model completed successfully return "Output successful. The shapefiles are locacted at: " + geoProcessorResult.ReturnValue.ToString(); } } catch (Exception ex) { // Catch any other errors return "Error running the model. Debug the application and test again."; } }
public IRasterCatalog CreateRasterCat(string name, string sdePath) { ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); CreateRasterCatalog createRasterCatalog = new CreateRasterCatalog(); IGPCoordinateSystem rSR = new GPCoordinateSystemClass(); IGPSpatialReference gSR = new GPSpatialReferenceClass(); rSR.SpatialReference = new UnknownCoordinateSystemClass(); gSR.SpatialReference = new UnknownCoordinateSystemClass(); createRasterCatalog.out_path = sdePath; createRasterCatalog.out_name = name; createRasterCatalog.raster_spatial_reference = (object)rSR; createRasterCatalog.spatial_reference = (object)gSR; geoProcessor.Execute(createRasterCatalog, null); IRasterCatalog rastercat = ((IRasterWorkspaceEx)this.m_workSpace).OpenRasterCatalog(name); return rastercat; }
public bool AppendTable(string InTable, string TargetTable, bool Messages = false) { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.OverwriteOutput = true; IGeoProcessorResult myresult = new GeoProcessorResultClass(); // Create a variant array to hold the parameter values. IVariantArray parameters = new VarArrayClass(); // Populate the variant array with parameter values. parameters.Add(InTable); parameters.Add(TargetTable); // Execute the tool. Note this only works with geodatabase tables. try { myresult = (IGeoProcessorResult)gp.Execute("Append_management", parameters, null); // Wait until the execution completes. while (myresult.Status == esriJobStatus.esriJobExecuting) Thread.Sleep(1000); // Wait for 1 second. if (Messages) { MessageBox.Show("Process complete"); } gp = null; return true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); gp = null; return false; } }
public bool CopyFeatures(string InFeatureClass, string OutFeatureClass, bool Messages = false) { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.OverwriteOutput = true; IGeoProcessorResult myresult = new GeoProcessorResultClass(); object sev = null; // Create a variant array to hold the parameter values. IVariantArray parameters = new VarArrayClass(); // Populate the variant array with parameter values. parameters.Add(InFeatureClass); parameters.Add(OutFeatureClass); // Execute the tool. try { myresult = (IGeoProcessorResult)gp.Execute("CopyFeatures_management", parameters, null); // Wait until the execution completes. while (myresult.Status == esriJobStatus.esriJobExecuting) Thread.Sleep(1000); // Wait for 1 second. if (Messages) { MessageBox.Show("Process complete"); } gp = null; return true; } catch (Exception ex) { if (Messages) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(gp.GetMessages(ref sev)); } gp = null; return false; } }
public bool CopyTable(string InTable, string OutTable, bool Messages = false) { // This works absolutely fine for dbf and geodatabase but does not export to CSV. // Note the csv export already removes ghe geometry field; in this case it is not necessary to check again. ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.OverwriteOutput = true; IGeoProcessorResult myresult = new GeoProcessorResultClass(); // Create a variant array to hold the parameter values. IVariantArray parameters = new VarArrayClass(); // Populate the variant array with parameter values. parameters.Add(InTable); parameters.Add(OutTable); // Execute the tool. try { myresult = (IGeoProcessorResult)gp.Execute("CopyRows_management", parameters, null); // Wait until the execution completes. while (myresult.Status == esriJobStatus.esriJobExecuting) Thread.Sleep(1000); // Wait for 1 second. if (Messages) { MessageBox.Show("Process complete"); } gp = null; return true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); gp = null; return false; } }