gvsig-raster / org.gvsig.raster.tasseledcap / trunk / org.gvsig.raster.tasseledcap / org.gvsig.raster.tasseledcap.toolbox.algorithm / src / main / java / org / gvsig / raster / tasseledcap / TasseledCapSextanteAlgorithm.java @ 2381
History | View | Annotate | Download (6.25 KB)
1 |
package org.gvsig.raster.tasseledcap; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
|
5 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
6 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
7 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
8 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
9 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
10 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterIRasterLayer; |
11 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
12 |
import org.gvsig.raster.algorithm.process.DataProcess; |
13 |
import org.gvsig.raster.algorithm.process.IProcessActions; |
14 |
import org.gvsig.raster.algorithm.process.ProcessException; |
15 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
16 |
import org.gvsig.raster.tasseledcap.algorithm.TasseledCapAlgorithmLibrary; |
17 |
import org.gvsig.raster.tasseledcap.algorithm.TasseledCapProcess; |
18 |
|
19 |
import es.unex.sextante.core.AnalysisExtent; |
20 |
import es.unex.sextante.core.Sextante; |
21 |
import es.unex.sextante.dataObjects.IRasterLayer; |
22 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
23 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
24 |
|
25 |
/**
|
26 |
* ...
|
27 |
*/
|
28 |
public class TasseledCapSextanteAlgorithm extends AbstractSextanteGeoProcess implements IProcessActions { |
29 |
public static final String RESULT = "RESULT"; |
30 |
public static final String LAYER = TasseledCapProcess.RASTER_STORE; |
31 |
public static final String USE_ROI = "USE_ROI"; |
32 |
public static final String TYPE = "TYPE"; |
33 |
|
34 |
public static String[] LANDSAT_TYPES = new String[]{"Landsat MS" , "Landsat TM", "Landsat ETM"}; |
35 |
|
36 |
|
37 |
private boolean useROI = false; |
38 |
private DataProcess taskStats = null; |
39 |
private DataProcess taskPC = null; |
40 |
private int type = 0; |
41 |
|
42 |
|
43 |
public void defineCharacteristics() { |
44 |
setName(getTranslation("tasseledcap"));
|
45 |
setGroup(getTranslation("multispectral"));
|
46 |
|
47 |
try {
|
48 |
m_Parameters.addInputRasterLayer(LAYER, getTranslation("Input_layer"), true); |
49 |
m_Parameters.addBoolean(USE_ROI, getTranslation("use_roi"), false); |
50 |
m_Parameters.addSelection(TYPE, getTranslation("type"), LANDSAT_TYPES);
|
51 |
} catch (RepeatedParameterNameException e) {
|
52 |
Sextante.addErrorToLog(e); |
53 |
} |
54 |
addOutputRasterLayer(RESULT, getTranslation("tasseledcap"));
|
55 |
} |
56 |
|
57 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
58 |
|
59 |
if(existsOutPutFile(TasseledCapSextanteAlgorithm.RESULT, 0)) { |
60 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
61 |
} |
62 |
|
63 |
IRasterLayer input = m_Parameters.getParameterValueAsRasterLayer(LAYER); |
64 |
useROI = m_Parameters.getParameterValueAsBoolean(USE_ROI); |
65 |
String value = m_Parameters.getParameterValueAsString(TYPE);
|
66 |
type = 0;
|
67 |
for (int j = 0; j < LANDSAT_TYPES.length; j++) { |
68 |
if(LANDSAT_TYPES[j].equals(value))
|
69 |
type = j; |
70 |
} |
71 |
|
72 |
FLyrRaster lyrRaster = ((FLyrRaster)input.getBaseDataObject()); |
73 |
IRasterLayer output = null;
|
74 |
|
75 |
output = getNewRORasterLayer( |
76 |
RESULT, |
77 |
Sextante.getText("tasseledcap_description"),
|
78 |
input.getDataType(), |
79 |
input.getBandsCount()); |
80 |
|
81 |
String fileName = ((FLyrRasterIRasterLayer)output).getFileName(); //getOutPutFile(RESULT); |
82 |
|
83 |
try {
|
84 |
setProgressText(getTranslation("calculating"));
|
85 |
taskPC = createTasseledCapProcess(lyrRaster.getDataStore(), fileName, type); |
86 |
taskPC.execute(); |
87 |
((FLyrRasterIRasterLayer)output).setBaseDataObject(fileName); |
88 |
} catch (ProcessInterruptedException e) {
|
89 |
Sextante.addErrorToLog(e); |
90 |
} catch (ProcessException e) {
|
91 |
Sextante.addErrorToLog(e); |
92 |
} |
93 |
|
94 |
if(getTaskMonitor().isCanceled())
|
95 |
return false; |
96 |
|
97 |
return true; |
98 |
} |
99 |
|
100 |
private DataProcess createTasseledCapProcess(RasterDataStore inputStore, String fileName, int type) throws ProcessException { |
101 |
DataProcess taskPC = RasterBaseAlgorithmLibrary.getManager().createRasterTask(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL); |
102 |
taskPC.setActions(this);
|
103 |
List<String> params = taskPC.getRasterTaskInputParameters(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL); |
104 |
for (int i = 0; i < params.size(); i++) { |
105 |
String paramName = params.get(i);
|
106 |
Class<?> paramType = taskPC.getParameterTypeByProcess(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL, paramName);
|
107 |
if(paramType == RasterDataStore.class) {
|
108 |
taskPC.addParam(paramName, (RasterDataStore)inputStore); |
109 |
} |
110 |
|
111 |
if(paramType == Boolean[].class) { |
112 |
boolean[] bands = new boolean[type == 0 ? 4 : 6]; |
113 |
for (int j = 0; j < bands.length; j++) { |
114 |
bands[j] = true;
|
115 |
} |
116 |
taskPC.addParam(paramName, bands); |
117 |
} |
118 |
|
119 |
if(paramType == Integer.class) { |
120 |
taskPC.addParam(paramName, type); |
121 |
} |
122 |
|
123 |
if(paramName.equals("PATH")) { |
124 |
taskPC.addParam(paramName, fileName); |
125 |
} |
126 |
|
127 |
if(paramName.equals("ROI_EPSG") && useROI) { |
128 |
taskPC.addParam(paramName, "EPSG:4326");
|
129 |
} |
130 |
|
131 |
if(paramName.equals("WINDOW")) { |
132 |
AnalysisExtent ext = getAnalysisExtent(); |
133 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent( |
134 |
ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin()); |
135 |
Extent inputBbox = inputStore.getExtent(); |
136 |
if(bbox.getULX() != inputBbox.getULX() ||
|
137 |
bbox.getULY() != inputBbox.getULY() || |
138 |
bbox.getLRX() != inputBbox.getLRX() || |
139 |
bbox.getLRY() != inputBbox.getLRY()) { |
140 |
taskPC.addParam(paramName, bbox); |
141 |
} |
142 |
} |
143 |
} |
144 |
return taskPC;
|
145 |
} |
146 |
|
147 |
public void interrupted() { |
148 |
|
149 |
} |
150 |
|
151 |
public void end(Object param) { |
152 |
|
153 |
} |
154 |
|
155 |
public void updateProgress(int current, int total) { |
156 |
boolean cancelled = setProgress(current, total);
|
157 |
|
158 |
if(!cancelled) {
|
159 |
if(taskStats != null) |
160 |
taskStats.actionCanceled(null);
|
161 |
if(taskPC != null) |
162 |
taskPC.actionCanceled(null);
|
163 |
} |
164 |
} |
165 |
|
166 |
/*
|
167 |
* TODO: Customized panels
|
168 |
@Override
|
169 |
public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
|
170 |
return PrincipalComponentsParametersPanel.class;
|
171 |
}*/
|
172 |
} |