gvsig-raster / org.gvsig.raster.tools / trunk / templates / rasterTaskProjectTemplate / sextante_template / sources / ProjectTemplateSextanteAlgorithm.java @ 1927
History | View | Annotate | Download (3.78 KB)
1 |
package org.gvsig.raster.projecttemplate; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
4 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
5 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
6 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
7 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterIRasterLayer; |
8 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
9 |
import org.gvsig.raster.algorithm.process.ProcessException; |
10 |
import org.gvsig.raster.algorithm.process.RasterProcess; |
11 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
12 |
import org.gvsig.raster.projecttemplate.algorithm.ProjectTemplateProcess; |
13 |
|
14 |
import es.unex.sextante.core.AnalysisExtent; |
15 |
import es.unex.sextante.core.Sextante; |
16 |
import es.unex.sextante.dataObjects.IRasterLayer; |
17 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
18 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
19 |
|
20 |
/**
|
21 |
* ...
|
22 |
*/
|
23 |
public class ProjectTemplateSextanteAlgorithm extends AbstractSextanteGeoProcess { |
24 |
public static final String RESULT = "RESULT"; |
25 |
public static final String LAYER = ProjectTemplateProcess.RASTER_STORE1; |
26 |
|
27 |
|
28 |
public void defineCharacteristics() { |
29 |
setName(getTranslation("projecttemplate"));
|
30 |
setGroup(getTranslation("basic_raster_algorithms"));
|
31 |
// setGeneratesUserDefinedRasterOutput(false);
|
32 |
|
33 |
try {
|
34 |
m_Parameters.addInputRasterLayer(LAYER, getTranslation("Input_layer"), true); |
35 |
//TODO:Add parameters
|
36 |
} catch (RepeatedParameterNameException e) {
|
37 |
Sextante.addErrorToLog(e); |
38 |
} |
39 |
addOutputRasterLayer(RESULT, getTranslation("projecttemplate"));
|
40 |
} |
41 |
|
42 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
43 |
|
44 |
if(existsOutPutFile(ProjectTemplateSextanteAlgorithm.RESULT, 0)) { |
45 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
46 |
} |
47 |
|
48 |
IRasterLayer input = m_Parameters.getParameterValueAsRasterLayer(LAYER); |
49 |
//TODO:Get parameters
|
50 |
|
51 |
FLyrRaster lyrRaster = ((FLyrRaster)input.getBaseDataObject()); |
52 |
IRasterLayer output = null;
|
53 |
RasterProcess task = null;
|
54 |
AnalysisExtent ext = getAnalysisExtent(); |
55 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent( |
56 |
ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin()); |
57 |
try {
|
58 |
output = getNewRORasterLayer( |
59 |
RESULT, |
60 |
Sextante.getText("projecttemplate_description"),
|
61 |
input.getDataType(), |
62 |
input.getBandsCount()); |
63 |
task = RasterBaseAlgorithmLibrary.getManager().createRasterTask("ProjectTemplateProcess");
|
64 |
} catch (ProcessException e1) {
|
65 |
Sextante.addErrorToLog(e1); |
66 |
} |
67 |
|
68 |
String fileName = ((FLyrRasterIRasterLayer)output).getFileName(); //getOutPutFile(RESULT); |
69 |
task.addParam(ProjectTemplateProcess.PATH, fileName); |
70 |
task.addParam(ProjectTemplateProcess.RASTER_STORE1, lyrRaster.getDataStore()); |
71 |
//TODO:Add parameters
|
72 |
task.addParam(ProjectTemplateProcess.EXPORT, true);
|
73 |
task.addParam(ProjectTemplateProcess.TEST_EXTENT, bbox); |
74 |
task.addParam(ProjectTemplateProcess.TEST_WIDTH, ext.getNX()); |
75 |
task.addParam(ProjectTemplateProcess.TEST_HEIGHT, ext.getNY()); |
76 |
|
77 |
try {
|
78 |
task.execute(); |
79 |
((FLyrRasterIRasterLayer)output).setBaseDataObject(fileName); |
80 |
} catch (ProcessInterruptedException e) {
|
81 |
Sextante.addErrorToLog(e); |
82 |
} catch (ProcessException e) {
|
83 |
Sextante.addErrorToLog(e); |
84 |
} |
85 |
|
86 |
if(getTaskMonitor().isCanceled())
|
87 |
return false; |
88 |
|
89 |
return true; |
90 |
} |
91 |
|
92 |
/*
|
93 |
* TODO: Customized panels
|
94 |
@Override
|
95 |
public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
|
96 |
return ProjectTemplateParametersPanel.class;
|
97 |
}*/
|
98 |
} |