private void doParalellpiped() { int iNX, iNY; int x, y; int iMatchingClass = 0; int iClass, iGrid; final double dMean[][] = new double[m_Classes.size()][m_Window.length]; final double dStdDev[][] = new double[m_Classes.size()][m_Window.length]; double dValue; ArrayList stats; MeanAndStdDev substats; Set set; Iterator iter; iNX = m_Output.getWindowGridExtent().getNX(); iNY = m_Output.getWindowGridExtent().getNY(); set = m_Classes.keySet(); iter = set.iterator(); iClass = 0; while (iter.hasNext()) { stats = (ArrayList) m_Classes.get(iter.next()); for (iGrid = 0; iGrid < m_Window.length; iGrid++) { substats = ((MeanAndStdDev) stats.get(iGrid)); dMean[iClass][iGrid] = substats.mean; dStdDev[iClass][iGrid] = substats.stdDev; } iClass++; } for (y = 0; y < iNY; y++) { for (x = 0; x < iNX; x++) { for (iClass = 0; iClass < m_Classes.size(); iClass++) { iMatchingClass = iClass; for (iGrid = 0; iGrid < m_Window.length; iGrid++) { dValue = m_Window[iGrid].getCellValueAsDouble(x, y); if (!m_Window[iGrid].isNoDataValue(dValue)) { if (Math.abs(m_Window[iGrid].getCellValueAsDouble(x, y) - dMean[iClass][iGrid]) > dStdDev[iClass][iGrid]) { iMatchingClass = -1; break; } } else { break; } } if (iMatchingClass != -1) { break; } } if (iMatchingClass != -1) { m_Output.setCellValue(x, y, iMatchingClass + 1); } else { m_Output.setNoData(x, y); } } } }
private void doMinimumDistance() { int iNX, iNY; int x, y; int iClass, iGrid, iMin = 0; final double dMean[][] = new double[m_Classes.size()][m_Window.length]; double dMin, d, e; double dValue; ArrayList stats; Set set; Iterator iter; iNX = m_Output.getWindowGridExtent().getNX(); iNY = m_Output.getWindowGridExtent().getNY(); set = m_Classes.keySet(); iter = set.iterator(); iClass = 0; while (iter.hasNext()) { stats = (ArrayList) m_Classes.get(iter.next()); for (iGrid = 0; iGrid < m_Window.length; iGrid++) { dMean[iClass][iGrid] = ((MeanAndStdDev) stats.get(iGrid)).mean; } iClass++; } for (y = 0; y < iNY; y++) { for (x = 0; x < iNX; x++) { for (iClass = 0, dMin = -1.0; iClass < m_Classes.size(); iClass++) { for (iGrid = 0, d = 0.0; iGrid < m_Window.length; iGrid++) { dValue = m_Window[iGrid].getCellValueAsDouble(x, y); if (!m_Window[iGrid].isNoDataValue(dValue)) { e = m_Window[iGrid].getCellValueAsDouble(x, y) - dMean[iClass][iGrid]; d += e * e; if ((dMin < 0.0) || (dMin > d)) { dMin = d; iMin = iClass; } } else { dMin = -1; } } } if (dMin >= 0.0) { m_Output.setCellValue(x, y, iMin + 1); } else { m_Output.setNoData(x, y); } } } }
@Override public boolean processAlgorithm() throws GeoAlgorithmExecutionException { m_LowerGrid = m_Parameters.getParameterValueAsRasterLayer(LGRID); m_UpperGrid = m_Parameters.getParameterValueAsRasterLayer(UGRID); m_LowerGrid.setWindowExtent(m_AnalysisExtent); m_UpperGrid.setWindowExtent(m_AnalysisExtent); m_iNX = m_LowerGrid.getNX(); m_iNY = m_LowerGrid.getNY(); return calculateVolumes(); }
@Override public boolean processAlgorithm() throws GeoAlgorithmExecutionException { int i; AnalysisExtent ge; final int iMethod = m_Parameters.getParameterValueAsInt(METHOD); m_Bands = m_Parameters.getParameterValueAsArrayList(INPUT); if (m_Bands.size() == 0) { return false; } m_Classes = new HashMap(); getClassInformation(); if (m_Task.isCanceled()) { return false; } m_Output = getNewRasterLayer( CLASSIFICATION, Sextante.getText("Classification"), IRasterLayer.RASTER_DATA_TYPE_SHORT); m_Output.setNoDataValue(-1); ge = m_Output.getWindowGridExtent(); m_Window = new IRasterLayer[m_Bands.size()]; m_iBands = new int[m_Bands.size()]; for (i = 0; i < m_Window.length; i++) { final RasterLayerAndBand band = (RasterLayerAndBand) m_Bands.get(i); m_iBands[i] = band.getBand(); m_Window[i] = band.getRasterLayer(); m_Window[i].setWindowExtent(ge); } switch (iMethod) { case 0: doParalellpiped(); case 1: default: doMinimumDistance(); case 2: doMaximumLikelihood(); } return !m_Task.isCanceled(); }
@Override public boolean processAlgorithm() throws GeoAlgorithmExecutionException { int x, y; int iN; int iNX, iNY; double dValue; double dProb; boolean bCDF; final IRasterLayer layer = m_Parameters.getParameterValueAsRasterLayer(INPUT); bCDF = m_Parameters.getParameterValueAsBoolean(CDF); dProb = m_Parameters.getParameterValueAsDouble(P); iN = m_Parameters.getParameterValueAsInt(N); layer.setFullExtent(); final AnalysisExtent gridExtent = new AnalysisExtent(layer); final IRasterLayer result = getNewRasterLayer( PROBABILITY, Sextante.getText("Probability__binomial"), IRasterLayer.RASTER_DATA_TYPE_DOUBLE, gridExtent); iNX = layer.getNX(); iNY = layer.getNY(); for (y = 0; y < iNY && setProgress(y, iNY); y++) { for (x = 0; x < iNX; x++) { dValue = layer.getCellValueAsDouble(x, y); if (!layer.isNoDataValue(dValue)) { if (bCDF) { result.setCellValue(x, y, PDF.binomialCDF(dProb, iN, (int) dValue)); } else { result.setCellValue(x, y, PDF.binomial(dProb, iN, (int) dValue)); } } else { result.setNoData(x, y); } } } return !m_Task.isCanceled(); }
@Override public boolean processAlgorithm() throws GeoAlgorithmExecutionException { int x, y; int iNX, iNY; double dValue; double dMean, dStdDev; boolean bCDF; final IRasterLayer window = m_Parameters.getParameterValueAsRasterLayer(INPUT); bCDF = m_Parameters.getParameterValueAsBoolean(CDF); dMean = m_Parameters.getParameterValueAsDouble(MEAN); dStdDev = m_Parameters.getParameterValueAsDouble(STDDEV); window.setFullExtent(); final AnalysisExtent gridExtent = new AnalysisExtent(window); final IRasterLayer result = getNewRasterLayer( PROBABILITY, Sextante.getText("Probability__exponential"), IRasterLayer.RASTER_DATA_TYPE_DOUBLE, gridExtent); iNX = window.getNX(); iNY = window.getNY(); for (y = 0; y < iNY && setProgress(y, iNY); y++) { for (x = 0; x < iNX; x++) { dValue = window.getCellValueAsDouble(x, y); if (!window.isNoDataValue(dValue)) { if (bCDF) { result.setCellValue(x, y, PDF.exponentialCDF(dMean, dStdDev, dValue)); } else { result.setCellValue(x, y, PDF.exponential(dMean, dStdDev, dValue)); } } else { result.setNoData(x, y); } } } return !m_Task.isCanceled(); }
private boolean calculateVolumes() { int x, y; double z, z2; double dVolumePos = 0; double dVolumeNeg = 0; double dVolume = 0; double dDif; final double dArea = m_LowerGrid.getWindowCellSize() * m_LowerGrid.getWindowCellSize(); for (y = 0; (y < m_iNY) && setProgress(y, m_iNY); y++) { for (x = 0; x < m_iNX; x++) { z = m_LowerGrid.getCellValueAsDouble(x, y); z2 = m_UpperGrid.getCellValueAsDouble(x, y); if (!m_LowerGrid.isNoDataValue(z) && !m_UpperGrid.isNoDataValue(z2)) { dDif = (z2 - z); dVolume += Math.abs(dDif); if (dDif > 0) { dVolumePos += dDif; } else { dVolumeNeg += -dDif; } } } } if (m_Task.isCanceled()) { return false; } else { dVolume *= dArea; dVolumePos *= dArea; dVolumeNeg *= dArea; final DecimalFormat df = new DecimalFormat("##.##"); final HTMLDoc doc = new HTMLDoc(); doc.open(Sextante.getText("Volumes")); doc.addHeader(Sextante.getText("Volumes"), 2); doc.startUnorderedList(); doc.addListElement(Sextante.getText("Volume_+") + df.format(dVolumePos)); doc.addListElement(Sextante.getText("Volume_-") + df.format(dVolumeNeg)); doc.addListElement(Sextante.getText("Total_volume") + df.format(dVolume)); doc.close(); addOutputText(VOL, Sextante.getText("Volume"), doc.getHTMLCode()); return true; } }
private void doMaximumLikelihood() { int iNX, iNY; int x, y; int iClass, iGrid, iMax = 0; final double dMean[][] = new double[m_Classes.size()][m_Window.length]; final double dStdDev[][] = new double[m_Classes.size()][m_Window.length]; final double dK[][] = new double[m_Classes.size()][m_Window.length]; double dMax, d, e; double dValue; ArrayList stats; MeanAndStdDev substats; Set set; Iterator iter; iNX = m_Output.getWindowGridExtent().getNX(); iNY = m_Output.getWindowGridExtent().getNY(); set = m_Classes.keySet(); iter = set.iterator(); iClass = 0; while (iter.hasNext()) { stats = (ArrayList) m_Classes.get(iter.next()); for (iGrid = 0; iGrid < m_Window.length; iGrid++) { substats = ((MeanAndStdDev) stats.get(iGrid)); dMean[iClass][iGrid] = substats.mean; dStdDev[iClass][iGrid] = substats.stdDev; dK[iClass][iGrid] = 1.0 / (dStdDev[iClass][iGrid] * Math.sqrt(2.0 * Math.PI)); } iClass++; } for (y = 0; y < iNY; y++) { for (x = 0; x < iNX; x++) { for (iClass = 0, dMax = 0.0; iClass < m_Classes.size(); iClass++) { for (iGrid = 0, d = 0.0; iGrid < m_Window.length; iGrid++) { dValue = m_Window[iGrid].getCellValueAsDouble(x, y); if (!m_Window[iGrid].isNoDataValue(dValue)) { e = (m_Window[iGrid].getCellValueAsDouble(x, y) - dMean[iClass][iGrid]) / dStdDev[iClass][iGrid]; e = dK[iClass][iGrid] * Math.exp(-0.5 * e * e); d += e * e; if (dMax < d) { dMax = d; iMax = iClass; } } else { dMax = -1; } } } if (dMax > 0.0) { m_Output.setCellValue(x, y, iMax + 1); } else { m_Output.setNoData(x, y); } } } }