Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / store / properties / DataStoreMetadata.java @ 162

History | View | Annotate | Download (6.99 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.impl.store.properties;
23

    
24
import java.util.ArrayList;
25

    
26
import org.gvsig.fmap.dal.coverage.datastruct.TransparencyRange;
27
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
28
import org.gvsig.raster.impl.datastruct.TransparencyRangeImpl;
29

    
30

    
31

    
32
/**
33
 * Guarda en un Array los metadatos de los distintos tipos de imagenes.
34
 *
35
 *  NODATA_VALUES=255 255 255 1
36
 *  AREA_OR_POINT=Point 4
37
 *  TIFFTAG_XRESOLUTION=72 4
38
 *  TIFFTAG_YRESOLUTION=72 4
39
 *  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) 4
40
 *
41
 *  STATISTICS_MINIMUM=0
42
 *  STATISTICS_MAXIMUM=221
43
 *  STATISTICS_MEAN=35.910196078431
44
 *  STATISTICS_MEDIAN=30
45
 *  STATISTICS_MODE=0
46
 *  STATISTICS_STDDEV=29.609849452294
47
 *  STATISTICS_HISTONUMBINS=256
48
 *  STATISTICS_HISTOMIN=0
49
 *  STATISTICS_HISTOMAX=255
50
 *  LAYER_TYPE=athematic
51
 *  STATISTICS_HISTOBINVALUES=30285675|0|0|22050| ...
52
 *
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class DataStoreMetadata implements Metadata {
56
        /**
57
         * Valores para los identificadores de los metadatos
58
         */
59
        private ArrayList<String>               metadata       = new ArrayList<String>();
60
        /**
61
         * Valores de los metadatos
62
         */
63
        private ArrayList<String>               values         = new ArrayList<String>();
64
        /**
65
         * Valores no data para cada banda de la imagen (si los tiene)
66
         */
67
        protected double[]                      noDataByBand   = null;
68
        /**
69
         * Valor para saber si el NoData esta activo
70
         */
71
        protected boolean                       noDataEnabled  = false;
72
        /**
73
         * Metadatos
74
         */
75
        protected String[]                                         metadataString = null;
76
        protected DataStoreColorInterpretation         colorInterpr   = null;
77

    
78
        public DataStoreMetadata(String[] metadata, DataStoreColorInterpretation colorInterpr){
79
                this.colorInterpr = colorInterpr;
80
                if(metadata == null)
81
                        return;
82
                metadataString = metadata;
83
                for(int i = 0;i<metadata.length;i++){
84
                        String[] value = metadata[i].split("=");
85
                        if(value.length >= 2){
86
                                this.metadata.add(value[0]);
87
                                this.values.add(value[1]);
88
                        }
89
                }
90
        }
91

    
92
        /**
93
         * Crea un objeto TransparencyRange a partir de los rangos de transparencia
94
         * @return
95
         */
96
        public TransparencyRange parserNodataByBand(){
97
                int bandR = colorInterpr.getBand("Red");
98
                int bandG = colorInterpr.getBand("Green");
99
                int bandB = colorInterpr.getBand("Blue");
100

    
101
                if(bandR < 0 && bandG < 0 && bandB < 0)
102
                        return null;
103

    
104
                //Esta comprobaci?n es para los raster con paleta (gif). Cuando se trate la paleta y no se usen como
105
                //imagenes de una banda habr? que cambiar esto
106
                if((colorInterpr.length() == 1) && colorInterpr.get(0).equals("Palette"))
107
                        return null;
108

    
109
                if(noDataByBand == null)
110
                        return null;
111

    
112
                //Si todos los valores nodata por banda son -1 es que no hay ninguno asignado
113
                int count =0;
114
                for(int i = 0; i < noDataByBand.length; i++)
115
                        if(noDataByBand[i] < 0)
116
                                count ++;
117

    
118
                if(count == noDataByBand.length)
119
                        return null;
120

    
121
                TransparencyRange tr = new TransparencyRangeImpl();
122
                int[] red = new int[2];
123
                int[] green = new int[2];
124
                int[] blue = new int[2];
125

    
126
                if(bandR >= 0){
127
                        red[0] = red[1] = (int)noDataByBand[bandR];
128
                        tr.setRed(red);
129
                }
130
                if(bandG >= 0){
131
                        green[0] = green[1] = (int)noDataByBand[bandG];
132
                        tr.setGreen(green);
133
                }
134
                if(bandB >= 0){
135
                        blue[0] = blue[1] = (int)noDataByBand[bandB];
136
                        tr.setBlue(blue);
137
                }
138

    
139
                tr.setAnd(true);
140
                tr.loadStrEntryFromValues();
141

    
142
                return tr;
143
        }
144

    
145
        /**
146
         * Parsea los metadatos NODATA_VALUES si existe alguno y devuelve un objeto TransparencyRange.
147
         * @param nodata
148
         * @return Vector de enteros con los valores RGBA o null si no tiene este metadato o no es parseable
149
         * en este formato.
150
         */
151
        public TransparencyRange[] parserNodataInMetadata(){
152
                //Esta comprobaci?n es para los raster con paleta (gif). Cuando se trate la paleta y no se usen como
153
                //imagenes de una banda habr? que cambiar esto
154
                if((colorInterpr.length() == 1) && colorInterpr.get(0).equals("Palette"))
155
                        return null;
156

    
157
                int count = 0;
158
                for(int i = 0; i < metadata.size(); i++){
159
                        if(((String)metadata.get(i)).equals("NODATA_VALUES"))
160
                                count ++;
161
                }
162
                if(count == 0)
163
                        return null;
164

    
165
                TransparencyRange[] trList = new TransparencyRange[count];
166

    
167
                count = 0;
168
                for(int i = 0; i < metadata.size(); i++){
169
                        TransparencyRange tr = new TransparencyRangeImpl();
170
                        int[] red = new int[2];
171
                        int[] green = new int[2];
172
                        int[] blue = new int[2];
173

    
174
                        if(((String)metadata.get(i)).equals("NODATA_VALUES")){
175
                                String data = (String)values.get(i);
176
                                String[] dataValues = data.split(" ");
177
                                //int[] values = new int[dataValues.length];
178
                                try{
179
                                        red[0] = red[1] = Integer.parseInt(dataValues[0]);
180
                                        green[0] = green[1] = Integer.parseInt(dataValues[1]);
181
                                        blue[0] = blue[1] = Integer.parseInt(dataValues[2]);
182
                                }catch(NumberFormatException exc){
183
                                        return null;
184
                                }
185
                        }
186
                        tr.setAnd(true);
187
                        tr.setRed(red);
188
                        tr.setGreen(green);
189
                        tr.setBlue(blue);
190
                        tr.loadStrEntryFromValues();
191
                        trList[count] = tr;
192
                        count ++;
193
                }
194

    
195
                return trList;
196
        }
197

    
198
        /**
199
         * Inicializa los valores no data;
200
         * @param values
201
         */
202
        public void initNoDataByBand(int values){
203
                noDataByBand = new double[values];
204
                for(int i = 0; i < values; i++)
205
                        noDataByBand[i] = -1;
206
        }
207

    
208
        /**
209
         * Asigna un valor para el valor noData por banda
210
         * @param band Banda
211
         * @param value valor
212
         */
213
        public void setNoDataValue(int band, double value){
214
                try {
215
                        noDataByBand[band] = value;
216
                } catch(ArrayIndexOutOfBoundsException ex) {
217
                        //No asignamos el elemento
218
                }
219
        }
220

    
221
        /**
222
         * Devuelve el valor NoData para una banda en concreto.
223
         * @param band
224
         * @return
225
         */
226
        public double getNoDataValue(int band) {
227
                return noDataByBand[band];
228
        }
229

    
230
        /**
231
         * Devuelve el valor NoData en forma de array.
232
         * @return
233
         */
234
        public double[] getNoDataValue() {
235
                return noDataByBand;
236
        }
237

    
238
        /**
239
         * Obtiene los metadatos en forma de vector de cadenas
240
         * @return Vector de cadenas en el que cada cadena es atributo=valor
241
         */
242
        public String[] getMetadataString() {
243
                return metadataString;
244
        }
245

    
246
        /**
247
         * Devuelve si el valor NoData esta activo
248
         * @return
249
         */
250
        public boolean isNoDataEnabled() {
251
                return noDataEnabled;
252
        }
253

    
254
        /**
255
         * Establece si el valor NoData esta activo
256
         * @param noDataEnabled
257
         */
258
        public void setNoDataEnabled(boolean noDataEnabled) {
259
                this.noDataEnabled = noDataEnabled;
260
        }
261
}