Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / driver / MultiFileStatistics.java @ 10740

History | View | Annotate | Download (3.9 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.driver;
20

    
21
import java.util.ArrayList;
22
import java.util.Date;
23

    
24
import org.gvsig.raster.driver.datasetproperties.DatasetStatistics;
25

    
26

    
27
/**
28
 * Estadisticas asociadas a un fichero raster formado por multiples ficheros.
29
 *  
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public class MultiFileStatistics extends DatasetStatistics{
33
         
34
        private DatasetStatistics[]         statList = null;
35
        private RasterDataset[]         grfList = null;
36
        
37
        /**
38
         * Constructor
39
         */
40
        public MultiFileStatistics(RasterDataset[] grfList){
41
                super(null);
42
                this.grfList = grfList;
43
                statList = new DatasetStatistics[grfList.length];
44
                for(int i = 0; i < grfList.length; i ++)
45
                        statList[i] = this.grfList[i].getStatistics();
46
        }
47
        
48
        /**
49
         * Constructor
50
         */
51
        public MultiFileStatistics(ArrayList grfList){
52
                super(null);
53
                statList = new DatasetStatistics[grfList.size()];
54
                this.grfList = new RasterDataset[grfList.size()];
55
                for(int i = 0; i < grfList.size(); i ++){
56
                        this.grfList[i] = (RasterDataset)grfList.get(i);
57
                        statList[i] = this.grfList[i].getStatistics();
58
                }
59
        }
60
        
61
        /**
62
         * Calcula las estadisticas recorriendo todo el fichero.
63
         */
64
        public void calcFullStatistics()throws FileNotOpenException, RasterDriverException{
65
                long t2;
66
        long t1 = new Date().getTime();
67
     
68
        int len = 0;
69
                for(int i = 0; i < statList.length; i ++){
70
                        statList[i].calcFullStatistics();
71
                        len += grfList[i].getBandCount();
72
                }
73
        
74
                constructStats(len);
75
                
76
        calculated = true;
77
                t2 = new Date().getTime();
78
            System.out.println("Estadisticas MultiFile: " + ((t2 - t1) / 1000D) + ", secs.");
79
        }
80
        
81
        private void constructStats(int len){
82
                max = new double[len];
83
                min = new double[len];
84
                secondMax = new double[len];
85
                secondMin = new double[len];
86
                mean = new double[len];
87
                variance = new double[len];
88
                        
89
                int count = 0;
90
                for(int i = 0; i < statList.length; i ++){
91
                        for(int j = 0; j < statList[i].getMax().length; j ++){
92
                                max[count] = statList[i].getMax()[j];
93
                                min[count] = statList[i].getMin()[j];
94
                                secondMax[count] = statList[i].getSecondMax()[j];
95
                                secondMin[count] = statList[i].getSecondMin()[j];
96
                                mean[count] = statList[i].getMean()[j];
97
                                variance[count] = statList[i].getVariance()[j];
98
                                count ++;
99
                        }
100
                }
101
        }
102
        
103
        /**
104
         * Carga estadisticas desde el fichero Rmf si las hay.
105
         * @param fName Nombre del fichero
106
         */
107
        public void loadFromRmf(){
108
                int len = 0;
109
                for(int i = 0; i < statList.length; i ++){
110
                        statList[i].loadFromRmf();
111
                        len += grfList[i].getBandCount();
112
                }
113
                
114
                constructStats(len);
115
        }
116
        
117
        /**
118
         * Salva estad?sticas a fichero rmf.
119
         * @param fName
120
         */
121
        public void saveToRmf(){
122
                for(int i = 0; i < statList.length; i ++)
123
                        statList[i].saveToRmf();
124
        }
125

    
126
        /**
127
         * Obtiene el flag que informa de si las estad?sticas est?n calculadas o no.
128
         * @return true indica que est?n calculadas y false que no lo est?n
129
         */
130
        public boolean isCalculated() {
131
                return calculated;
132
        }
133
        
134
        /**
135
         * N?mero de bandas
136
         * @return
137
         */
138
        public int getBandCount(){
139
                int bandCount = 0;
140
                for(int i = 0; i < statList.length; i ++)
141
                        bandCount += statList[i].getBandCount();
142
                return bandCount;
143
        }
144
}