/// <summary> /// Calultes std using spatial analyst focal statistics for each raster band within a specified neighborhood (square). Naming convention is std_bandNumber /// </summary> /// <param name="inputRstPath">can be a IRaster IRasterDataset or string path to a raster</param> /// <param name="numCellsWide"> number of cells wide</param> /// <returns>a string of all geoprocessing messages</returns> public string calcBandSpatialVariation(object inputRstPath, int numCellsWide) { StringBuilder sb = new StringBuilder(); try { gp.OverwriteOutput = true; IRasterDataset rsDset = null; string rsPath = null; if (inputRstPath is string) { rsPath = inputRstPath.ToString(); string bnd = ""; rsDset = rsUtil.openRasterDataset(rsPath, out bnd); } else if (inputRstPath is IRasterDataset) { rsDset = (IRasterDataset)inputRstPath; IDataset dSet = (IDataset)rsDset; rsPath = dSet.Workspace.PathName + "\\" + dSet.BrowseName; } else if (inputRstPath is IRaster2) { rsDset = ((IRaster2)inputRstPath).RasterDataset; IDataset dSet = (IDataset)rsDset; rsPath = dSet.Workspace.PathName + "\\" + dSet.BrowseName; } else { string x = "Not a string, RasterDataset, or Raster"; Console.WriteLine(x); return(x); } IRasterBandCollection rsBndColl = (IRasterBandCollection)rsDset; int bndCnt = rsBndColl.Count; for (int cnt = 0; cnt < bndCnt; cnt++) { IRaster rst = rsUtil.returnRaster(rsUtil.getBand(inputRstPath, cnt)); string outRstPath = System.IO.Path.GetDirectoryName(rsPath) + "\\std_" + (cnt + 1).ToString(); IGPSANeighborhood nbr = new GPSANeighborhoodClass(); double cells = System.Convert.ToDouble(numCellsWide); nbr.SetRectangle(cells, cells, esriGeoAnalysisUnitsEnum.esriUnitsCells); IGeoProcessorResult rslt = focalRaster(rst, nbr, statType.STD, "std_" + cnt.ToString()); sb.Append(getMessages(rslt)); } } catch (Exception e) { sb.Append(e.ToString()); Console.WriteLine(e.ToString()); } return(sb.ToString()); }
/// <summary> /// Calultes std using spatial analyst focal statistics for each raster band within a specified neighborhood (square). Naming convention is std_bandNumber /// </summary> /// <param name="inputRstPath">can be a IRaster IRasterDataset or string path to a raster</param> /// <param name="numCellsWide"> number of cells wide</param> /// <returns>a string of all geoprocessing messages</returns> public string calcBandSpatialVariation(object inputRstPath, int numCellsWide) { StringBuilder sb = new StringBuilder(); try { gp.OverwriteOutput = true; IRasterDataset rsDset = null; string rsPath = null; if (inputRstPath is string) { rsPath = inputRstPath.ToString(); string bnd = ""; rsDset = rsUtil.openRasterDataset(rsPath,out bnd); } else if (inputRstPath is IRasterDataset) { rsDset = (IRasterDataset)inputRstPath; IDataset dSet = (IDataset)rsDset; rsPath = dSet.Workspace.PathName + "\\" + dSet.BrowseName; } else if (inputRstPath is IRaster2) { rsDset = ((IRaster2)inputRstPath).RasterDataset; IDataset dSet = (IDataset)rsDset; rsPath = dSet.Workspace.PathName + "\\" + dSet.BrowseName; } else { string x = "Not a string, RasterDataset, or Raster"; Console.WriteLine(x); return x; } IRasterBandCollection rsBndColl = (IRasterBandCollection)rsDset; int bndCnt = rsBndColl.Count; for (int cnt = 0; cnt < bndCnt; cnt++) { IRaster rst = rsUtil.returnRaster(rsUtil.getBand(inputRstPath, cnt)); string outRstPath = System.IO.Path.GetDirectoryName(rsPath) + "\\std_" + (cnt + 1).ToString(); IGPSANeighborhood nbr = new GPSANeighborhoodClass(); double cells = System.Convert.ToDouble(numCellsWide); nbr.SetRectangle(cells, cells, esriGeoAnalysisUnitsEnum.esriUnitsCells); IGeoProcessorResult rslt = focalRaster(rst, nbr, statType.STD, "std_" + cnt.ToString()); sb.Append(getMessages(rslt)); } } catch (Exception e) { sb.Append(e.ToString()); Console.WriteLine(e.ToString()); } return sb.ToString(); }