Revision 13130 trunk/libraries/libCresques/src/org/cresques/io/data/Metadata.java

View differences:

Metadata.java
29 29

  
30 30
/**
31 31
 * Guarda en un Array los metadatos de los distintos tipos de imagenes.
32
 * 
32
 *
33 33
 *  NODATA_VALUES=255 255 255 1
34 34
 *  AREA_OR_POINT=Point 4
35 35
 *  TIFFTAG_XRESOLUTION=72 4
36 36
 *  TIFFTAG_YRESOLUTION=72 4
37 37
 *  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) 4
38
 * 
38
 *
39 39
 *  STATISTICS_MINIMUM=0
40 40
 *  STATISTICS_MAXIMUM=221
41 41
 *  STATISTICS_MEAN=35.910196078431
......
47 47
 *  STATISTICS_HISTOMAX=255
48 48
 *  LAYER_TYPE=athematic
49 49
 *  STATISTICS_HISTOBINVALUES=30285675|0|0|22050| ...
50
 *  
50
 *
51 51
 * @author Nacho Brodin (brodin_ign@gva.es)
52 52
 */
53 53
public class Metadata{
......
75 75
	 * Metadatos
76 76
	 */
77 77
	private String[] 	metadataString = null;
78
	
78

  
79 79
	public Metadata(String[] metadata){
80 80
		metadataString = metadata;
81 81
		for(int i = 0;i<metadata.length;i++){
......
84 84
			this.values.add(value[1]);
85 85
		}
86 86
	}
87
	
87

  
88 88
	/**
89 89
	 * Crea un objeto TransparencyRange a partir de los rangos de transparencia
90 90
	 * @return
......
93 93
		int bandR = getBand("Red");
94 94
		int bandG = getBand("Green");
95 95
		int bandB = getBand("Blue");
96
		
96

  
97 97
		if(bandR < 0 && bandG < 0 && bandB < 0)
98 98
			return null;
99
		
99

  
100 100
		//Esta comprobaci?n es para los raster con paleta (gif). Cuando se trate la paleta y no se usen como
101 101
		//imagenes de una banda habr? que cambiar esto
102 102
		if((colorInterpretation.length == 1) && colorInterpretation[0].equals("Palette"))
103 103
			return null;
104
				
104

  
105 105
		if(noDataByBand == null)
106 106
			return null;
107
		
108
		//Si todos los valores nodata por banda son -1 es que no hay ninguno asignado 
107

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

  
114 114
		if(count == noDataByBand.length)
115 115
			return null;
116
		
116

  
117 117
		TransparencyRange tr = new TransparencyRange();
118 118
		int[] red = new int[2];
119 119
		int[] green = new int[2];
120 120
		int[] blue = new int[2];
121
		
121

  
122 122
		if(bandR >= 0){
123 123
			red[0] = red[1] = (int)noDataByBand[bandR];
124 124
			tr.setRed(red);
......
131 131
			blue[0] = blue[1] = (int)noDataByBand[bandB];
132 132
			tr.setBlue(blue);
133 133
		}
134
		
134

  
135 135
		tr.setAnd(true);
136 136
		tr.loadStrEntryFromValues();
137
		
137

  
138 138
		return tr;
139 139
	}
140
	
140

  
141 141
	/**
142
	 * Parsea los metadatos NODATA_VALUES si existe alguno y devuelve un objeto TransparencyRange. 
142
	 * Parsea los metadatos NODATA_VALUES si existe alguno y devuelve un objeto TransparencyRange.
143 143
	 * @param nodata
144 144
	 * @return Vector de enteros con los valores RGBA o null si no tiene este metadato o no es parseable
145 145
	 * en este formato.
......
149 149
		//imagenes de una banda habr? que cambiar esto
150 150
		if((colorInterpretation.length == 1) && colorInterpretation[0].equals("Palette"))
151 151
			return null;
152
		
152

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

  
161 161
		TransparencyRange[] trList = new TransparencyRange[count];
162
		
162

  
163 163
		count = 0;
164 164
		for(int i = 0; i < metadata.size(); i++){
165 165
			TransparencyRange tr = new TransparencyRange();
166 166
			int[] red = new int[2];
167 167
			int[] green = new int[2];
168 168
			int[] blue = new int[2];
169
			
169

  
170 170
			if(((String)metadata.get(i)).equals("NODATA_VALUES")){
171 171
				String data = (String)values.get(i);
172 172
				String[] dataValues = data.split(" ");
173
				int[] values = new int[dataValues.length];
174 173
				try{
175 174
					red[0] = red[1] = Integer.parseInt(dataValues[0]);
176 175
					green[0] = green[1] = Integer.parseInt(dataValues[1]);
......
187 186
			trList[count] = tr;
188 187
			count ++;
189 188
		}
190
		
189

  
191 190
		return trList;
192 191
	}
193
	
192

  
194 193
	/**
195
	 * Inicializa el vector de cadenas que contendr?n el nombre de la interpretaci?n 
194
	 * Inicializa el vector de cadenas que contendr?n el nombre de la interpretaci?n
196 195
	 * de color asignada a cada banda. Este valor es el devuelto por la imagen.
197 196
	 * @param values N?mero de valores
198 197
	 */
199 198
	public void initColorInterpretation(int values){
200 199
		colorInterpretation = new String[values];
201 200
	}
202
	
201

  
203 202
	/**
204 203
	 * Asigna un valor para la interpretaci?n de color de una banda
205
	 * @param band Banda 
204
	 * @param band Banda
206 205
	 * @param value valor
207 206
	 */
208 207
	public void setColorInterpValue(int band, String value){
......
214 213
			//No asignamos el elemento
215 214
		}
216 215
	}
217
	
216

  
218 217
	/**
219
	 * Obtiene la posici?n de la banda que contiene el identificador pasado por par?metro 
218
	 * Obtiene la posici?n de la banda que contiene el identificador pasado por par?metro
220 219
	 * o -1 si no tiene dicho identificador.
221 220
	 * @return Posici?n de la banda que contiene el identificador o -1 si no lo tiene.
222 221
	 */
......
236 235
	public boolean isAlphaBand() {
237 236
		return isAlphaBand;
238 237
	}
239
	
238

  
240 239
	/**
241 240
	 * Inicializa los valores no data;
242 241
	 * @param values
......
246 245
		for(int i = 0; i < values; i++)
247 246
			noDataByBand[i] = -1;
248 247
	}
249
	
248

  
250 249
	/**
251 250
	 * Asigna un valor para el valor noData por banda
252
	 * @param band Banda 
251
	 * @param band Banda
253 252
	 * @param value valor
254 253
	 */
255 254
	public void setNoDataValue(int band, double value){
......
267 266
	public String[] getMetadataString() {
268 267
		return metadataString;
269 268
	}
270
	
269

  
271 270
}

Also available in: Unified diff