Statistics
| Revision:

gvsig-raster / org.gvsig.raster.principalcomponents / trunk / org.gvsig.raster.principalcomponents / org.gvsig.raster.principalcomponents.sextante / src / main / java / org / gvsig / raster / principalcomponents / PrincipalComponentsSextanteAlgorithm.java @ 2100

History | View | Annotate | Download (3.85 KB)

1
package org.gvsig.raster.principalcomponents;
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.DataProcess;
11
import org.gvsig.raster.fmap.layers.FLyrRaster;
12
import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsProcess;
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 PrincipalComponentsSextanteAlgorithm extends AbstractSextanteGeoProcess {
24
    public static final String RESULT            = "RESULT";
25
    public static final String LAYER             = PrincipalComponentsProcess.RASTER_STORE;
26
    
27

    
28
    public void defineCharacteristics() {
29
        setName(getTranslation("principalcomponents"));
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("principalcomponents"));
40
    }
41

    
42
    public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
43

    
44
            if(existsOutPutFile(PrincipalComponentsSextanteAlgorithm.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
            DataProcess 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("principalcomponents_description"), 
61
                                        input.getDataType(), 
62
                                        input.getBandsCount());
63
                        task = RasterBaseAlgorithmLibrary.getManager().createRasterTask("PrincipalComponentsProcess");
64
                } catch (ProcessException e1) {
65
                         Sextante.addErrorToLog(e1);
66
                } 
67
            
68
            String fileName = ((FLyrRasterIRasterLayer)output).getFileName(); //getOutPutFile(RESULT);
69
            task.addParam(PrincipalComponentsProcess.PATH, fileName);
70
                task.addParam(PrincipalComponentsProcess.RASTER_STORE, lyrRaster.getDataStore());
71
                //TODO:Add parameters
72
                /*task.addParam(PrincipalComponentsProcess.EXPORT, true);
73
                task.addParam(PrincipalComponentsProcess.TEST_EXTENT, bbox);
74
                task.addParam(PrincipalComponentsProcess.TEST_WIDTH, ext.getNX());
75
                task.addParam(PrincipalComponentsProcess.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 PrincipalComponentsParametersPanel.class;
97
    }*/
98
}