public bool SetNoData(string inRaster, int excludeValue, string outRaster, out string msg) { msg = string.Empty; bool result = true; //IGeoDataset geoDataSet = null; IGeoProcessorResult geoProcessorResult = null; try { ESRI.ArcGIS.SpatialAnalystTools.SetNull setNull = new ESRI.ArcGIS.SpatialAnalystTools.SetNull(); //geoDataSet = EngineAPI.OpenRasterFile(inRaster) as IGeoDataset; setNull.in_conditional_raster = inRaster; setNull.in_false_raster_or_constant = inRaster; setNull.where_clause = "VALUE <> " + excludeValue; setNull.out_raster = outRaster; //geoProcessorResult = this.m_gp.Execute(setNull, null) as IGeoProcessorResult; //msg += GetGPMessages(this.m_gp); //Geoprocessor m_gp = new Geoprocessor() { OverwriteOutput = true }; geoProcessorResult = m_gp.Execute(setNull, null) as IGeoProcessorResult; msg += GetGPMessages(m_gp); if (geoProcessorResult.Status != esriJobStatus.esriJobSucceeded) { result = false; } return(result); } catch (Exception ex) { throw ex; } finally { Marshal.ReleaseComObject(geoProcessorResult); } }
public static IRaster SetNull(IRaster condition, IRaster falseRaster, string outputPath) { var geoprocessor = GeoprocessingUtility.GetGeoprocessor(); var setNullTool = new ESRI.ArcGIS.SpatialAnalystTools.SetNull(); setNullTool.in_conditional_raster = GeoprocessingUtility.GetGPRasterObject(condition); setNullTool.in_false_raster_or_constant = GeoprocessingUtility.GetGPRasterObject(falseRaster); setNullTool.out_raster = outputPath; string resultPath = GeoprocessingUtility.RunGpTool(geoprocessor, setNullTool) as string; IRaster outputRaster = GeoprocessingUtility.GetRasterFromPath(resultPath); GeoprocessingUtility.ResetGeoprocessor(); return(outputRaster); }