root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / io / EcwDriver.java @ 11207
History | View | Annotate | Download (25.3 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.io; |
20 |
|
21 |
import java.awt.geom.Point2D; |
22 |
import java.io.File; |
23 |
import java.util.Vector; |
24 |
|
25 |
import org.cresques.cts.ICoordTrans; |
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.raster.dataset.BandList; |
28 |
import org.gvsig.raster.dataset.FileNotOpenException; |
29 |
import org.gvsig.raster.dataset.GeoInfo; |
30 |
import org.gvsig.raster.dataset.IBuffer; |
31 |
import org.gvsig.raster.dataset.InvalidSetViewException; |
32 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
33 |
import org.gvsig.raster.dataset.RasterDataset; |
34 |
import org.gvsig.raster.dataset.RasterDriverException; |
35 |
import org.gvsig.raster.dataset.properties.DatasetTransparency; |
36 |
import org.gvsig.raster.shared.Extent; |
37 |
import org.gvsig.raster.util.RasterUtilities; |
38 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
39 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
40 |
|
41 |
import com.ermapper.ecw.JNCSException; |
42 |
import com.ermapper.ecw.JNCSFile; |
43 |
import com.ermapper.ecw.JNCSFileNotOpenException; |
44 |
import com.ermapper.ecw.JNCSInvalidSetViewException; |
45 |
import com.ermapper.ecw.JNCSProgressiveUpdate; |
46 |
|
47 |
|
48 |
/**
|
49 |
* Driver de Ecw
|
50 |
*
|
51 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
52 |
*/
|
53 |
public class EcwDriver extends RasterDataset implements JNCSProgressiveUpdate { |
54 |
|
55 |
private JNCSFile file = null; |
56 |
private int currentFullWidth = -1; |
57 |
private int currentFullHeight = -1; |
58 |
/**
|
59 |
* Contorno en coordenadas geogr?ficas sin rotaci?n aplicada. Esto es util para poder
|
60 |
* calcular los pixeles necesarios que se van a leer del raster.
|
61 |
*/
|
62 |
public Contour bBoxWithoutRot = new Contour(); |
63 |
/**
|
64 |
* Estado de transparencia del raster.
|
65 |
*/
|
66 |
protected DatasetTransparency fileTransparency = null; |
67 |
|
68 |
/**
|
69 |
* Extent de la ventana seleccionada
|
70 |
*/
|
71 |
private Extent view = null; |
72 |
|
73 |
static {
|
74 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
75 |
extensionPoints.add("RasterDriver", "ecw", EcwDriver.class); |
76 |
extensionPoints.add("RasterDriver", "jp2", EcwDriver.class); |
77 |
} |
78 |
|
79 |
class Contour extends Vector { |
80 |
final private static long serialVersionUID = 0; |
81 |
public double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; |
82 |
public double maxX = -Double.MAX_VALUE, maxY = -Double.MAX_VALUE; |
83 |
public Contour() {
|
84 |
super();
|
85 |
} |
86 |
public void add(Point2D pt) { |
87 |
super.add(pt);
|
88 |
if (pt.getX() > maxX) maxX = pt.getX();
|
89 |
if (pt.getX() < minX) minX = pt.getX();
|
90 |
if (pt.getY() > maxY) maxY = pt.getY();
|
91 |
if (pt.getY() < minY) minY = pt.getY();
|
92 |
} |
93 |
} |
94 |
|
95 |
/**
|
96 |
* Constructor. Abre el dataset.
|
97 |
* @param proj Proyecci?n
|
98 |
* @param fName Nombre del fichero ecw
|
99 |
* @throws NotSupportedExtensionException
|
100 |
*/
|
101 |
public EcwDriver(IProjection proj, Object param)throws NotSupportedExtensionException { |
102 |
super(proj, ((String)param)); |
103 |
extent = new Extent();
|
104 |
try {
|
105 |
|
106 |
if (!new File(((String)param)).exists() && !((String)param).startsWith("ecwp:")) |
107 |
throw new NotSupportedExtensionException("Extension not supported"); |
108 |
|
109 |
file = new JNCSFile(((String)param), false); |
110 |
load(); |
111 |
//readGeoInfo(fName);
|
112 |
bandCount = file.numBands; |
113 |
getTransparencyDatasetStatus(); |
114 |
setDataType(IBuffer.TYPE_BYTE); |
115 |
} catch (Exception e) { |
116 |
throw new NotSupportedExtensionException("Extension not supported"); |
117 |
} |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Carga un ECW.
|
122 |
* @param fname
|
123 |
*/
|
124 |
public GeoInfo load() {
|
125 |
double minX;
|
126 |
double minY;
|
127 |
double maxX;
|
128 |
double maxY;
|
129 |
|
130 |
if(file.cellIncrementY > 0) |
131 |
file.cellIncrementY = -file.cellIncrementY; |
132 |
|
133 |
minX = file.originX; |
134 |
maxY = file.originY; |
135 |
maxX = file.originX + |
136 |
((double) (file.width) * file.cellIncrementX);
|
137 |
minY = file.originY + |
138 |
((double) (file.height) * file.cellIncrementY);
|
139 |
|
140 |
currentFullWidth = file.width; |
141 |
currentFullHeight = file.height; |
142 |
boundingBoxWithoutRotation(); |
143 |
|
144 |
extent = new Extent(minX, minY, maxX, maxY);
|
145 |
requestExtent = extent; |
146 |
return this; |
147 |
} |
148 |
|
149 |
/**
|
150 |
* Calcula la bounding box en la que est? metido el raster teniendo en cuenta
|
151 |
* el tama?o de pixel y la rotaci?n.
|
152 |
*/
|
153 |
private void boundingBoxWithoutRotation() { |
154 |
double ox = file.originX;
|
155 |
double oy = file.originY;
|
156 |
double resx = file.cellIncrementX;
|
157 |
double resy = file.cellIncrementY;
|
158 |
|
159 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy)); |
160 |
bBoxWithoutRot.add(new Point2D.Double(ox + resx * (file.width), oy)); |
161 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy + resy * (file.height))); |
162 |
bBoxWithoutRot.add(new Point2D.Double(ox + resx * (file.width), oy + resy * (file.height))); |
163 |
} |
164 |
|
165 |
/**
|
166 |
* Cierra el fichero ECW
|
167 |
*/
|
168 |
public void close() { |
169 |
if(file != null){ |
170 |
file.close(true);
|
171 |
file = null;
|
172 |
} |
173 |
} |
174 |
|
175 |
/**
|
176 |
* Obtiene el objeto que contiene el estado de la transparencia
|
177 |
*/
|
178 |
public DatasetTransparency getTransparencyDatasetStatus() {
|
179 |
if(fileTransparency == null) |
180 |
fileTransparency = new DatasetTransparency();
|
181 |
return fileTransparency;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* Devuelve el ancho de la imagen
|
186 |
*/
|
187 |
public int getWidth() { |
188 |
return file.width;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* Devuelve el alto de la imagen
|
193 |
*/
|
194 |
public int getHeight() { |
195 |
return file.height;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Obtiene el extent de la ?ltima ventana seleccionada.
|
200 |
* @return Extent
|
201 |
*/
|
202 |
public Extent getView() {
|
203 |
return view;
|
204 |
} |
205 |
|
206 |
/*
|
207 |
* (non-Javadoc)
|
208 |
* @see org.gvsig.fmap.driver.RasterDataset#setView(org.gvsig.fmap.raster.Extent)
|
209 |
*/
|
210 |
public void setView(Extent e) { |
211 |
//TODO: FUNCIONALIDAD: Falta aplicar la transformaci?n a la vista en caso de que haya un fichero .rmf. Mirar EcwFile de piloto
|
212 |
view = new Extent(e);
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Cuando se hace una petici?n de carga de buffer la extensi?n pedida puede estar ajustada a la extensi?n del raster
|
217 |
* o no estarlo. En caso de no estarlo los pixeles del buffer que caen fuera de la extensi?n del raster tendr?n valor
|
218 |
* de NoData. Esta funci?n calcula en que pixel del buffer hay que empezar a escribir en caso de que este sea mayor
|
219 |
* que los datos a leer.
|
220 |
* @param dWorldTLX Posici?n X superior izquierda en coord reales
|
221 |
* @param dWorldTLY Posici?n Y superior izquierda en coord reales
|
222 |
* @param dWorldBRX Posici?n X inferior derecha en coord reales
|
223 |
* @param dWorldBRY Posici?n Y inferior derecha en coord reales
|
224 |
* @param nWidth Ancho en pixeles del buffer
|
225 |
* @param nHeight Alto en pixeles del buffer
|
226 |
* @return desplazamiento dentro del buffer en X e Y
|
227 |
*/
|
228 |
private int[] calcStepBuffer(Extent dataExtent, int nWidth, int nHeight, int[] stpBuffer) { |
229 |
Extent imageExtent = new Extent(bBoxWithoutRot.minX, bBoxWithoutRot.minY, bBoxWithoutRot.maxX, bBoxWithoutRot.maxY);
|
230 |
Extent ajustDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, imageExtent); |
231 |
if(!RasterUtilities.compareExtents(dataExtent, ajustDataExtent)) {
|
232 |
Point2D p1 = worldToRaster(new Point2D.Double(ajustDataExtent.minX(), ajustDataExtent.maxY())); |
233 |
Point2D p2 = worldToRaster(new Point2D.Double(ajustDataExtent.maxX(), ajustDataExtent.minY())); |
234 |
Point2D p3 = worldToRaster(new Point2D.Double(dataExtent.minX(), dataExtent.maxY())); |
235 |
Point2D p4 = worldToRaster(new Point2D.Double(dataExtent.maxX(), dataExtent.minY())); |
236 |
//Ese es el ancho y alto q tendr?a el buffer en caso de haberse ajustado
|
237 |
int w = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX())); |
238 |
int h = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY())); |
239 |
|
240 |
stpBuffer[0] = (int)(p1.getX() + (-p3.getX())); |
241 |
stpBuffer[1] = (int)(p1.getY() + (-p3.getY())); |
242 |
stpBuffer[2] = stpBuffer[0] + w; |
243 |
stpBuffer[3] = stpBuffer[1] + h; |
244 |
return new int[]{w, h}; |
245 |
} |
246 |
return new int[]{nWidth, nHeight}; |
247 |
} |
248 |
|
249 |
/*
|
250 |
* (non-Javadoc)
|
251 |
* @see org.gvsig.fmap.driver.RasterDataset#worldToRaster(java.awt.geom.Point2D)
|
252 |
*/
|
253 |
public Point2D worldToRaster(Point2D pt) { |
254 |
double x = ((pt.getX() - bBoxWithoutRot.minX) * ((double) currentFullWidth)) / (double)(bBoxWithoutRot.maxX - bBoxWithoutRot.minX); |
255 |
double y = ((bBoxWithoutRot.maxY - pt.getY()) * ((double) currentFullHeight)) / (double)(bBoxWithoutRot.maxY - bBoxWithoutRot.minY); |
256 |
Point2D ptRes = new Point2D.Double(x, y); |
257 |
return ptRes;
|
258 |
} |
259 |
|
260 |
/*
|
261 |
* (non-Javadoc)
|
262 |
* @see org.gvsig.fmap.driver.RasterDataset#rasterToWorld(java.awt.geom.Point2D)
|
263 |
*/
|
264 |
public Point2D rasterToWorld(Point2D pt) { |
265 |
double x = bBoxWithoutRot.minX + ((pt.getX() * (bBoxWithoutRot.maxX - bBoxWithoutRot.minX)) / currentFullWidth);
|
266 |
double y = bBoxWithoutRot.maxY - ((pt.getY() * (bBoxWithoutRot.maxY - bBoxWithoutRot.minY)) / currentFullHeight);
|
267 |
Point2D ptRes = new Point2D.Double(x, y); |
268 |
return ptRes;
|
269 |
} |
270 |
|
271 |
/*
|
272 |
* (non-Javadoc)
|
273 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(double, double, double, double, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer, boolean)
|
274 |
*/
|
275 |
public IBuffer getWindowRaster(double x, double y, double w, double h, BandList bandList, IBuffer rasterBuf, boolean adjustToExtent) { |
276 |
|
277 |
//Si cojemos pixeles completos hemos de calcular las coordenadas reales de esos pixeles completos para hacer la petici?n.
|
278 |
//Este el calculo que se hizo en RasterMultiDataset para calcular pixeles completos, convertir a pixel, redondear el primero
|
279 |
//por abajo y el ultimo por arriba
|
280 |
Point2D p1 = worldToRaster(new Point2D.Double(x, y)); |
281 |
Point2D p2 = worldToRaster(new Point2D.Double(x + w, y - h)); |
282 |
Point2D a = rasterToWorld(new Point2D.Double(Math.floor(p1.getX()), Math.floor(p1.getY()))); |
283 |
Point2D b = rasterToWorld(new Point2D.Double(Math.ceil(p2.getX()), Math.ceil(p2.getY()))); |
284 |
|
285 |
//Extent selectedExtent = new Extent(x, y, x + w, y - h);
|
286 |
Extent selectedExtent = new Extent(a.getX(), a.getY(), b.getX(), b.getY());
|
287 |
setView(selectedExtent); |
288 |
int wPx = rasterBuf.getWidth();
|
289 |
int hPx = rasterBuf.getHeight();
|
290 |
int[] stpBuffer = new int[]{0, 0 , wPx, hPx}; |
291 |
|
292 |
//TODO: FUNCIONALIDAD: Implementar adjustToExtent = false
|
293 |
/*if(!adjustToExtent){
|
294 |
int[] wh = calcStepBuffer(selectedExtent, wPx, hPx, stpBuffer);
|
295 |
if(x < 0)
|
296 |
x = 0;
|
297 |
if(y < 0)
|
298 |
y = 0;
|
299 |
readData(buf, bandList, x, y, wh[0], wh[1], wh[0], wh[1], 0, 0, stpBuffer);
|
300 |
return;
|
301 |
}*/
|
302 |
|
303 |
loadBuffer(selectedExtent, wPx, hPx, rasterBuf, bandList, stpBuffer); |
304 |
|
305 |
return rasterBuf;
|
306 |
} |
307 |
|
308 |
/*
|
309 |
* (non-Javadoc)
|
310 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(int, int, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
311 |
*/
|
312 |
public IBuffer getWindowRaster(int x, int y, int w, int h, BandList bandList, IBuffer rasterBuf) { |
313 |
Point2D init = this.rasterToWorld(new Point2D.Double(x, y)); |
314 |
Point2D end = this.rasterToWorld(new Point2D.Double(x + w, y + h)); |
315 |
Extent selectedExtent = new Extent(init.getX(), init.getY(), end.getX(), end.getY());
|
316 |
setView(selectedExtent); |
317 |
int[] stpBuffer = new int[]{0, 0 , w, h}; |
318 |
|
319 |
loadBuffer(selectedExtent, w, h, rasterBuf, bandList, stpBuffer); |
320 |
return rasterBuf;
|
321 |
} |
322 |
|
323 |
/*
|
324 |
* (non-Javadoc)
|
325 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer, boolean)
|
326 |
*/
|
327 |
public IBuffer getWindowRaster(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, BandList bandList, IBuffer rasterBuf, boolean adjustToExtent) { |
328 |
Extent selectedExtent = new Extent(minX, maxY, maxX, minY);
|
329 |
setView(selectedExtent); |
330 |
int[] stpBuffer = new int[]{0, 0 , bufWidth, bufHeight}; |
331 |
|
332 |
//TODO: FUNCIONALIDAD: Implementar adjustToExtent = false
|
333 |
|
334 |
loadBuffer(selectedExtent, bufWidth, bufHeight, rasterBuf, bandList, stpBuffer); |
335 |
return rasterBuf;
|
336 |
} |
337 |
|
338 |
/*
|
339 |
* (non-Javadoc)
|
340 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
341 |
*/
|
342 |
public IBuffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight, BandList bandList, IBuffer rasterBuf) { |
343 |
Point2D init = this.rasterToWorld(new Point2D.Double(x, y)); |
344 |
Point2D end = this.rasterToWorld(new Point2D.Double(x + w, y + h)); |
345 |
Extent selectedExtent = new Extent(init.getX(), init.getY(), end.getX(), end.getY());
|
346 |
setView(selectedExtent); |
347 |
int[] stpBuffer = new int[]{0, 0 , bufWidth, bufHeight}; |
348 |
|
349 |
loadBuffer(selectedExtent, bufWidth, bufHeight, rasterBuf, bandList, stpBuffer); |
350 |
return rasterBuf;
|
351 |
} |
352 |
|
353 |
/**
|
354 |
* Carga el buffer con las bandas RGB del raster con los par?metros especificados de extensi?n
|
355 |
* y tama?o de buffer. El problema de ecw es que solo podemos leer 3 bandas de una vez ya que solo disponemos
|
356 |
* de una llamada readLineRGBA. Para leer m?s bandas tendremos que hacer multiples llamadas a setView para leer
|
357 |
* 3 cada vez.
|
358 |
*
|
359 |
* Si por ejemplo tenemos un ecw de 6 bandas [0, 1, 2, 3, 4, 5] y queremos cargar un buffer con el siguiente orden
|
360 |
* [0, -, 2, -, 4, -] La variable readBandsFromECW har? la llamada a setView con los valores [0, 2, 4, 0, 0, 0]. La
|
361 |
* funci?n drawRGB ser? la encargada de hacer el switch para obtener [0, -, 2, -, 4, -].
|
362 |
*
|
363 |
* Bug#1: Si se dispone de un ecw de m?s de tres bandas podemos llamar a setView con readBandsFromECW con el orden
|
364 |
* que queramos, por ejemplo [3, 2, 5, 1, 0] pero para ecw de 3 bandas la llamada con las bandas cambiadas no
|
365 |
* hace caso. El caso de readBandsFromECW = [2, 0, 1] ser? tomado siempre como [0, 1, 2].
|
366 |
*
|
367 |
* @param selectedExtent Extensi?n seleccionada
|
368 |
* @param bufWidth Ancho de buffer
|
369 |
* @param bufHeight Alto de buffer
|
370 |
* @param rasterBuf Buffer de datos
|
371 |
*/
|
372 |
private void loadBuffer(Extent selectedExtent, int bufWidth, int bufHeight, IBuffer rasterBuf, BandList bandList, int[] stpBuffer){ |
373 |
try{
|
374 |
//Leemos el raster desde la librer?a
|
375 |
|
376 |
int[] readBandsFromECW = new int[file.numBands]; |
377 |
int[] readBands = new int[file.numBands]; |
378 |
|
379 |
|
380 |
for(int i = 0; i < readBandsFromECW.length; i ++) |
381 |
readBands[i] = -1;
|
382 |
int cont = 0; |
383 |
for(int i = 0; i < file.numBands; i++){ |
384 |
int[] bandsToDraw = bandList.getBand(i).getDataImageBandToDraw(); |
385 |
if(bandsToDraw != null){ |
386 |
for(int j = 0; j < bandsToDraw.length; j++){ |
387 |
readBandsFromECW[cont] = i; |
388 |
readBands[cont] = i; |
389 |
cont ++; |
390 |
} |
391 |
} |
392 |
|
393 |
} |
394 |
|
395 |
file.setView(file.numBands, readBandsFromECW, selectedExtent.minX(), selectedExtent.maxY(), selectedExtent.maxX(), selectedExtent.minY(), bufWidth, bufHeight); |
396 |
|
397 |
//Escribimos el raster sobre un IBuffer
|
398 |
int[] pRGBArray = new int[bufWidth]; |
399 |
drawRGB(rasterBuf, pRGBArray, readBands, bandList); |
400 |
|
401 |
}catch(JNCSInvalidSetViewException exc){
|
402 |
exc.printStackTrace(); |
403 |
}catch (JNCSFileNotOpenException e) {
|
404 |
e.printStackTrace(); |
405 |
}catch (JNCSException ex) {
|
406 |
ex.printStackTrace(); |
407 |
} |
408 |
|
409 |
} |
410 |
|
411 |
|
412 |
private void drawRGB(IBuffer rasterBuf, int[] pRGBArray, int[] readBands, BandList bandList)throws JNCSException{ |
413 |
byte data = 0; |
414 |
int bandR = readBands[0]; |
415 |
int bandG = (readBands.length > 1) ? readBands[1] : -1; |
416 |
int bandB = (readBands.length > 2) ? readBands[2] : -1; |
417 |
|
418 |
//********* caso especial que resuelve Bug#1 **********************
|
419 |
if(file.numBands == 3 && bandList.getDrawableBandsCount() < 3){ |
420 |
for(int i = 0; i < 3; i ++){ |
421 |
int[] b = bandList.getBand(i).getDataImageBandToDraw(); |
422 |
if(b != null){ |
423 |
bandG = 1; bandR = 0; bandB = 2; |
424 |
} |
425 |
} |
426 |
} |
427 |
if(file.numBands == 3 && bandR == bandG && bandG == bandB){ //caso especial que resuelve Bug#1 |
428 |
for(int i = 0; i < 3; i ++){ |
429 |
int[] b = bandList.getBand(i).getDataImageBandToDraw(); |
430 |
if(b != null){ |
431 |
if(i == 0){ |
432 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
433 |
file.readLineRGBA(pRGBArray); |
434 |
for(int col = 0; col < pRGBArray.length; col ++){ |
435 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
436 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
437 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
438 |
} |
439 |
} |
440 |
return;
|
441 |
} |
442 |
if(i == 1){ |
443 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
444 |
file.readLineRGBA(pRGBArray); |
445 |
for(int col = 0; col < pRGBArray.length; col ++){ |
446 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
447 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
448 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
449 |
} |
450 |
} |
451 |
return;
|
452 |
} |
453 |
if(i == 2){ |
454 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
455 |
file.readLineRGBA(pRGBArray); |
456 |
for(int col = 0; col < pRGBArray.length; col ++){ |
457 |
rasterBuf.setElem(line, col, bandR, (byte)(pRGBArray[col] & 0x000000ff)); |
458 |
rasterBuf.setElem(line, col, bandG, (byte)(pRGBArray[col] & 0x000000ff)); |
459 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff)); |
460 |
} |
461 |
} |
462 |
return;
|
463 |
} |
464 |
} |
465 |
} |
466 |
|
467 |
} |
468 |
//********* END caso especial que resuelve Bug#1 **********************
|
469 |
|
470 |
if(bandR >= 0 && bandG >= 0 && bandB >= 0){ |
471 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
472 |
file.readLineRGBA(pRGBArray); |
473 |
for(int col = 0; col < pRGBArray.length; col ++){ |
474 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
475 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
476 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff)); |
477 |
} |
478 |
} |
479 |
return;
|
480 |
} |
481 |
|
482 |
if(bandR >= 0 && bandG >= 0){ |
483 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
484 |
file.readLineRGBA(pRGBArray); |
485 |
for(int col = 0; col < pRGBArray.length; col ++){ |
486 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
487 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
488 |
} |
489 |
} |
490 |
return;
|
491 |
} |
492 |
|
493 |
if(bandR >= 0){ |
494 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
495 |
file.readLineRGBA(pRGBArray); |
496 |
for(int col = 0; col < pRGBArray.length; col ++) |
497 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
498 |
} |
499 |
return;
|
500 |
} |
501 |
|
502 |
} |
503 |
|
504 |
public void reProject(ICoordTrans rp) { |
505 |
} |
506 |
|
507 |
public void setExtentTransform(double originX, double originY, double psX, double psY) { |
508 |
} |
509 |
|
510 |
public int getBlockSize() { |
511 |
return 0; |
512 |
} |
513 |
|
514 |
/*
|
515 |
* (non-Javadoc)
|
516 |
* @see org.gvsig.raster.driver.RasterDataset#readCompletetLine(int, int)
|
517 |
*/
|
518 |
public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
519 |
if(line < 0 || line >= file.height || band < 0 || band >= getBandCount()) |
520 |
throw new InvalidSetViewException("Request out of grid"); |
521 |
|
522 |
Point2D begin = rasterToWorld(new Point2D.Double(0, line)); |
523 |
Point2D end = rasterToWorld(new Point2D.Double(file.width, line + 1)); |
524 |
int[] readBandsFromECW = new int[file.numBands]; |
525 |
if(file.numBands <= 3) { |
526 |
for(int i = 0; i < file.numBands; i++) |
527 |
readBandsFromECW[i] = i; |
528 |
}else {
|
529 |
readBandsFromECW[0] = band;
|
530 |
} |
531 |
|
532 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY());
|
533 |
|
534 |
try {
|
535 |
int[] value = new int[file.width]; |
536 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), file.width, 1);
|
537 |
file.readLineRGBA(value); |
538 |
|
539 |
if(file.numBands <= 3) { |
540 |
switch(getDataType()) {
|
541 |
case IBuffer.TYPE_BYTE: byte[] b = new byte[file.width]; |
542 |
switch(band) {
|
543 |
case 0: for(int i = 0; i < file.width; i ++) |
544 |
b[i] = (byte)(((value[i] & 0x00ff0000) >> 16) & 0xff); |
545 |
break;
|
546 |
case 1: for(int i = 0; i < file.width; i ++) |
547 |
b[i] = (byte)(((value[i] & 0x0000ff00) >> 8) & 0xff); |
548 |
break;
|
549 |
case 2: for(int i = 0; i < file.width; i ++) |
550 |
b[i] = (byte)((value[i] & 0x000000ff) & 0xff); |
551 |
break;
|
552 |
} |
553 |
return b;
|
554 |
} |
555 |
}else {
|
556 |
switch(getDataType()) {
|
557 |
case IBuffer.TYPE_BYTE: byte[] b = new byte[file.width]; |
558 |
for(int i = 0; i < file.width; i ++) |
559 |
b[i] = (byte)(((value[i] & 0x00ff0000) >> 16) & 0xff); |
560 |
break;
|
561 |
} |
562 |
} |
563 |
//TODO: FUNCIONALIDAD: Ecw con otro tipo de dato != Byte
|
564 |
} catch (JNCSFileNotOpenException e1) {
|
565 |
throw new FileNotOpenException("Error en jecw: JNCSFileNotOpenException"); |
566 |
} catch (JNCSInvalidSetViewException e1) {
|
567 |
throw new FileNotOpenException("Error en jecw: JNCSInvalidSetViewException"); |
568 |
} catch (JNCSException e1) {
|
569 |
throw new RasterDriverException("Error la lectura de datos ecw"); |
570 |
} |
571 |
|
572 |
return null; |
573 |
} |
574 |
|
575 |
/*
|
576 |
* (non-Javadoc)
|
577 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int, int)
|
578 |
*/
|
579 |
public Object readBlock(int pos, int blockHeight) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
580 |
if(pos < 0) |
581 |
throw new InvalidSetViewException("Request out of grid"); |
582 |
|
583 |
if((pos + blockHeight) > file.height)
|
584 |
blockHeight = Math.abs(file.height - pos);
|
585 |
|
586 |
Point2D begin = rasterToWorld(new Point2D.Double(0, pos)); |
587 |
Point2D end = rasterToWorld(new Point2D.Double(file.width, pos + blockHeight)); |
588 |
int[] readBandsFromECW = new int[file.numBands]; |
589 |
|
590 |
for(int i = 0; i < file.numBands; i++) |
591 |
readBandsFromECW[i] = i; |
592 |
|
593 |
byte[][][] buf = new byte[file.numBands][blockHeight][file.width]; |
594 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY());
|
595 |
|
596 |
try {
|
597 |
int[] value = new int[file.width]; |
598 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), file.width, 1);
|
599 |
|
600 |
if(file.numBands <= 3) { |
601 |
for (int row = 0; row < blockHeight; row++) { |
602 |
file.readLineRGBA(value); |
603 |
switch(getDataType()) {
|
604 |
case IBuffer.TYPE_BYTE:
|
605 |
for(int col = 0; col < file.width; col ++) { |
606 |
buf[0][row][col] = (byte)(((value[col] & 0x00ff0000) >> 16) & 0xff); |
607 |
buf[1][row][col] = (byte)(((value[col] & 0x0000ff00) >> 8) & 0xff); |
608 |
buf[2][row][col] = (byte)((value[col] & 0x000000ff) & 0xff); |
609 |
} |
610 |
break;
|
611 |
} |
612 |
} |
613 |
} else {
|
614 |
//TODO: FUNCIONALIDAD: file.numBands > 3
|
615 |
} |
616 |
|
617 |
//TODO: FUNCIONALIDAD: Ecw con otro tipo de dato != Byte
|
618 |
} catch (JNCSFileNotOpenException e1) {
|
619 |
throw new FileNotOpenException("Error en jecw: JNCSFileNotOpenException"); |
620 |
} catch (JNCSInvalidSetViewException e1) {
|
621 |
throw new FileNotOpenException("Error en jecw: JNCSInvalidSetViewException"); |
622 |
} catch (JNCSException e1) {
|
623 |
throw new RasterDriverException("Error la lectura de datos ecw"); |
624 |
} |
625 |
|
626 |
return buf;
|
627 |
} |
628 |
|
629 |
/*
|
630 |
* (non-Javadoc)
|
631 |
* @see org.gvsig.raster.driver.RasterDataset#getData(int, int, int)
|
632 |
*/
|
633 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
634 |
if(x < 0 || y < 0 || x >= file.width || y >= file.height) |
635 |
throw new InvalidSetViewException("Request out of grid"); |
636 |
|
637 |
Point2D begin = rasterToWorld(new Point2D.Double(x, y)); |
638 |
Point2D end = rasterToWorld(new Point2D.Double(x + 1, y + 1)); |
639 |
int[] readBandsFromECW = new int[file.numBands]; |
640 |
if(file.numBands <= 3){ |
641 |
for(int i = 0; i < file.numBands; i++) |
642 |
readBandsFromECW[i] = i; |
643 |
}else{
|
644 |
readBandsFromECW[0] = band;
|
645 |
} |
646 |
|
647 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY());
|
648 |
try {
|
649 |
int[] value = new int[1]; |
650 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), 1, 1); |
651 |
file.readLineRGBA(value); |
652 |
if(file.numBands <= 3){ |
653 |
switch(band){
|
654 |
case 0: return new Integer((((value[0] & 0x00ff0000) >> 16) & 0xffffffff)); |
655 |
case 1: return new Integer((((value[0] & 0x0000ff00) >> 8) & 0xffffffff)); |
656 |
case 2: return new Integer((((value[0] & 0x000000ff)) & 0xffffffff)); |
657 |
} |
658 |
} |
659 |
return new Integer((((value[0] & 0x00ff0000) >> 16) & 0xffffffff)); |
660 |
} catch (JNCSFileNotOpenException e1) {
|
661 |
throw new FileNotOpenException("Error en jecw: JNCSFileNotOpenException"); |
662 |
} catch (JNCSInvalidSetViewException e1) {
|
663 |
throw new FileNotOpenException("Error en jecw: JNCSInvalidSetViewException"); |
664 |
} catch (JNCSException e1) {
|
665 |
throw new RasterDriverException("Error reading ecw data"); |
666 |
} |
667 |
} |
668 |
|
669 |
public void refreshUpdate(int arg0, int arg1, double arg2, double arg3, double arg4, double arg5) { |
670 |
} |
671 |
|
672 |
public void refreshUpdate(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) { |
673 |
} |
674 |
|
675 |
/*
|
676 |
* (non-Javadoc)
|
677 |
* @see org.gvsig.raster.driver.GeoData#getStringProjection()
|
678 |
*/
|
679 |
public String getStringProjection() throws RasterDriverException{ |
680 |
return file.projection;
|
681 |
} |
682 |
|
683 |
} |
684 |
|
685 |
|
686 |
|