Revision 13130 trunk/libraries/libCresques/src/org/cresques/io/GdalFile.java
GdalFile.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.io; |
... | ... | |
50 | 50 |
* Probablemente esto deber?a formar parte del JNI que recubre a la |
51 | 51 |
* librer?a en C extraida de gdal.<br> |
52 | 52 |
* Lo pongo aqu? a manera de ejemplo de como atacar un formato binario |
53 |
* desde Java.<br><br>
|
|
53 |
* desde Java.<br><br> |
|
54 | 54 |
* @author Luis W. Sevilla. |
55 | 55 |
*/ |
56 | 56 |
|
57 | 57 |
class GdalNative extends Gdal { |
58 | 58 |
static boolean WITH_OVERVIEWS = true; |
59 | 59 |
private String ext = ""; |
60 |
/** |
|
61 |
* Nombre corto del driver de gdal |
|
62 |
*/ |
|
63 |
private String shortName = ""; |
|
64 | 60 |
public GeoTransform trans = null; |
65 | 61 |
/** |
66 | 62 |
* Contorno en coordenadas geogr?ficas. (y Extent del raster). |
... | ... | |
68 | 64 |
public Contour bBoxRot = new Contour(); |
69 | 65 |
/** |
70 | 66 |
* Contorno en coordenadas geogr?ficas sin rotaci?n aplicada. Esto es util para poder |
71 |
* calcular los pixeles necesarios que se van a leer del raster. Cuando el raster no tiene
|
|
72 |
* rotaci?n coincide con esq.
|
|
67 |
* calcular los pixeles necesarios que se van a leer del raster. Cuando el raster no tiene |
|
68 |
* rotaci?n coincide con esq. |
|
73 | 69 |
*/ |
74 | 70 |
public Contour bBoxWithoutRot = new Contour(); |
75 | 71 |
public int width = 0, height = 0; |
... | ... | |
84 | 80 |
private Metadata metadata = null; |
85 | 81 |
private boolean georeferenced = true; |
86 | 82 |
|
87 |
|
|
83 |
|
|
88 | 84 |
// Polilinea con extent |
89 | 85 |
public class Contour extends Vector { |
90 | 86 |
final private static long serialVersionUID = -3370601314380922368L; |
... | ... | |
101 | 97 |
if (pt.getY() < minY) minY = pt.getY(); |
102 | 98 |
} |
103 | 99 |
} |
104 |
|
|
100 |
|
|
105 | 101 |
public GdalNative(String fName) throws GdalException, IOException { |
106 | 102 |
super(); |
107 | 103 |
init(fName); |
108 | 104 |
} |
109 |
|
|
105 |
|
|
110 | 106 |
/** |
111 | 107 |
* <P> |
112 | 108 |
* Calcula la bounding box en la que est? metido el raster teniendo en cuenta |
113 |
* el tama?o de pixel y la rotaci?n. Esto lo hace con los valores de transformaci?n
|
|
109 |
* el tama?o de pixel y la rotaci?n. Esto lo hace con los valores de transformaci?n |
|
114 | 110 |
* leidos por gdal en el vector de 6 elementos adfGeoTransform donde cada elemento |
115 | 111 |
* del vector represnta los siguientes valores |
116 | 112 |
* </P> |
... | ... | |
128 | 124 |
* PtoY = originY + shearY * x + pixelSizeY * y;<BR> |
129 | 125 |
* Aplicandolo a las cuatro esquinas sustituimos en cada una de ellas por. |
130 | 126 |
* </P> |
131 |
* <UL>
|
|
127 |
* <UL> |
|
132 | 128 |
* <LI>Esquina superior izquierda: x = 0; y = 0;</LI> |
133 | 129 |
* <LI>Esquina superior derecha: x = MaxX; y = 0;</LI> |
134 | 130 |
* <LI>Esquina inferior izquierda: x = 0; y = MaxY;</LI> |
135 | 131 |
* <LI>Esquina inferior derecha: x = MaxX; y = MaxY;</LI> |
136 |
* </UL>
|
|
132 |
* </UL> |
|
137 | 133 |
* <P> |
138 | 134 |
* quedandonos en los cuatro casos: |
139 | 135 |
* </P> |
140 |
* <UL>
|
|
136 |
* <UL> |
|
141 | 137 |
* <LI>Esquina superior izquierda: originX; originY;</LI> |
142 | 138 |
* <LI>Esquina superior derecha: PtoX = originX + pixelSizeX * x; PtoY = originY + shearY * x;</LI> |
143 | 139 |
* <LI>Esquina inferior izquierda: PtoX = originX + shearX * y; PtoY = originY + pixelSizeY * y;</LI> |
144 | 140 |
* <LI>Esquina inferior derecha: PtoX = originX + pixelSizeX * x + shearX * y; PtoY = originY + shearY * x + pixelSizeY * y;</LI> |
145 | 141 |
* </UL> |
146 |
*
|
|
142 |
* |
|
147 | 143 |
*/ |
148 | 144 |
private void boundingBoxFromGeoTransform(){ |
149 | 145 |
double geoX = 0D, geoY = 0D; |
... | ... | |
155 | 151 |
geoX = trans.adfgeotransform[0] + trans.adfgeotransform[2] * height; |
156 | 152 |
geoY = trans.adfgeotransform[3] + trans.adfgeotransform[5] * height; |
157 | 153 |
bBoxRot.add(new Point2D.Double(geoX, geoY)); |
158 |
|
|
154 |
|
|
159 | 155 |
//Upper right corner |
160 | 156 |
geoX = trans.adfgeotransform[0] + trans.adfgeotransform[1] * width; |
161 | 157 |
geoY = trans.adfgeotransform[3] + trans.adfgeotransform[4] * width; |
162 | 158 |
bBoxRot.add(new Point2D.Double(geoX, geoY)); |
163 |
|
|
159 |
|
|
164 | 160 |
//Lower right corner |
165 | 161 |
geoX = trans.adfgeotransform[0] + trans.adfgeotransform[1] * width + trans.adfgeotransform[2] * height; |
166 | 162 |
geoY = trans.adfgeotransform[3] + trans.adfgeotransform[4] * width + trans.adfgeotransform[5] * height; |
167 | 163 |
bBoxRot.add(new Point2D.Double(geoX, geoY)); |
168 |
|
|
164 |
|
|
169 | 165 |
//TODO: ?OJO! con coordenadas geogr?ficas |
170 | 166 |
} |
171 |
|
|
167 |
|
|
172 | 168 |
/** |
173 | 169 |
* Calcula la bounding box en la que est? metido el raster teniendo en cuenta |
174 |
* el tama?o de pixel y la rotaci?n.
|
|
170 |
* el tama?o de pixel y la rotaci?n. |
|
175 | 171 |
*/ |
176 | 172 |
private void boundingBoxWithoutRotation(){ |
177 | 173 |
double ox = trans.adfgeotransform[0]; |
178 | 174 |
double oy = trans.adfgeotransform[3]; |
179 | 175 |
double resx = trans.adfgeotransform[1]; |
180 | 176 |
double resy = trans.adfgeotransform[5]; |
181 |
|
|
177 |
|
|
182 | 178 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy)); |
183 | 179 |
bBoxWithoutRot.add(new Point2D.Double(ox + resx * width, oy)); |
184 | 180 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy + resy * height)); |
... | ... | |
186 | 182 |
|
187 | 183 |
//TODO: ?OJO! con coordenadas geogr?ficas |
188 | 184 |
} |
189 |
|
|
185 |
|
|
190 | 186 |
private void init(String fName) throws GdalException, IOException { |
191 | 187 |
open(fName,GA_ReadOnly); |
192 | 188 |
ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1); |
... | ... | |
195 | 191 |
width = getRasterXSize(); |
196 | 192 |
height = getRasterYSize(); |
197 | 193 |
setDataType(this.getRasterBand(1).getRasterDataType()); |
198 |
shortName = getDriverShortName(); |
|
199 | 194 |
metadata = new Metadata(getMetadata()); |
200 |
|
|
195 |
|
|
201 | 196 |
//Asignamos la interpretaci?n de color leida por gdal a cada banda. Esto nos sirve |
202 | 197 |
//para saber que banda de la imagen va asignada a cada banda de visualizaci?n (ARGB) |
203 | 198 |
metadata.initColorInterpretation(getRasterCount()); |
204 | 199 |
metadata.initNoDataByBand(getRasterCount()); |
205 |
for(int i = 0; i < getRasterCount(); i++){ |
|
206 |
GdalRasterBand rb = getRasterBand(i + 1); |
|
207 |
String colorInt = getColorInterpretationName(rb.getRasterColorInterpretation()); |
|
208 |
metadata.setNoDataValue(i, rb.getRasterNoDataValue()); |
|
209 |
metadata.setColorInterpValue(i, colorInt); |
|
210 |
if(colorInt.equals("Red")) |
|
211 |
rBandNr = i + 1; |
|
212 |
if(colorInt.equals("Green")) |
|
213 |
gBandNr = i + 1; |
|
214 |
if(colorInt.equals("Blue")) |
|
215 |
bBandNr = i + 1; |
|
216 |
if(colorInt.equals("Alpha")) |
|
217 |
aBandNr = i + 1; |
|
218 |
} |
|
219 |
|
|
220 |
double ox=0D, oy=0D, resx=0D, resy=0D; |
|
200 |
for(int i = 0; i < getRasterCount(); i++){ |
|
201 |
GdalRasterBand rb = getRasterBand(i + 1); |
|
202 |
String colorInt = getColorInterpretationName(rb.getRasterColorInterpretation()); |
|
203 |
metadata.setNoDataValue(i, rb.getRasterNoDataValue()); |
|
204 |
metadata.setColorInterpValue(i, colorInt); |
|
205 |
if(colorInt.equals("Red")) |
|
206 |
rBandNr = i + 1; |
|
207 |
if(colorInt.equals("Green")) |
|
208 |
gBandNr = i + 1; |
|
209 |
if(colorInt.equals("Blue")) |
|
210 |
bBandNr = i + 1; |
|
211 |
if(colorInt.equals("Alpha")) |
|
212 |
aBandNr = i + 1; |
|
213 |
} |
|
214 |
|
|
221 | 215 |
try{ |
222 | 216 |
trans = getGeoTransform(); |
223 |
|
|
217 |
|
|
224 | 218 |
boundingBoxWithoutRotation(); |
225 | 219 |
boundingBoxFromGeoTransform(); |
226 |
|
|
220 |
|
|
227 | 221 |
this.georeferenced = true; |
228 | 222 |
}catch(GdalException exc){ |
229 | 223 |
bBoxRot.add(new Point2D.Double(0, 0)); |
... | ... | |
234 | 228 |
this.georeferenced = false; |
235 | 229 |
} |
236 | 230 |
} |
237 |
|
|
231 |
|
|
238 | 232 |
public void setAlpha(int a) { alpha = a; } |
239 |
|
|
233 |
|
|
240 | 234 |
public void setDataType(int dt) { dataType = dt; } |
241 | 235 |
public int getDataType() { return dataType; } |
242 |
|
|
236 |
|
|
243 | 237 |
double lastReadLine = -1; |
244 | 238 |
int currentFullWidth = -1; |
245 | 239 |
int currentFullHeight = -1; |
... | ... | |
253 | 247 |
double stepX = 0D; |
254 | 248 |
double stepY = 0D; |
255 | 249 |
int currentOverview = -1; |
256 |
|
|
250 |
|
|
257 | 251 |
protected GdalRasterBand bandR = null, bandG = null, bandB = null, bandA = null; |
258 |
|
|
252 |
|
|
259 | 253 |
private boolean[] orientation; |
260 |
|
|
254 |
|
|
261 | 255 |
/** |
262 | 256 |
* Devuelve la banda actualmente en uso para el color especificado. |
263 | 257 |
* @param color 0=Rojo, 1=Green, 2=Blue. |
264 | 258 |
* @return |
265 | 259 |
*/ |
266 | 260 |
public GdalRasterBand getCurrentBand(int color) { |
267 |
if (color == 0)
|
|
261 |
if (color == 0) |
|
268 | 262 |
return bandR; |
269 |
else if (color == 1)
|
|
263 |
else if (color == 1) |
|
270 | 264 |
return bandG; |
271 | 265 |
return bandB; |
272 | 266 |
} |
273 |
|
|
267 |
|
|
274 | 268 |
//Supone rasters no girados |
275 | 269 |
public Point2D worldToRaster(Point2D pt) { |
276 | 270 |
double x = (((double) currentFullWidth) / (bBoxWithoutRot.maxX - bBoxWithoutRot.minX)) * (pt.getX() - bBoxWithoutRot.minX); |
... | ... | |
278 | 272 |
Point2D ptRes = new Point2D.Double(x, y); |
279 | 273 |
return ptRes; |
280 | 274 |
} |
281 |
|
|
275 |
|
|
282 | 276 |
/** |
283 | 277 |
* Si el tama?o de pixel en X es menor que 0 entonces la imagen se orienta al contrario en X por lo que en los zooms |
284 |
* habr? que invertir la petici?n de la parte derecha a la izquierda y viceversa. Esto lo detectamos con la
|
|
285 |
* variable orientation , si orientation[0] es false entonces el punto inicial del zoom lo invertimos de la
|
|
278 |
* habr? que invertir la petici?n de la parte derecha a la izquierda y viceversa. Esto lo detectamos con la |
|
279 |
* variable orientation , si orientation[0] es false entonces el punto inicial del zoom lo invertimos de la |
|
286 | 280 |
* siguiente forma: |
287 | 281 |
* Nuevo_punto_inicialX = (Ancho_total_raster - punto_inicial_del_zoomX) - Ancho_de_petici?n |
288 | 282 |
* |
289 |
* Si el tama?o de pixel en Y es mayor que 0 entonces la imagen se orienta al contrario en Y por
|
|
290 |
* lo que en los zooms habr? que invertir la petici?n de abajo a arriba y viceversa. Esto lo detectamos con la
|
|
291 |
* variable orientation , si orientation[1] es true entonces el punto inicial del zoom lo invertimos de la
|
|
283 |
* Si el tama?o de pixel en Y es mayor que 0 entonces la imagen se orienta al contrario en Y por |
|
284 |
* lo que en los zooms habr? que invertir la petici?n de abajo a arriba y viceversa. Esto lo detectamos con la |
|
285 |
* variable orientation , si orientation[1] es true entonces el punto inicial del zoom lo invertimos de la |
|
292 | 286 |
* siguiente forma: |
293 | 287 |
* Nuevo_punto_inicialY = (Alto_total_raster - punto_inicial_del_zoomY) - Alto_de_petici?n |
294 |
*
|
|
288 |
* |
|
295 | 289 |
* @param dWorldTLX |
296 | 290 |
* @param dWorldTLY |
297 | 291 |
* @param dWorldBRX |
... | ... | |
304 | 298 |
* @return |
305 | 299 |
*/ |
306 | 300 |
public int setView(double dWorldTLX, double dWorldTLY, |
307 |
double dWorldBRX, double dWorldBRY,
|
|
308 |
int nWidth, int nHeight, boolean[] orientation) {
|
|
301 |
double dWorldBRX, double dWorldBRY,
|
|
302 |
int nWidth, int nHeight, boolean[] orientation) {
|
|
309 | 303 |
int err = 0; |
310 | 304 |
this.orientation = orientation; |
311 | 305 |
currentFullWidth = width; |
... | ... | |
316 | 310 |
currentViewWidth = nWidth; |
317 | 311 |
currentViewHeight = nHeight; |
318 | 312 |
wcWidth = Math.abs(br.getX() - tl.getX()); |
319 |
|
|
313 |
|
|
320 | 314 |
if(!orientation[0]) //Invierte la orientaci?n en X |
321 | 315 |
currentViewX = (width - tl.getX()) - (br.getX()-tl.getX()); |
322 | 316 |
else |
323 | 317 |
currentViewX = tl.getX(); |
324 |
|
|
318 |
|
|
325 | 319 |
viewportScaleX = (double) currentViewWidth/(br.getX()-tl.getX()); |
326 | 320 |
viewportScaleY = (double) currentViewHeight/(br.getY()-tl.getY()); |
327 | 321 |
stepX = 1D/viewportScaleX; |
... | ... | |
331 | 325 |
lastReadLine = (height - tl.getY()) - (br.getY()-tl.getY()); |
332 | 326 |
else |
333 | 327 |
lastReadLine = tl.getY(); |
334 |
|
|
328 |
|
|
335 | 329 |
try { |
336 | 330 |
// calcula el overview a usar |
337 | 331 |
bandR = getRasterBand(1); |
338 | 332 |
currentOverview = -1; |
339 | 333 |
if (WITH_OVERVIEWS && bandR.getOverviewCount() > 0) { |
340 | 334 |
GdalRasterBand ovb = null; |
341 |
for (int i=bandR.getOverviewCount()-1; i>0; i--) {
|
|
335 |
for (int i=bandR.getOverviewCount()-1; i>0; i--) { |
|
342 | 336 |
ovb = bandR.getOverview(i); |
343 | 337 |
if (ovb.getRasterBandXSize()>getRasterXSize()*viewportScaleX) { |
344 | 338 |
currentOverview = i; |
345 |
viewportScaleX *= ((double) width/(double) ovb.getRasterBandXSize());
|
|
346 |
viewportScaleY *= ((double) height/(double) ovb.getRasterBandYSize());
|
|
347 |
stepX = 1D/viewportScaleX;
|
|
348 |
stepY = 1D/viewportScaleY;
|
|
349 |
currentFullWidth = ovb.getRasterBandXSize();
|
|
350 |
currentFullHeight = ovb.getRasterBandYSize();
|
|
351 |
tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY));
|
|
352 |
if(!orientation[0])//Invierte la orientaci?n en X
|
|
353 |
currentViewX = (width - tl.getX()) - (br.getX()-tl.getX());
|
|
354 |
else
|
|
355 |
currentViewX = tl.getX();
|
|
356 |
if(orientation[1])//Invierte la orientaci?n en Y
|
|
357 |
lastReadLine = (height - tl.getY()) - (br.getY()-tl.getY());
|
|
358 |
else
|
|
359 |
lastReadLine = tl.getY();
|
|
360 |
break;
|
|
339 |
viewportScaleX *= ((double) width/(double) ovb.getRasterBandXSize());
|
|
340 |
viewportScaleY *= ((double) height/(double) ovb.getRasterBandYSize());
|
|
341 |
stepX = 1D/viewportScaleX;
|
|
342 |
stepY = 1D/viewportScaleY;
|
|
343 |
currentFullWidth = ovb.getRasterBandXSize();
|
|
344 |
currentFullHeight = ovb.getRasterBandYSize();
|
|
345 |
tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY));
|
|
346 |
if(!orientation[0])//Invierte la orientaci?n en X
|
|
347 |
currentViewX = (width - tl.getX()) - (br.getX()-tl.getX());
|
|
348 |
else
|
|
349 |
currentViewX = tl.getX();
|
|
350 |
if(orientation[1])//Invierte la orientaci?n en Y
|
|
351 |
lastReadLine = (height - tl.getY()) - (br.getY()-tl.getY());
|
|
352 |
else
|
|
353 |
lastReadLine = tl.getY();
|
|
354 |
break;
|
|
361 | 355 |
} |
362 | 356 |
} |
363 | 357 |
} |
364 |
|
|
358 |
|
|
365 | 359 |
// Selecciona las bandas y los overviews necesarios |
366 | 360 |
bandR = getRasterBand(rBandNr); |
367 | 361 |
setDataType(bandR.getRasterDataType()); |
368 |
|
|
362 |
|
|
369 | 363 |
if (this.getRasterCount() > 1) { |
370 | 364 |
bandG = getRasterBand(gBandNr); |
371 |
bandB = getRasterBand(bBandNr);
|
|
365 |
bandB = getRasterBand(bBandNr); |
|
372 | 366 |
if(metadata.isAlphaBand()) |
373 |
bandA = getRasterBand(aBandNr);
|
|
367 |
bandA = getRasterBand(aBandNr); |
|
374 | 368 |
} |
375 | 369 |
if (currentOverview > 0) { |
376 | 370 |
bandR = bandR.getOverview(currentOverview); |
377 |
if (this.getRasterCount() > 1) {
|
|
371 |
if (this.getRasterCount() > 1) {
|
|
378 | 372 |
bandG = bandG.getOverview(currentOverview); |
379 | 373 |
bandB = bandB.getOverview(currentOverview); |
380 | 374 |
if(metadata.isAlphaBand()) |
... | ... | |
387 | 381 |
} |
388 | 382 |
return err; |
389 | 383 |
} |
390 |
|
|
384 |
|
|
391 | 385 |
int lastY = -1; |
392 |
|
|
386 |
|
|
393 | 387 |
public void readLine(int[][] line) throws GdalException { |
394 |
int w = (int) (Math.ceil(((double)currentViewWidth)*stepX) + 1);
|
|
395 |
int x = (int) Math.ceil(currentViewX);
|
|
396 |
int y = (int) Math.ceil(lastReadLine);
|
|
397 |
GdalBuffer r = null, g = null, b = null, p = null;
|
|
398 |
GdalBuffer a = new GdalBuffer();
|
|
399 |
|
|
400 |
//if (alpha > 0) a = alpha << 24;
|
|
401 |
if (x+w > bandR.getRasterBandXSize())
|
|
402 |
w = bandR.getRasterBandXSize()-x;
|
|
403 |
|
|
404 |
if(bandR.getRasterColorTable() != null){
|
|
405 |
p = bandR.readRasterWithPalette(x, y, w, 1, w, 1, dataType);
|
|
406 |
a.buffByte = p.buffAPalette;
|
|
407 |
r = new GdalBuffer();
|
|
408 |
r.buffByte = p.buffRPalette;
|
|
409 |
g = new GdalBuffer();
|
|
410 |
g.buffByte = p.buffGPalette;
|
|
411 |
b = new GdalBuffer();
|
|
412 |
b.buffByte = p.buffBPalette;
|
|
413 |
}else{
|
|
414 |
a.buffByte = new byte[w];
|
|
388 |
int w = (int) (Math.ceil(((double)currentViewWidth)*stepX) + 1);
|
|
389 |
int x = (int) Math.ceil(currentViewX);
|
|
390 |
int y = (int) Math.ceil(lastReadLine);
|
|
391 |
GdalBuffer r = null, g = null, b = null, p = null;
|
|
392 |
GdalBuffer a = new GdalBuffer();
|
|
393 |
|
|
394 |
//if (alpha > 0) a = alpha << 24;
|
|
395 |
if (x+w > bandR.getRasterBandXSize())
|
|
396 |
w = bandR.getRasterBandXSize()-x;
|
|
397 |
|
|
398 |
if(bandR.getRasterColorTable() != null){
|
|
399 |
p = bandR.readRasterWithPalette(x, y, w, 1, w, 1, dataType);
|
|
400 |
a.buffByte = p.buffAPalette;
|
|
401 |
r = new GdalBuffer();
|
|
402 |
r.buffByte = p.buffRPalette;
|
|
403 |
g = new GdalBuffer();
|
|
404 |
g.buffByte = p.buffGPalette;
|
|
405 |
b = new GdalBuffer();
|
|
406 |
b.buffByte = p.buffBPalette;
|
|
407 |
}else{
|
|
408 |
a.buffByte = new byte[w];
|
|
415 | 409 |
r = bandR.readRaster(x, y, w, 1, w, 1, dataType); |
416 | 410 |
if (bandG != null) |
417 |
g = bandG.readRaster(x, y, w, 1, w, 1, dataType);
|
|
411 |
g = bandG.readRaster(x, y, w, 1, w, 1, dataType);
|
|
418 | 412 |
if (bandB != null) |
419 |
b = bandB.readRaster(x, y, w, 1, w, 1, dataType);
|
|
420 |
}
|
|
421 |
|
|
413 |
b = bandB.readRaster(x, y, w, 1, w, 1, dataType);
|
|
414 |
}
|
|
415 |
|
|
422 | 416 |
lastReadLine += stepY; |
423 |
|
|
424 |
int i=0;
|
|
425 |
double j = 0D;
|
|
426 |
double initOffset = Math.abs(currentViewX - ((int)currentViewX));
|
|
427 |
|
|
428 |
if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16){
|
|
429 |
if (g == null){ // Sibgle Band (Typical DEM)
|
|
430 |
for (int k=0; k<4; k++){
|
|
431 |
for (i=0, j = initOffset; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
432 |
if(k<3)
|
|
433 |
line[i][k] = (r.buffShort[(int) j] & 0xffff);
|
|
434 |
else
|
|
435 |
line[i][3] = 0xff;
|
|
436 |
}
|
|
437 |
}
|
|
438 |
}else { // Multiband
|
|
439 |
//System.err.println("readLine(): Raster 16bits multibanda");
|
|
440 |
GdalBuffer [] bands = {r,g,b};
|
|
441 |
for (int k=0; k<4; k++){
|
|
442 |
for (i=0, j = initOffset; i<currentViewWidth && j<r.getSize(); i++, j+=stepX){
|
|
443 |
if(k<3)
|
|
444 |
line[i][k] = (bands[k].buffShort[(int) j] & 0xffff);
|
|
445 |
else
|
|
446 |
line[i][3] = 0xff;
|
|
447 |
}
|
|
448 |
}
|
|
449 |
}
|
|
450 |
}else if(dataType == GDT_Float32){
|
|
451 |
GdalBuffer [] bands = {r,g,b};
|
|
417 |
|
|
418 |
int i=0;
|
|
419 |
double j = 0D;
|
|
420 |
double initOffset = Math.abs(currentViewX - ((int)currentViewX));
|
|
421 |
|
|
422 |
if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16){
|
|
423 |
if (g == null){ // Sibgle Band (Typical DEM)
|
|
424 |
for (int k=0; k<4; k++){
|
|
425 |
for (i=0, j = initOffset; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
426 |
if(k<3)
|
|
427 |
line[i][k] = (r.buffShort[(int) j] & 0xffff);
|
|
428 |
else
|
|
429 |
line[i][3] = 0xff;
|
|
430 |
}
|
|
431 |
}
|
|
432 |
}else { // Multiband
|
|
433 |
//System.err.println("readLine(): Raster 16bits multibanda");
|
|
434 |
GdalBuffer [] bands = {r,g,b};
|
|
435 |
for (int k=0; k<4; k++){
|
|
436 |
for (i=0, j = initOffset; i<currentViewWidth && j<r.getSize(); i++, j+=stepX){
|
|
437 |
if(k<3)
|
|
438 |
line[i][k] = (bands[k].buffShort[(int) j] & 0xffff);
|
|
439 |
else
|
|
440 |
line[i][3] = 0xff;
|
|
441 |
}
|
|
442 |
}
|
|
443 |
}
|
|
444 |
}else if(dataType == GDT_Float32){
|
|
445 |
GdalBuffer [] bands = {r,g,b};
|
|
452 | 446 |
for (int k=0; k<4; k++){ |
453 |
for (i=0, j = initOffset; i<currentViewWidth && j<r.getSize(); i++, j+=stepX){
|
|
454 |
if(k < 3)
|
|
455 |
line[i][k] = (int)bands[0].buffFloat[(int) j];
|
|
456 |
else
|
|
457 |
line[i][3] = 0xff;
|
|
458 |
}
|
|
447 |
for (i=0, j = initOffset; i<currentViewWidth && j<r.getSize(); i++, j+=stepX){
|
|
448 |
if(k < 3)
|
|
449 |
line[i][k] = (int)bands[0].buffFloat[(int) j];
|
|
450 |
else
|
|
451 |
line[i][3] = 0xff;
|
|
452 |
}
|
|
459 | 453 |
} |
460 |
}
|
|
461 |
|
|
454 |
}
|
|
455 |
|
|
462 | 456 |
return; |
463 | 457 |
} |
464 |
|
|
458 |
|
|
465 | 459 |
//int liney = 0; |
466 | 460 |
int readLineRGBA(int [] line) throws GdalException { |
467 | 461 |
int err = 0; |
468 |
|
|
469 |
int w = (int) (Math.ceil(((double)currentViewWidth)*stepX) + 1);
|
|
470 |
int x = (int) currentViewX;
|
|
471 |
int y = (int) lastReadLine;
|
|
472 |
GdalBuffer r = null, g = null, b = null, p = null;
|
|
473 |
GdalBuffer a = new GdalBuffer();
|
|
474 |
|
|
475 |
while(y >= bandR.getRasterBandYSize())
|
|
476 |
y--;
|
|
477 |
|
|
478 |
//if (alpha > 0) a = alpha << 24;
|
|
479 |
if (x+w > bandR.getRasterBandXSize())
|
|
480 |
w = bandR.getRasterBandXSize()-x;
|
|
481 |
|
|
482 |
if(bandR.getRasterColorTable() != null){
|
|
483 |
p = bandR.readRasterWithPalette(x, y, w, 1, w, 1, dataType);
|
|
484 |
a.buffByte = p.buffAPalette;
|
|
485 |
r = new GdalBuffer();
|
|
486 |
r.buffByte = p.buffRPalette;
|
|
487 |
g = new GdalBuffer();
|
|
488 |
g.buffByte = p.buffGPalette;
|
|
489 |
b = new GdalBuffer();
|
|
490 |
b.buffByte = p.buffBPalette;
|
|
491 |
}else{
|
|
492 |
r = bandR.readRaster(x, y, w, 1, w, 1, dataType);
|
|
462 |
|
|
463 |
int w = (int) (Math.ceil(((double)currentViewWidth)*stepX) + 1);
|
|
464 |
int x = (int) currentViewX;
|
|
465 |
int y = (int) lastReadLine;
|
|
466 |
GdalBuffer r = null, g = null, b = null, p = null;
|
|
467 |
GdalBuffer a = new GdalBuffer();
|
|
468 |
|
|
469 |
while(y >= bandR.getRasterBandYSize())
|
|
470 |
y--;
|
|
471 |
|
|
472 |
//if (alpha > 0) a = alpha << 24;
|
|
473 |
if (x+w > bandR.getRasterBandXSize())
|
|
474 |
w = bandR.getRasterBandXSize()-x;
|
|
475 |
|
|
476 |
if(bandR.getRasterColorTable() != null){
|
|
477 |
p = bandR.readRasterWithPalette(x, y, w, 1, w, 1, dataType);
|
|
478 |
a.buffByte = p.buffAPalette;
|
|
479 |
r = new GdalBuffer();
|
|
480 |
r.buffByte = p.buffRPalette;
|
|
481 |
g = new GdalBuffer();
|
|
482 |
g.buffByte = p.buffGPalette;
|
|
483 |
b = new GdalBuffer();
|
|
484 |
b.buffByte = p.buffBPalette;
|
|
485 |
}else{
|
|
486 |
r = bandR.readRaster(x, y, w, 1, w, 1, dataType);
|
|
493 | 487 |
if (bandG != null) |
494 |
g = bandG.readRaster(x, y, w, 1, w, 1, dataType);
|
|
488 |
g = bandG.readRaster(x, y, w, 1, w, 1, dataType);
|
|
495 | 489 |
if (bandB != null) |
496 |
b = bandB.readRaster(x, y, w, 1, w, 1, dataType);
|
|
497 |
|
|
498 |
if(metadata.isAlphaBand()){
|
|
499 |
//if(getRasterCount() == 4 && shortName.equals("PNG")){
|
|
500 |
a = bandA.readRaster(x, y, w, 1, w, 1, GDT_Byte);
|
|
501 |
}else{
|
|
502 |
a.buffByte = new byte[w];
|
|
503 |
for (int i = 0;i < w;i++)
|
|
504 |
a.buffByte[i] = (byte)255;
|
|
505 |
}
|
|
506 |
}
|
|
507 |
|
|
508 |
lastReadLine += stepY;
|
|
509 |
|
|
510 |
int i=0;
|
|
511 |
double j = Math.abs(currentViewX - ((int)currentViewX));
|
|
490 |
b = bandB.readRaster(x, y, w, 1, w, 1, dataType);
|
|
491 |
|
|
492 |
if(metadata.isAlphaBand()){
|
|
493 |
//if(getRasterCount() == 4 && shortName.equals("PNG")){
|
|
494 |
a = bandA.readRaster(x, y, w, 1, w, 1, GDT_Byte);
|
|
495 |
}else{
|
|
496 |
a.buffByte = new byte[w];
|
|
497 |
for (int i = 0;i < w;i++)
|
|
498 |
a.buffByte[i] = (byte)255;
|
|
499 |
}
|
|
500 |
}
|
|
501 |
|
|
502 |
lastReadLine += stepY;
|
|
503 |
|
|
504 |
int i=0;
|
|
505 |
double j = Math.abs(currentViewX - ((int)currentViewX));
|
|
512 | 506 |
int alpha = (this.alpha & 0xff) << 24; |
513 | 507 |
|
514 | 508 |
if(orientation[0]){ //Pixel size en X positivo |
515 |
if (dataType == GDT_Byte){
|
|
516 |
if (g != null)
|
|
517 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
518 |
int jInt = (int)(j);
|
|
519 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((g.buffByte[jInt] & 0xff) << 8) + (b.buffByte[jInt] & 0xff);
|
|
520 |
}
|
|
521 |
else
|
|
522 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
523 |
int jInt = (int)(j);
|
|
524 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((r.buffByte[jInt] & 0xff) << 8) + (r.buffByte[jInt] & 0xff);
|
|
525 |
}
|
|
526 |
}else if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16){
|
|
527 |
if (g == null) // Sibgle Band (Typical DEM)
|
|
528 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
529 |
int jInt = (int)(j);
|
|
530 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + r.buffShort[jInt];
|
|
531 |
}
|
|
532 |
else { // Multiband - Raster 16bits multibanda
|
|
533 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
534 |
int jInt = (int)(j);
|
|
535 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) | (((r.buffShort[jInt] & 0xfff0) << 12) & 0xff0000 ) |
|
|
536 |
(((g.buffShort[jInt] & 0xfff0) << 4 ) & 0xff00 ) |
|
|
537 |
(((b.buffShort[jInt] & 0xfff0) >> 4 ) & 0xff );
|
|
538 |
}
|
|
539 |
}
|
|
540 |
}
|
|
509 |
if (dataType == GDT_Byte){
|
|
510 |
if (g != null)
|
|
511 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
512 |
int jInt = (int)(j);
|
|
513 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((g.buffByte[jInt] & 0xff) << 8) + (b.buffByte[jInt] & 0xff);
|
|
514 |
}
|
|
515 |
else
|
|
516 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
517 |
int jInt = (int)(j);
|
|
518 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((r.buffByte[jInt] & 0xff) << 8) + (r.buffByte[jInt] & 0xff);
|
|
519 |
}
|
|
520 |
}else if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16){
|
|
521 |
if (g == null) // Sibgle Band (Typical DEM)
|
|
522 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
523 |
int jInt = (int)(j);
|
|
524 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + r.buffShort[jInt];
|
|
525 |
}
|
|
526 |
else { // Multiband - Raster 16bits multibanda
|
|
527 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=stepX) {
|
|
528 |
int jInt = (int)(j);
|
|
529 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) | (((r.buffShort[jInt] & 0xfff0) << 12) & 0xff0000 ) |
|
|
530 |
(((g.buffShort[jInt] & 0xfff0) << 4 ) & 0xff00 ) |
|
|
531 |
(((b.buffShort[jInt] & 0xfff0) >> 4 ) & 0xff );
|
|
532 |
}
|
|
533 |
}
|
|
534 |
}
|
|
541 | 535 |
}else{ //Pixel size en X negativo |
542 | 536 |
if (dataType == GDT_Byte){ |
543 |
if (g != null)
|
|
544 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
545 |
int jInt = (int)(j);
|
|
546 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((g.buffByte[jInt] & 0xff) << 8) + (b.buffByte[jInt] & 0xff);
|
|
547 |
}
|
|
548 |
else
|
|
549 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
550 |
int jInt = (int)(j);
|
|
551 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((r.buffByte[jInt] & 0xff) << 8) + (r.buffByte[jInt] & 0xff);
|
|
552 |
}
|
|
553 |
}else if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16){
|
|
554 |
if (g == null) // Sibgle Band (Typical DEM)
|
|
555 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
556 |
int jInt = (int)(j);
|
|
557 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + r.buffShort[jInt];
|
|
558 |
}
|
|
559 |
else { // Multiband - Raster 16bits multibanda;
|
|
560 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
561 |
int jInt = (int)(j);
|
|
562 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) | (((r.buffShort[jInt] & 0xfff0) << 12) & 0xff0000 ) |
|
|
563 |
(((g.buffShort[jInt] & 0xfff0) << 4 ) & 0xff00 ) |
|
|
564 |
(((b.buffShort[jInt] & 0xfff0) >> 4 ) & 0xff );
|
|
565 |
}
|
|
566 |
}
|
|
567 |
}
|
|
568 |
|
|
537 |
if (g != null)
|
|
538 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
539 |
int jInt = (int)(j);
|
|
540 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((g.buffByte[jInt] & 0xff) << 8) + (b.buffByte[jInt] & 0xff);
|
|
541 |
}
|
|
542 |
else
|
|
543 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
544 |
int jInt = (int)(j);
|
|
545 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + ((r.buffByte[jInt] & 0xff) << 16) + ((r.buffByte[jInt] & 0xff) << 8) + (r.buffByte[jInt] & 0xff);
|
|
546 |
}
|
|
547 |
}else if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16){
|
|
548 |
if (g == null) // Sibgle Band (Typical DEM)
|
|
549 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
550 |
int jInt = (int)(j);
|
|
551 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) + r.buffShort[jInt];
|
|
552 |
}
|
|
553 |
else { // Multiband - Raster 16bits multibanda;
|
|
554 |
for (i=currentViewWidth - 1; i>=0 && j<r.getSize(); i--, j+=stepX) {
|
|
555 |
int jInt = (int)(j);
|
|
556 |
line[i] = (alpha & ((a.buffByte[jInt])& 0xff) << 24) | (((r.buffShort[jInt] & 0xfff0) << 12) & 0xff0000 ) |
|
|
557 |
(((g.buffShort[jInt] & 0xfff0) << 4 ) & 0xff00 ) |
|
|
558 |
(((b.buffShort[jInt] & 0xfff0) >> 4 ) & 0xff );
|
|
559 |
}
|
|
560 |
}
|
|
561 |
}
|
|
562 |
|
|
569 | 563 |
} |
570 | 564 |
|
571 | 565 |
return err; |
572 | 566 |
} |
573 |
|
|
567 |
|
|
574 | 568 |
/** |
575 | 569 |
* Lee una franja de la imagen. |
576 | 570 |
* @param bandH Altura de la franja |
... | ... | |
581 | 575 |
*/ |
582 | 576 |
public int readBandRGBA(int bandH, int bufH, int [] buf) throws GdalException { |
583 | 577 |
int err = 0; |
584 |
int w = (int)(((double)currentViewWidth)*stepX);
|
|
585 |
int x = (int)(((double)currentViewX)*stepX);
|
|
586 |
int y = (int) lastReadLine;
|
|
587 |
int h = (int) (((double)bandH)*stepX);
|
|
588 |
System.out.println("Leyendo "+y);
|
|
589 |
GdalBuffer r = null, g = null, b = null, p = null;
|
|
590 |
GdalBuffer a = new GdalBuffer();
|
|
591 |
|
|
592 |
if (x+w > bandR.getRasterBandXSize())
|
|
593 |
w = bandR.getRasterBandXSize()-x;
|
|
594 |
|
|
595 |
if(bandR.getRasterColorTable() != null){
|
|
596 |
p = bandR.readRasterWithPalette(x, y, w, h, w, h, GDT_Byte);
|
|
597 |
a.buffByte = p.buffAPalette;
|
|
598 |
r = new GdalBuffer();
|
|
599 |
r.buffByte = p.buffRPalette;
|
|
600 |
g = new GdalBuffer();
|
|
601 |
g.buffByte = p.buffGPalette;
|
|
602 |
b = new GdalBuffer();
|
|
603 |
b.buffByte = p.buffBPalette;
|
|
604 |
}else{
|
|
605 |
r = bandR.readRaster(x, y, w, h, w, h, dataType);
|
|
578 |
int w = (int)(((double)currentViewWidth)*stepX);
|
|
579 |
int x = (int)(((double)currentViewX)*stepX);
|
|
580 |
int y = (int) lastReadLine;
|
|
581 |
int h = (int) (((double)bandH)*stepX);
|
|
582 |
System.out.println("Leyendo "+y);
|
|
583 |
GdalBuffer r = null, g = null, b = null, p = null;
|
|
584 |
GdalBuffer a = new GdalBuffer();
|
|
585 |
|
|
586 |
if (x+w > bandR.getRasterBandXSize())
|
|
587 |
w = bandR.getRasterBandXSize()-x;
|
|
588 |
|
|
589 |
if(bandR.getRasterColorTable() != null){
|
|
590 |
p = bandR.readRasterWithPalette(x, y, w, h, w, h, GDT_Byte);
|
|
591 |
a.buffByte = p.buffAPalette;
|
|
592 |
r = new GdalBuffer();
|
|
593 |
r.buffByte = p.buffRPalette;
|
|
594 |
g = new GdalBuffer();
|
|
595 |
g.buffByte = p.buffGPalette;
|
|
596 |
b = new GdalBuffer();
|
|
597 |
b.buffByte = p.buffBPalette;
|
|
598 |
}else{
|
|
599 |
r = bandR.readRaster(x, y, w, h, w, h, dataType);
|
|
606 | 600 |
if (bandG != null) |
607 |
g = bandG.readRaster(x, y, w, h, w, h, dataType);
|
|
601 |
g = bandG.readRaster(x, y, w, h, w, h, dataType);
|
|
608 | 602 |
if (bandB != null) |
609 |
b = bandB.readRaster(x, y, w, h, w, h, dataType);
|
|
610 |
|
|
611 |
if(metadata.isAlphaBand()){
|
|
612 |
//if(getRasterCount() == 4 && shortName.equals("PNG")){
|
|
613 |
a = bandA.readRaster(x, y, w, h, w, h, GDT_Byte);
|
|
614 |
}else{
|
|
615 |
a.buffByte = new byte[w];
|
|
616 |
for (int i = 0;i < w*h;i++)
|
|
617 |
a.buffByte[i] = (byte)255;
|
|
618 |
}
|
|
619 |
}
|
|
620 |
|
|
621 |
lastReadLine += ((double)bandH)*stepY;
|
|
622 |
|
|
623 |
// TODO Acabar de implementarlo
|
|
624 |
float k=0F;
|
|
603 |
b = bandB.readRaster(x, y, w, h, w, h, dataType);
|
|
604 |
|
|
605 |
if(metadata.isAlphaBand()){
|
|
606 |
//if(getRasterCount() == 4 && shortName.equals("PNG")){
|
|
607 |
a = bandA.readRaster(x, y, w, h, w, h, GDT_Byte);
|
|
608 |
}else{
|
|
609 |
a.buffByte = new byte[w];
|
|
610 |
for (int i = 0;i < w*h;i++)
|
|
611 |
a.buffByte[i] = (byte)255;
|
|
612 |
}
|
|
613 |
}
|
|
614 |
|
|
615 |
lastReadLine += ((double)bandH)*stepY;
|
|
616 |
|
|
617 |
// TODO Acabar de implementarlo
|
|
618 |
float k=0F;
|
|
625 | 619 |
int alpha = (this.alpha & 0xff) << 24; |
626 |
for (int j=0, t=0; j<bandH; j++) {
|
|
627 |
k = j*w; t=j*currentViewWidth;
|
|
628 |
for (int i=0; i<currentViewWidth && k<r.getSize(); i++, k+=stepX) {
|
|
629 |
buf[t+i] = (alpha & ((a.buffByte[(int)j])& 0xff) << 24) + ((r.buffByte[(int) k]) << 16) + ((g.buffByte[(int) k]) << 8) + b.buffByte[(int) k];
|
|
630 |
}
|
|
631 |
}
|
|
632 |
|
|
620 |
for (int j=0, t=0; j<bandH; j++) {
|
|
621 |
k = j*w; t=j*currentViewWidth;
|
|
622 |
for (int i=0; i<currentViewWidth && k<r.getSize(); i++, k+=stepX) {
|
|
623 |
buf[t+i] = (alpha & ((a.buffByte[(int)j])& 0xff) << 24) + ((r.buffByte[(int) k]) << 16) + ((g.buffByte[(int) k]) << 8) + b.buffByte[(int) k];
|
|
624 |
}
|
|
625 |
}
|
|
626 |
|
|
633 | 627 |
return err; |
634 |
|
|
628 |
|
|
635 | 629 |
} |
636 | 630 |
|
637 | 631 |
/* (non-Javadoc) |
... | ... | |
664 | 658 |
return null; |
665 | 659 |
} |
666 | 660 |
} |
667 |
|
|
661 |
|
|
668 | 662 |
void pintaInfo() { |
669 | 663 |
try { |
670 | 664 |
//System.out.println("Origin = "+originX+","+originY); |
... | ... | |
679 | 673 |
System.out.println(metadata[i]); |
680 | 674 |
} |
681 | 675 |
} catch (GdalException e) { |
682 |
|
|
676 |
|
|
683 | 677 |
} |
684 |
|
|
678 |
|
|
685 | 679 |
} |
686 |
|
|
680 |
|
|
687 | 681 |
void pintaPaleta() { |
688 | 682 |
} |
689 |
|
|
683 |
|
|
690 | 684 |
public int getBlockSize(){ |
691 | 685 |
return this.getBlockSize(); |
692 | 686 |
} |
... | ... | |
715 | 709 |
protected GdalNative file = null; |
716 | 710 |
|
717 | 711 |
private Extent v = null; |
718 |
|
|
712 |
|
|
719 | 713 |
public GdalFile(IProjection proj, String fName){ |
720 | 714 |
super(proj, fName); |
721 | 715 |
extent = new Extent(); |
... | ... | |
723 | 717 |
file = new GdalNative(fName); |
724 | 718 |
load(); |
725 | 719 |
readGeoInfo(fName); |
726 |
bandCount = file.getRasterCount();
|
|
720 |
bandCount = file.getRasterCount(); |
|
727 | 721 |
if ( bandCount > 2) { |
728 | 722 |
setBand(RED_BAND, 0); |
729 | 723 |
setBand(GREEN_BAND, 1); |
... | ... | |
731 | 725 |
} else |
732 | 726 |
setBand(RED_BAND|GREEN_BAND|BLUE_BAND, 0); |
733 | 727 |
} catch(Exception e){ |
734 |
System.out.println("Error en GdalOpen");
|
|
735 |
e.printStackTrace();
|
|
736 |
file = null;
|
|
728 |
System.out.println("Error en GdalOpen");
|
|
729 |
e.printStackTrace();
|
|
730 |
file = null;
|
|
737 | 731 |
} |
738 |
|
|
732 |
|
|
739 | 733 |
switch(file.getDataType()){ |
740 |
case 1:setDataType(DataBuffer.TYPE_BYTE);break;//GDT_BYTE
|
|
741 |
case 2://GDT_UInt16
|
|
742 |
case 3:setDataType(DataBuffer.TYPE_SHORT);break;//GDT_Int16
|
|
734 |
case 1:setDataType(DataBuffer.TYPE_BYTE);break;//GDT_BYTE |
|
735 |
case 2://GDT_UInt16 |
|
736 |
case 3:setDataType(DataBuffer.TYPE_SHORT);break;//GDT_Int16 |
|
743 | 737 |
case 4://GDT_UInt32 |
744 | 738 |
case 5:setDataType(DataBuffer.TYPE_INT);break;//GDT_Int32 |
745 | 739 |
case 6:setDataType(DataBuffer.TYPE_FLOAT);break;//GDT_Float32 |
... | ... | |
749 | 743 |
case 10:setDataType(DataBuffer.TYPE_UNDEFINED);break;//GDT_CFloat32 |
750 | 744 |
case 11:setDataType(DataBuffer.TYPE_UNDEFINED);break;//GDT_CFloat64 |
751 | 745 |
} |
752 |
|
|
746 |
|
|
753 | 747 |
} |
754 |
|
|
748 |
|
|
755 | 749 |
/** |
756 | 750 |
* Obtenemos o calculamos el extent de la imagen. |
757 | 751 |
*/ |
... | ... | |
760 | 754 |
requestExtent = new Extent(file.bBoxWithoutRot.minX, file.bBoxWithoutRot.minY, file.bBoxWithoutRot.maxX, file.bBoxWithoutRot.maxY); |
761 | 755 |
return this; |
762 | 756 |
} |
763 |
|
|
757 |
|
|
764 | 758 |
/** |
765 | 759 |
* Cierra el fichero de imagen |
766 | 760 |
*/ |
... | ... | |
775 | 769 |
e.printStackTrace(); |
776 | 770 |
} |
777 | 771 |
} |
778 |
|
|
772 |
|
|
779 | 773 |
/** |
780 | 774 |
* Asigna a cada banda R,G o B una banda de la imagen |
781 | 775 |
*/ |
... | ... | |
785 | 779 |
if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) file.gBandNr = bandNr+1; |
786 | 780 |
if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) file.bBandNr = bandNr+1; |
787 | 781 |
} |
788 |
|
|
782 |
|
|
789 | 783 |
/** |
790 | 784 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n |
791 | 785 |
* de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v) |
792 | 786 |
* ha de estar en coordenadas del fichero. |
793 | 787 |
*/ |
794 |
public void setView(Extent e) {
|
|
788 |
public void setView(Extent e) { |
|
795 | 789 |
if(rmfExists){ |
796 |
|
|
790 |
|
|
797 | 791 |
Point2D.Double petInit = null, petEnd = null; |
798 | 792 |
try{ |
799 | 793 |
petInit = new Point2D.Double(e.minX(), e.maxY()); |
... | ... | |
805 | 799 |
}catch(NoninvertibleTransformException ex){} |
806 | 800 |
double h = file.bBoxWithoutRot.maxY - file.bBoxWithoutRot.minY; |
807 | 801 |
if(!file.isGeoreferenced()) |
808 |
v = new Extent( petInit.getX(), h - petInit.getY(), petEnd.getX(), h - petEnd.getY());
|
|
802 |
v = new Extent( petInit.getX(), h - petInit.getY(), petEnd.getX(), h - petEnd.getY()); |
|
809 | 803 |
else |
810 | 804 |
v = new Extent( petInit.getX(), petInit.getY(), petEnd.getX(), petEnd.getY()); |
811 |
|
|
805 |
|
|
812 | 806 |
}else |
813 |
v = new Extent(e.minX(), e.minY(), e.maxX(), e.maxY());
|
|
807 |
v = new Extent(e.minX(), e.minY(), e.maxX(), e.maxY()); |
|
814 | 808 |
} |
815 |
|
|
809 |
|
|
816 | 810 |
/** |
817 | 811 |
* Calcula la transformaci?n que se produce sobre la vista cuando la imagen tiene un fichero .rmf |
818 | 812 |
* asociado. En Gdal el origen de coordenadas en Y es el valor m?nimo y crece hasta el m?ximo. De la |
... | ... | |
820 | 814 |
* @param originX Origen de la imagen en la coordenada X |
821 | 815 |
* @param originY Origen de la imagen en la coordenada Y |
822 | 816 |
*/ |
823 |
public void setExtentTransform(double originX, double originY, double psX, double psY) {
|
|
817 |
public void setExtentTransform(double originX, double originY, double psX, double psY) { |
|
824 | 818 |
transformRMF.setToTranslation(originX, originY); |
825 | 819 |
transformRMF.scale(psX, psY); |
826 |
|
|
827 |
if(file.trans != null){
|
|
820 |
|
|
821 |
if(file.trans != null){ |
|
828 | 822 |
transformTFW.setToTranslation(file.trans.adfgeotransform[0], file.trans.adfgeotransform[3]); |
829 | 823 |
transformTFW.scale(file.trans.adfgeotransform[1], file.trans.adfgeotransform[5]); |
830 | 824 |
} |
831 | 825 |
} |
832 |
|
|
826 |
|
|
833 | 827 |
/** |
834 | 828 |
* Obtiene extent de la vista actual |
835 | 829 |
*/ |
836 |
public Extent getView() {
|
|
837 |
return v;
|
|
830 |
public Extent getView() { |
|
831 |
return v; |
|
838 | 832 |
} |
839 |
|
|
833 |
|
|
840 | 834 |
/** |
841 | 835 |
* Obtiene la anchura del fichero |
842 | 836 |
*/ |
843 |
public int getWidth() {
|
|
844 |
return file.width;
|
|
837 |
public int getWidth() { |
|
838 |
return file.width; |
|
845 | 839 |
} |
846 |
|
|
840 |
|
|
847 | 841 |
/** |
848 | 842 |
* Obtiene la altura del fichero |
849 | 843 |
*/ |
850 |
public int getHeight() {
|
|
844 |
public int getHeight() { |
|
851 | 845 |
return file.height; |
852 | 846 |
} |
853 | 847 |
|
... | ... | |
857 | 851 |
public void reProject(ICoordTrans rp) { |
858 | 852 |
// TODO Auto-generated method stub |
859 | 853 |
} |
860 |
|
|
854 |
|
|
861 | 855 |
/** |
862 | 856 |
* Obtiene la orientaci?n de la imagen a partir del signo del tama?o de pixel para poder |
863 |
* asignarlo en el setView. Esto es util para poder conocer como debe leerse la image,
|
|
864 |
* de abajo a arriba, de arriba a abajo, de izquierda a derecha o de derecha a izquierda.
|
|
865 |
* La posici?n habitual es la que el pixel size en X es positivo y en Y negativo leyendose
|
|
857 |
* asignarlo en el setView. Esto es util para poder conocer como debe leerse la image, |
|
858 |
* de abajo a arriba, de arriba a abajo, de izquierda a derecha o de derecha a izquierda. |
|
859 |
* La posici?n habitual es la que el pixel size en X es positivo y en Y negativo leyendose |
|
866 | 860 |
* en este caso las X de menor a mayor y las Y de mayor a menor. Los casos posibles son: |
867 | 861 |
* <UL> |
868 | 862 |
* <LI><B>X > 0; Y < 0;</B> {true, false}</LI> |
... | ... | |
870 | 864 |
* <LI><B>X < 0; Y > 0;</B> {false, true}</LI> |
871 | 865 |
* <LI><B>X < 0; Y < 0;</B> {false, false}</LI> |
872 | 866 |
* </UL> |
873 |
*
|
|
867 |
* |
|
874 | 868 |
* @return |
875 | 869 |
*/ |
876 | 870 |
private boolean[] getOrientation(){ |
... | ... | |
888 | 882 |
} |
889 | 883 |
return orientation; |
890 | 884 |
} |
891 |
|
|
885 |
|
|
892 | 886 |
/* (non-Javadoc) |
893 | 887 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans) |
894 | 888 |
*/ |
895 | 889 |
public Image updateImage(int width, int height, ICoordTrans rp) { |
896 | 890 |
int line, pRGBArray[] = null; |
897 | 891 |
Image image = null; |
898 |
|
|
892 |
|
|
899 | 893 |
if (mustVerifySize()) { |
900 | 894 |
// Work out the correct aspect for the setView call. |
901 | 895 |
double dFileAspect = (double)v.width()/(double)v.height(); |
902 | 896 |
double dWindowAspect = (double)width /(double)height; |
903 |
|
|
897 |
|
|
904 | 898 |
if (dFileAspect > dWindowAspect) { |
905 |
height =(int)((double)width/dFileAspect);
|
|
899 |
height =(int)((double)width/dFileAspect);
|
|
906 | 900 |
} else { |
907 |
width = (int)((double)height*dFileAspect);
|
|
901 |
width = (int)((double)height*dFileAspect);
|
|
908 | 902 |
} |
909 | 903 |
} |
910 |
|
|
911 |
// Set the view
|
|
904 |
|
|
905 |
// Set the view |
|
912 | 906 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), |
913 | 907 |
width, height, getOrientation()); |
914 |
|
|
908 |
|
|
915 | 909 |
if(width<=0)width=1; |
916 | 910 |
if(height<=0)height=1; |
917 |
|
|
911 |
|
|
918 | 912 |
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
919 | 913 |
//image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
920 | 914 |
pRGBArray = new int[width/**BAND_HEIGHT*/]; |
... | ... | |
934 | 928 |
// TODO Auto-generated catch block |
935 | 929 |
e.printStackTrace(); |
936 | 930 |
} |
937 |
|
|
931 |
|
|
938 | 932 |
return image; |
939 | 933 |
} |
940 |
|
|
934 |
|
|
941 | 935 |
public RasterBuf getRaster(int width, int height, ICoordTrans rp) { |
942 | 936 |
int line; |
943 | 937 |
RasterBuf raster = null; |
944 |
|
|
938 |
|
|
945 | 939 |
if(mustVerifySize()){ |
946 | 940 |
// Work out the correct aspect for the setView call. |
947 | 941 |
double dFileAspect = (double)v.width()/(double)v.height(); |
948 | 942 |
double dWindowAspect = (double)width /(double)height; |
949 |
|
|
943 |
|
|
950 | 944 |
if (dFileAspect > dWindowAspect) { |
951 |
height =(int)((double)width/dFileAspect);
|
|
945 |
height =(int)((double)width/dFileAspect);
|
|
952 | 946 |
} else { |
953 |
width = (int)((double)height*dFileAspect);
|
|
947 |
width = (int)((double)height*dFileAspect);
|
|
954 | 948 |
} |
955 | 949 |
} |
956 |
|
|
950 |
|
|
957 | 951 |
// Set the view |
958 | 952 |
boolean[] orientation = getOrientation(); |
959 | 953 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), |
960 | 954 |
width, height, orientation); |
961 |
|
|
955 |
|
|
962 | 956 |
raster = new RasterBuf(DataBuffer.TYPE_INT, width, height, 4, new Point(0,0)); |
963 | 957 |
try { |
964 | 958 |
|
... | ... | |
972 | 966 |
} catch (Exception e) { |
973 | 967 |
e.printStackTrace(); |
974 | 968 |
} |
975 |
|
|
969 |
|
|
976 | 970 |
return raster; |
977 | 971 |
} |
978 |
|
|
972 |
|
|
979 | 973 |
/** |
980 |
* Asigna al objeto Image los valores con los dato de la imagen contenidos en el
|
|
974 |
* Asigna al objeto Image los valores con los dato de la imagen contenidos en el |
|
981 | 975 |
* vector de enteros. |
982 | 976 |
* @param image imagen con los datos actuales |
983 | 977 |
* @param startX inicio de la posici?n en X dentro de la imagen |
... | ... | |
988 | 982 |
* @param offset desplazamiento |
989 | 983 |
* @param scansize tama?o de imagen recorrida por cada p |
990 | 984 |
*/ |
991 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray,
|
|
985 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray, |
|
992 | 986 |
int offset, int scansize) { |
993 | 987 |
image.setRGB(startX, startY, w, h, rgbArray, offset, scansize); |
994 | 988 |
} |
995 |
|
|
989 |
|
|
996 | 990 |
/** |
997 |
* Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores
|
|
991 |
* Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores |
|
998 | 992 |
* con los dato de la imagen contenidos en el vector de enteros. De los valores RGB |
999 | 993 |
* que ya contiene se mantienen las bandas que no coinciden con el valor de flags. La |
1000 | 994 |
* banda correspondiente a flags es sustituida por los datos del vector. |
... | ... | |
1008 | 1002 |
* @param scansize tama?o de imagen recorrida por cada paso |
1009 | 1003 |
* @param flags banda que se va a sustituir (Ctes de GeoRasterFile) |
1010 | 1004 |
*/ |
1011 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray,
|
|
1005 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray, |
|
1012 | 1006 |
int offset, int scansize, int flags) { |
1013 |
int [] line = new int[rgbArray.length];
|
|
1007 |
int [] line = new int[rgbArray.length]; |
|
1014 | 1008 |
image.getRGB(startX, startY, w, h, line, offset, scansize); |
1015 | 1009 |
if (flags == GeoRasterFile.RED_BAND) |
1016 | 1010 |
for (int i=0; i<line.length; i++) |
... | ... | |
1023 | 1017 |
line[i] = (line[i] & 0x00ffff00) | (rgbArray[i] & 0xff0000ff); |
1024 | 1018 |
image.setRGB(startX, startY, w, h, line, offset, scansize); |
1025 | 1019 |
} |
1026 |
|
|
1020 |
|
|
1027 | 1021 |
/** |
1028 |
* Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores
|
|
1022 |
* Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores |
|
1029 | 1023 |
* con los dato de la imagen contenidos en el vector de enteros. De los valores RGB |
1030 | 1024 |
* que ya contiene se mantienen las bandas que no coinciden con el valor de flags. La |
1031 | 1025 |
* banda correspondiente a flags es sustituida por los datos del vector. |
... | ... | |
1040 | 1034 |
* @param origBand Banda origen del GeoRasterFile |
1041 | 1035 |
* @param destBandFlag banda que se va a sustituir (Ctes de GeoRasterFile) |
1042 | 1036 |
*/ |
1043 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray,
|
|
1037 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray, |
|
1044 | 1038 |
int offset, int scansize, int origBand, int destBandFlag) { |
1045 |
int [] line = new int[rgbArray.length];
|
|
1039 |
int [] line = new int[rgbArray.length]; |
|
1046 | 1040 |
image.getRGB(startX, startY, w, h, line, offset, scansize); |
1047 | 1041 |
if (origBand == 0 && destBandFlag == GeoRasterFile.RED_BAND) |
1048 | 1042 |
for (int i=0; i<line.length; i++) |
... | ... | |
1053 | 1047 |
else if (origBand == 2 && destBandFlag == GeoRasterFile.BLUE_BAND) |
1054 | 1048 |
for (int i=0; i<line.length; i++) |
1055 | 1049 |
line[i] = (line[i] & 0x00ffff00) | (rgbArray[i] & 0xff0000ff); |
1056 |
|
|
1050 |
|
|
1057 | 1051 |
else if (origBand == 0 && destBandFlag == GeoRasterFile.GREEN_BAND) |
1058 | 1052 |
for (int i=0; i<line.length; i++) |
1059 | 1053 |
line[i] = (line[i] & 0xffff00ff) | ((rgbArray[i] & 0x00ff0000) >> 8) ; |
... | ... | |
1063 | 1057 |
else if (origBand == 1 && destBandFlag == GeoRasterFile.RED_BAND) |
1064 | 1058 |
for (int i=0; i<line.length; i++) |
1065 | 1059 |
line[i] = (line[i] & 0xff00ffff) | ((rgbArray[i] & 0x0000ff00) << 8); |
1066 |
|
|
1060 |
|
|
1067 | 1061 |
else if (origBand == 1 && destBandFlag == GeoRasterFile.BLUE_BAND) |
1068 | 1062 |
for (int i=0; i<line.length; i++) |
1069 | 1063 |
line[i] = (line[i] & 0xffffff00) | ((rgbArray[i] & 0x0000ff00) >> 8); |
... | ... | |
1075 | 1069 |
line[i] = (line[i] & 0xffff00ff) | ((rgbArray[i] & 0x000000ff) << 8); |
1076 | 1070 |
image.setRGB(startX, startY, w, h, line, offset, scansize); |
1077 | 1071 |
} |
1078 |
|
|
1072 |
|
|
1073 |
/* |
|
1079 | 1074 |
private void showOnOpen() { |
1080 |
// Report en la apertura (quitar)
|
|
1081 |
System.out.println("Fichero GDAL '"+getName()+"' abierto.");
|
|
1082 |
System.out.println("Version = "+file.version);
|
|
1083 |
System.out.println(" Size = ("+file.width+","+file.height+")");
|
|
1084 |
try {
|
|
1075 |
// Report en la apertura (quitar)
|
|
1076 |
System.out.println("Fichero GDAL '"+getName()+"' abierto.");
|
|
1077 |
System.out.println("Version = "+file.version);
|
|
1078 |
System.out.println(" Size = ("+file.width+","+file.height+")");
|
|
1079 |
try {
|
|
1085 | 1080 |
System.out.println(" NumBands = ("+file.getRasterCount()+")"); |
1086 | 1081 |
} catch (GdalException e) { |
1087 | 1082 |
// TODO Auto-generated catch block |
1088 | 1083 |
e.printStackTrace(); |
1089 | 1084 |
} |
1090 |
//file.pintaInfo();
|
|
1091 |
file.pintaPaleta();
|
|
1085 |
//file.pintaInfo();
|
|
1086 |
file.pintaPaleta();
|
|
1092 | 1087 |
|
1093 | 1088 |
} |
1089 |
*/ |
|
1094 | 1090 |
|
1095 | 1091 |
/* (non-Javadoc) |
1096 | 1092 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int, int) |
1097 | 1093 |
*/ |
1098 | 1094 |
public Image updateImage(int width, int height, ICoordTrans rp, Image img, int origBand, int destBandFlag)throws SupersamplingNotSupportedException{ |
1099 | 1095 |
int line, pRGBArray[] = null; |
1100 |
|
|
1096 |
|
|
1101 | 1097 |
if(mustVerifySize()){ |
1102 | 1098 |
// Work out the correct aspect for the setView call. |
1103 | 1099 |
double dFileAspect = (double)v.width()/(double)v.height(); |
1104 | 1100 |
double dWindowAspect = (double)width /(double)height; |
1105 |
|
|
1101 |
|
|
1106 | 1102 |
if (dFileAspect > dWindowAspect) { |
1107 |
height =(int)((double)width/dFileAspect);
|
|
1103 |
height =(int)((double)width/dFileAspect);
|
|
1108 | 1104 |
} else { |
1109 |
width = (int)((double)height*dFileAspect);
|
|
1105 |
width = (int)((double)height*dFileAspect);
|
|
1110 | 1106 |
} |
1111 | 1107 |
} |
1112 |
|
|
1108 |
|
|
1113 | 1109 |
// Set the view |
1114 | 1110 |
boolean[] orientation = getOrientation(); |
1115 | 1111 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), |
1116 | 1112 |
width, height, orientation); |
1117 |
|
|
1113 |
|
|
1118 | 1114 |
if(width<=0)width=1; |
1119 | 1115 |
if(height<=0)height=1; |
1120 |
|
|
1116 |
|
|
1121 | 1117 |
pRGBArray = new int[width]; |
1122 | 1118 |
try { |
1123 | 1119 |
setBand(RED_BAND, rBandNr); |
... | ... | |
1129 | 1125 |
for (line=0; line < height; line++) { |
1130 | 1126 |
file.readLineRGBA(pRGBArray); |
1131 | 1127 |
setRGBLine((BufferedImage) img, 0, height - 1 - line, width, 1, pRGBArray, 0, width, origBand, destBandFlag); |
1132 |
}
|
|
1128 |
} |
|
1133 | 1129 |
}else{ |
1134 | 1130 |
for (line=0; line < height; line++) { |
1135 | 1131 |
file.readLineRGBA(pRGBArray); |
... | ... | |
1143 | 1139 |
for (line=0; line < height; line++) { |
1144 | 1140 |
file.readLineRGBA(pRGBArray); |
1145 | 1141 |
setRGBLine((BufferedImage) image, 0, height - 1 - line, width, 1, pRGBArray, 0, width); |
1146 |
}
|
|
1142 |
} |
|
1147 | 1143 |
}else{ |
1148 | 1144 |
for (line=0; line < height; line++) { |
1149 | 1145 |
file.readLineRGBA(pRGBArray); |
... | ... | |
1156 | 1152 |
// TODO Auto-generated catch block |
1157 | 1153 |
e.printStackTrace(); |
1158 | 1154 |
} |
1159 |
|
|
1155 |
|
|
1160 | 1156 |
return img; |
1161 | 1157 |
} |
1162 |
|
|
1158 |
|
|
1163 | 1159 |
/* (non-Javadoc) |
1164 | 1160 |
* @see org.cresques.io.GeoRasterFile#getData(int, int, int) |
1165 | 1161 |
*/ |
... | ... | |
1170 | 1166 |
} |
1171 | 1167 |
return null; |
1172 | 1168 |
} |
1173 |
|
|
1169 |
|
|
1174 | 1170 |
/** |
1175 | 1171 |
* Devuelve los datos de una ventana solicitada |
1176 | 1172 |
* @param ulX coordenada X superior izda. |
... | ... | |
1180 | 1176 |
* @param band Banda solicitada. |
1181 | 1177 |
*/ |
1182 | 1178 |
public byte[] getWindow(int ulX, int ulY, int sizeX, int sizeY, int band){ |
1183 |
|
|
1179 |
|
|
1184 | 1180 |
return null; |
1185 | 1181 |
} |
1186 |
|
|
1182 |
|
|
1187 | 1183 |
/** |
1188 | 1184 |
* Obtiene la zona (Norte / Sur) |
1189 | 1185 |
* @return true si la zona es norte y false si es sur |
1190 | 1186 |
*/ |
1191 |
|
|
1187 |
|
|
1192 | 1188 |
public boolean getZone(){ |
1193 |
|
|
1189 |
|
|
1194 | 1190 |
return false; |
1195 | 1191 |
} |
1196 |
|
|
1192 |
|
|
1197 | 1193 |
/** |
1198 | 1194 |
*Devuelve el n?mero de zona UTM |
1199 |
*@return N?mero de zona
|
|
1195 |
*@return N?mero de zona |
|
1200 | 1196 |
*/ |
1201 |
|
|
1197 |
|
|
1202 | 1198 |
public int getUTM(){ |
1203 |
|
|
1204 |
return 0;
|
|
1199 |
|
|
1200 |
return 0; |
|
1205 | 1201 |
} |
1206 |
|
|
1202 |
|
|
1207 | 1203 |
/** |
1208 | 1204 |
* Obtiene el sistema de coordenadas geograficas |
1209 | 1205 |
* @return Sistema de coordenadas geogr?ficas |
1210 | 1206 |
*/ |
1211 | 1207 |
public String getGeogCS(){ |
1212 |
|
|
1213 |
return new String("");
|
|
1208 |
|
|
1209 |
return new String(""); |
|
1214 | 1210 |
} |
1215 |
|
|
1211 |
|
|
1216 | 1212 |
/** |
1217 | 1213 |
* Devuelve el tama?o de bloque |
1218 | 1214 |
* @return Tama?o de bloque |
1219 | 1215 |
*/ |
1220 | 1216 |
public int getBlockSize(){ |
1221 |
return file.getBlockSize();
|
|
1217 |
return file.getBlockSize();
|
|
1222 | 1218 |
} |
1223 |
|
|
1219 |
|
|
1224 | 1220 |
/** |
1225 | 1221 |
* Obtiene el objeto que contiene los metadatos |
1226 | 1222 |
*/ |
1227 | 1223 |
public Metadata getMetadata() { |
1228 | 1224 |
if(file != null) |
1229 | 1225 |
return file.getMetadataJavaObject(); |
1230 |
else
|
|
1226 |
else |
|
1231 | 1227 |
return null; |
1232 | 1228 |
} |
1233 |
|
|
1229 |
|
|
1234 | 1230 |
/** |
1235 | 1231 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada |
1236 | 1232 |
* @return true si est? georreferenciada y false si no lo est?. |
... | ... | |
1238 | 1234 |
public boolean isGeoreferenced() { |
1239 | 1235 |
return file.isGeoreferenced(); |
1240 | 1236 |
} |
1241 |
|
|
1237 |
|
|
1242 | 1238 |
/** |
1243 | 1239 |
* Obtiene los par?metros de la transformaci?n af?n que corresponde con los elementos de |
1244 | 1240 |
* un fichero tfw. |
1245 |
* <UL>
|
|
1241 |
* <UL> |
|
1246 | 1242 |
* <LI>[1]tama?o de pixel en X</LI> |
1247 | 1243 |
* <LI>[2]rotaci?n en X</LI> |
1248 | 1244 |
* <LI>[4]rotaci?n en Y</LI> |
... | ... | |
1252 | 1248 |
* </UL> |
1253 | 1249 |
* Este m?todo debe ser reimplementado por el driver si tiene esta informaci?n. En principio |
1254 | 1250 |
* Gdal es capaz de proporcionarla de esta forma. |
1255 |
*
|
|
1251 |
* |
|
1256 | 1252 |
* En caso de que exista fichero .rmf asociado al raster pasaremos de la informaci?n de georreferenciaci?n |
1257 | 1253 |
* del .tfw y devolveremos la que est? asociada al rmf |
1258 | 1254 |
* @return vector de double con los elementos de la transformaci?n af?n. |
... | ... | |
1262 | 1258 |
return file.trans.adfgeotransform; |
1263 | 1259 |
else{ |
1264 | 1260 |
if(this.rmfExists){ |
1265 |
double[] rmfGeoref = { rmfTransform.getTranslateX(),
|
|
1261 |
double[] rmfGeoref = { rmfTransform.getTranslateX(), |
|
1266 | 1262 |
rmfTransform.getScaleX(), |
1267 |
rmfTransform.getShearX(),
|
|
1263 |
rmfTransform.getShearX(), |
|
1268 | 1264 |
rmfTransform.getTranslateY(), |
1269 | 1265 |
rmfTransform.getShearY(), |
1270 | 1266 |
rmfTransform.getScaleY()}; |
... | ... | |
1272 | 1268 |
} |
1273 | 1269 |
return null; |
1274 | 1270 |
} |
1275 |
|
|
1271 |
|
|
1276 | 1272 |
} |
1277 | 1273 |
} |
1278 | 1274 |
|
Also available in: Unified diff