Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / raster / process / StatisticsProcess.java @ 1419

History | View | Annotate | Download (3.73 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.basic.raster.process;
23

    
24
import javax.swing.SwingUtilities;
25

    
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
31
import org.gvsig.raster.fmap.layers.FLyrRaster;
32

    
33

    
34
/**
35
 * Proceso para la generaci?n de estad?sticas.
36
 *
37
 * 10/12/2007
38
 * @author Nacho Brodin nachobrodin@gmail.com
39
 */
40
public class StatisticsProcess extends RasterProcess {
41
        private FLyrRaster            lyr   = null;
42
        private Statistics            stats = null;
43
        private boolean               force = false;
44
        private double                scale = 1;
45

    
46
        /**
47
         * Lanzador del procesos de estad?sticas
48
         * @param lyr Capa a calcular las estad?sticas
49
         * @param actions Clase que recoge eventos del proceso
50
         */
51
        public static void launcher(FLyrRaster lyr, IProcessActions actions) {
52
                RasterProcess process = new StatisticsProcess();
53
                process.addParam("layer", lyr);
54
                process.addParam("force", new Boolean(false));
55
                process.setActions(actions);
56
                process.start();        
57
        }
58
        
59
        /*
60
         * (non-Javadoc)
61
         * @see org.gvsig.rastertools.RasterProcess#init()
62
         */
63
        public void init() {
64
                lyr = getLayerParam("layer");
65
                force = getBooleanParam("force");
66
                double s = getDoubleParam("scale");
67
                if(s > 0 && s < 1)
68
                        scale = s;
69
        }
70

    
71
        /**
72
         * M?todo donde se ejecutar? el Thread, aqu? se calcular?n las 
73
         * estad?sticas.
74
         * @throws ProcessException 
75
         */
76
        public void process() throws ProcessInterruptedException, ProcessException {
77
                insertLineLog(PluginServices.getText(this, "statistics_generation"));
78
                if(lyr == null || lyr.getDataStore() == null)
79
                        return;
80
                stats = lyr.getDataStore().getStatistics();
81
                lyr.setReadingData(Thread.currentThread().getId() + "");
82
                if (force)
83
                        stats.forceToRecalc();
84
                try {
85
                        stats.calculate(scale);
86
                        SwingUtilities.invokeLater(new Runnable() {
87
                                public void run() {
88
                                        if (externalActions != null)
89
                                                externalActions.end(lyr);
90
                                }
91
                        });
92
                } catch (FileNotOpenException e) {
93
                        throw new ProcessException("No se ha podido escribir en el fichero rmf", e);
94
                } catch (RasterDriverException e) {
95
                        throw new ProcessException("Error leyendo bloques de datos para calcular estad?sticas", e);
96
                } finally {
97
                        lyr.setReadingData(null);
98
                }
99
        }
100

    
101
        /*
102
         * (non-Javadoc)
103
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
104
         */
105
        public int getPercent() {
106
                return (stats != null) ? stats.getPercent() : 0;
107
        }
108

    
109
        /*
110
         * (non-Javadoc)
111
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
112
         */
113
        public String getTitle() {
114
                return PluginServices.getText(this, "increase_statistics");
115
        }
116
}