root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / morphometry / elevationReliefIndex / ElevationReliefIndexAlgorithm.java @ 59
History | View | Annotate | Download (3.15 KB)
1 |
package es.unex.sextante.morphometry.elevationReliefIndex; |
---|---|
2 |
|
3 |
import es.unex.sextante.core.GeoAlgorithm; |
4 |
import es.unex.sextante.core.AnalysisExtent; |
5 |
import es.unex.sextante.core.Sextante; |
6 |
import es.unex.sextante.dataObjects.IRasterLayer; |
7 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
8 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
9 |
|
10 |
public class ElevationReliefIndexAlgorithm |
11 |
extends
|
12 |
GeoAlgorithm { |
13 |
|
14 |
private final static int m_iOffsetX[] = { 0, 1, 1, 1, 0, -1, -1, -1 }; |
15 |
private final static int m_iOffsetY[] = { 1, 1, 0, -1, -1, -1, 0, 1 }; |
16 |
|
17 |
public static final String DEM = "DEM"; |
18 |
public static final String RESULT = "RESULT"; |
19 |
|
20 |
IRasterLayer m_ERIndex; |
21 |
IRasterLayer m_DEM = null;
|
22 |
|
23 |
|
24 |
@Override
|
25 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
26 |
|
27 |
int x, y;
|
28 |
int iNX, iNY;
|
29 |
|
30 |
m_DEM = m_Parameters.getParameterValueAsRasterLayer(DEM); |
31 |
|
32 |
m_ERIndex = getNewRasterLayer(RESULT, Sextante.getText("Elevation-relief_ratio"), IRasterLayer.RASTER_DATA_TYPE_FLOAT);
|
33 |
|
34 |
final AnalysisExtent extent = m_ERIndex.getWindowGridExtent();
|
35 |
|
36 |
m_DEM.setWindowExtent(extent); |
37 |
|
38 |
iNX = m_DEM.getNX(); |
39 |
iNY = m_DEM.getNY(); |
40 |
|
41 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
42 |
for (x = 0; x < iNX; x++) { |
43 |
calculateERIndex(x, y); |
44 |
} |
45 |
|
46 |
} |
47 |
|
48 |
return !m_Task.isCanceled();
|
49 |
|
50 |
} |
51 |
|
52 |
|
53 |
@Override
|
54 |
public void defineCharacteristics() { |
55 |
|
56 |
setName(Sextante.getText("Elevation-relief_ratio"));
|
57 |
setGroup(Sextante.getText("Geomorphometry_and_terrain_analysis"));
|
58 |
setUserCanDefineAnalysisExtent(true);
|
59 |
|
60 |
try {
|
61 |
m_Parameters.addInputRasterLayer(DEM, Sextante.getText("Elevation"), true); |
62 |
addOutputRasterLayer(RESULT, Sextante.getText("Elevation-relief_ratio"));
|
63 |
} |
64 |
catch (final RepeatedParameterNameException e) { |
65 |
Sextante.addErrorToLog(e); |
66 |
} |
67 |
|
68 |
} |
69 |
|
70 |
|
71 |
private void calculateERIndex(final int x, |
72 |
final int y) { |
73 |
|
74 |
int i;
|
75 |
int iCells;
|
76 |
double z, dAvgZ;
|
77 |
double dMaxZ, dMinZ;
|
78 |
double dIndex;
|
79 |
|
80 |
z = m_DEM.getCellValueAsDouble(x, y); |
81 |
|
82 |
if (m_DEM.isNoDataValue(z)) {
|
83 |
m_ERIndex.setNoData(x, y); |
84 |
} |
85 |
else {
|
86 |
dMaxZ = dMinZ = z; |
87 |
dAvgZ = z; |
88 |
iCells = 0;
|
89 |
for (i = 0; i < 8; i++) { |
90 |
z = m_DEM.getCellValueAsDouble(x + m_iOffsetX[i], y + m_iOffsetY[i]); |
91 |
if (!m_DEM.isNoDataValue(z)) {
|
92 |
iCells++; |
93 |
dAvgZ += z; |
94 |
dMinZ = Math.min(dMinZ, z);
|
95 |
dMaxZ = Math.max(dMaxZ, z);
|
96 |
} |
97 |
} |
98 |
|
99 |
if (iCells == 0) { |
100 |
m_ERIndex.setNoData(x, y); |
101 |
} |
102 |
else {
|
103 |
if (dMaxZ != dMinZ) {
|
104 |
dIndex = (dAvgZ - dMinZ) / (dMaxZ - dMinZ); |
105 |
m_ERIndex.setCellValue(x, y, dIndex); |
106 |
} |
107 |
else {
|
108 |
m_ERIndex.setNoData(x, y); |
109 |
} |
110 |
} |
111 |
} |
112 |
} |
113 |
|
114 |
|
115 |
} |