root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / properties / DatasetMetadata.java @ 12383
History | View | Annotate | Download (6 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.dataset.properties; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.raster.datastruct.TransparencyRange; |
24 |
|
25 |
|
26 |
|
27 |
/**
|
28 |
* Guarda en un Array los metadatos de los distintos tipos de imagenes.
|
29 |
*
|
30 |
* NODATA_VALUES=255 255 255 1
|
31 |
* AREA_OR_POINT=Point 4
|
32 |
* TIFFTAG_XRESOLUTION=72 4
|
33 |
* TIFFTAG_YRESOLUTION=72 4
|
34 |
* TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) 4
|
35 |
*
|
36 |
* STATISTICS_MINIMUM=0
|
37 |
* STATISTICS_MAXIMUM=221
|
38 |
* STATISTICS_MEAN=35.910196078431
|
39 |
* STATISTICS_MEDIAN=30
|
40 |
* STATISTICS_MODE=0
|
41 |
* STATISTICS_STDDEV=29.609849452294
|
42 |
* STATISTICS_HISTONUMBINS=256
|
43 |
* STATISTICS_HISTOMIN=0
|
44 |
* STATISTICS_HISTOMAX=255
|
45 |
* LAYER_TYPE=athematic
|
46 |
* STATISTICS_HISTOBINVALUES=30285675|0|0|22050| ...
|
47 |
*
|
48 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
49 |
*/
|
50 |
public class DatasetMetadata{ |
51 |
/**
|
52 |
* Valores para los identificadores de los metadatos
|
53 |
*/
|
54 |
private ArrayList metadata = new ArrayList(); |
55 |
/**
|
56 |
* Valores de los metadatos
|
57 |
*/
|
58 |
private ArrayList values = new ArrayList(); |
59 |
/**
|
60 |
* Valores no data para cada banda de la imagen (si los tiene)
|
61 |
*/
|
62 |
private double[] noDataByBand = null; |
63 |
/**
|
64 |
* Metadatos
|
65 |
*/
|
66 |
private String[] metadataString = null; |
67 |
private DatasetColorInterpretation colorInterpr = null; |
68 |
|
69 |
public DatasetMetadata(String[] metadata, DatasetColorInterpretation colorInterpr){ |
70 |
this.colorInterpr = colorInterpr;
|
71 |
if(metadata == null) |
72 |
return;
|
73 |
metadataString = metadata; |
74 |
for(int i = 0;i<metadata.length;i++){ |
75 |
String[] value = metadata[i].split("="); |
76 |
if(value.length >= 2){ |
77 |
this.metadata.add(value[0]); |
78 |
this.values.add(value[1]); |
79 |
} |
80 |
} |
81 |
} |
82 |
|
83 |
/**
|
84 |
* Crea un objeto TransparencyRange a partir de los rangos de transparencia
|
85 |
* @return
|
86 |
*/
|
87 |
public TransparencyRange parserNodataByBand(){
|
88 |
int bandR = colorInterpr.getBand("Red"); |
89 |
int bandG = colorInterpr.getBand("Green"); |
90 |
int bandB = colorInterpr.getBand("Blue"); |
91 |
|
92 |
if(bandR < 0 && bandG < 0 && bandB < 0) |
93 |
return null; |
94 |
|
95 |
//Esta comprobaci?n es para los raster con paleta (gif). Cuando se trate la paleta y no se usen como
|
96 |
//imagenes de una banda habr? que cambiar esto
|
97 |
if((colorInterpr.length() == 1) && colorInterpr.get(0).equals("Palette")) |
98 |
return null; |
99 |
|
100 |
if(noDataByBand == null) |
101 |
return null; |
102 |
|
103 |
//Si todos los valores nodata por banda son -1 es que no hay ninguno asignado
|
104 |
int count =0; |
105 |
for(int i = 0; i < noDataByBand.length; i++) |
106 |
if(noDataByBand[i] < 0) |
107 |
count ++; |
108 |
|
109 |
if(count == noDataByBand.length)
|
110 |
return null; |
111 |
|
112 |
TransparencyRange tr = new TransparencyRange();
|
113 |
int[] red = new int[2]; |
114 |
int[] green = new int[2]; |
115 |
int[] blue = new int[2]; |
116 |
|
117 |
if(bandR >= 0){ |
118 |
red[0] = red[1] = (int)noDataByBand[bandR]; |
119 |
tr.setRed(red); |
120 |
} |
121 |
if(bandG >= 0){ |
122 |
green[0] = green[1] = (int)noDataByBand[bandG]; |
123 |
tr.setGreen(green); |
124 |
} |
125 |
if(bandB >= 0){ |
126 |
blue[0] = blue[1] = (int)noDataByBand[bandB]; |
127 |
tr.setBlue(blue); |
128 |
} |
129 |
|
130 |
tr.setAnd(true);
|
131 |
tr.loadStrEntryFromValues(); |
132 |
|
133 |
return tr;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* Parsea los metadatos NODATA_VALUES si existe alguno y devuelve un objeto TransparencyRange.
|
138 |
* @param nodata
|
139 |
* @return Vector de enteros con los valores RGBA o null si no tiene este metadato o no es parseable
|
140 |
* en este formato.
|
141 |
*/
|
142 |
public TransparencyRange[] parserNodataInMetadata(){ |
143 |
//Esta comprobaci?n es para los raster con paleta (gif). Cuando se trate la paleta y no se usen como
|
144 |
//imagenes de una banda habr? que cambiar esto
|
145 |
if((colorInterpr.length() == 1) && colorInterpr.get(0).equals("Palette")) |
146 |
return null; |
147 |
|
148 |
int count = 0; |
149 |
for(int i = 0; i < metadata.size(); i++){ |
150 |
if(((String)metadata.get(i)).equals("NODATA_VALUES")) |
151 |
count ++; |
152 |
} |
153 |
if(count == 0) |
154 |
return null; |
155 |
|
156 |
TransparencyRange[] trList = new TransparencyRange[count]; |
157 |
|
158 |
count = 0;
|
159 |
for(int i = 0; i < metadata.size(); i++){ |
160 |
TransparencyRange tr = new TransparencyRange();
|
161 |
int[] red = new int[2]; |
162 |
int[] green = new int[2]; |
163 |
int[] blue = new int[2]; |
164 |
|
165 |
if(((String)metadata.get(i)).equals("NODATA_VALUES")){ |
166 |
String data = (String)values.get(i); |
167 |
String[] dataValues = data.split(" "); |
168 |
//int[] values = new int[dataValues.length];
|
169 |
try{
|
170 |
red[0] = red[1] = Integer.parseInt(dataValues[0]); |
171 |
green[0] = green[1] = Integer.parseInt(dataValues[1]); |
172 |
blue[0] = blue[1] = Integer.parseInt(dataValues[2]); |
173 |
}catch(NumberFormatException exc){ |
174 |
return null; |
175 |
} |
176 |
} |
177 |
tr.setAnd(true);
|
178 |
tr.setRed(red); |
179 |
tr.setGreen(green); |
180 |
tr.setBlue(blue); |
181 |
tr.loadStrEntryFromValues(); |
182 |
trList[count] = tr; |
183 |
count ++; |
184 |
} |
185 |
|
186 |
return trList;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* Inicializa los valores no data;
|
191 |
* @param values
|
192 |
*/
|
193 |
public void initNoDataByBand(int values){ |
194 |
noDataByBand = new double[values]; |
195 |
for(int i = 0; i < values; i++) |
196 |
noDataByBand[i] = -1;
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Asigna un valor para el valor noData por banda
|
201 |
* @param band Banda
|
202 |
* @param value valor
|
203 |
*/
|
204 |
public void setNoDataValue(int band, double value){ |
205 |
try{
|
206 |
noDataByBand[band] = value; |
207 |
}catch(ArrayIndexOutOfBoundsException ex){ |
208 |
//No asignamos el elemento
|
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Obtiene los metadatos en forma de vector de cadenas
|
214 |
* @return Vector de cadenas en el que cada cadena es atributo=valor
|
215 |
*/
|
216 |
public String[] getMetadataString() { |
217 |
return metadataString;
|
218 |
} |
219 |
|
220 |
} |