root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / morphometry / realArea / RealAreaAlgorithm.java @ 59
History | View | Annotate | Download (2.29 KB)
1 |
package es.unex.sextante.morphometry.realArea; |
---|---|
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 RealAreaAlgorithm |
11 |
extends
|
12 |
GeoAlgorithm { |
13 |
|
14 |
public static final String DEM = "DEM"; |
15 |
public static final String REALAREA = "REALAREA"; |
16 |
|
17 |
IRasterLayer m_RealArea; |
18 |
IRasterLayer m_DEM = null;
|
19 |
private double m_DX2; |
20 |
|
21 |
|
22 |
@Override
|
23 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
24 |
|
25 |
int x, y;
|
26 |
int iNX, iNY;
|
27 |
|
28 |
m_DEM = m_Parameters.getParameterValueAsRasterLayer(DEM); |
29 |
m_RealArea = getNewRasterLayer(REALAREA, Sextante.getText("Real_area"), IRasterLayer.RASTER_DATA_TYPE_FLOAT);
|
30 |
|
31 |
|
32 |
final AnalysisExtent extent = m_RealArea.getWindowGridExtent();
|
33 |
|
34 |
m_DEM.setWindowExtent(extent); |
35 |
|
36 |
iNX = m_DEM.getNX(); |
37 |
iNY = m_DEM.getNY(); |
38 |
|
39 |
m_DX2 = m_DEM.getWindowCellSize() * m_DEM.getWindowCellSize(); |
40 |
|
41 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
42 |
for (x = 0; x < iNX; x++) { |
43 |
setRealArea(x, y); |
44 |
} |
45 |
} |
46 |
|
47 |
return !m_Task.isCanceled();
|
48 |
} |
49 |
|
50 |
|
51 |
@Override
|
52 |
public void defineCharacteristics() { |
53 |
|
54 |
setUserCanDefineAnalysisExtent(true);
|
55 |
setGroup(Sextante.getText("Geomorphometry_and_terrain_analysis"));
|
56 |
setName(Sextante.getText("Real_area"));
|
57 |
|
58 |
try {
|
59 |
m_Parameters.addInputRasterLayer(DEM, Sextante.getText("Elevation"), true); |
60 |
addOutputRasterLayer(REALAREA, Sextante.getText("Real_area"));
|
61 |
} |
62 |
catch (final RepeatedParameterNameException e) { |
63 |
Sextante.addErrorToLog(e); |
64 |
} |
65 |
|
66 |
} |
67 |
|
68 |
|
69 |
private void setRealArea(final int x, |
70 |
final int y) { |
71 |
|
72 |
final double dSlope = m_DEM.getSlope(x, y); |
73 |
double dArea;
|
74 |
|
75 |
if (!m_DEM.isNoDataValue(dSlope)) {
|
76 |
dArea = m_DX2 / Math.cos(dSlope);
|
77 |
m_RealArea.setCellValue(x, y, dArea); |
78 |
} |
79 |
else {
|
80 |
m_RealArea.setNoData(x, y); |
81 |
} |
82 |
|
83 |
} |
84 |
|
85 |
} |