root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / RasterDataset.java @ 13328
History | View | Annotate | Download (23.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.dataset; |
20 |
|
21 |
import java.awt.geom.AffineTransform; |
22 |
import java.awt.geom.NoninvertibleTransformException; |
23 |
import java.awt.geom.Point2D; |
24 |
import java.io.File; |
25 |
import java.io.IOException; |
26 |
import java.lang.reflect.Constructor; |
27 |
import java.lang.reflect.InvocationTargetException; |
28 |
|
29 |
import org.cresques.cts.ICoordTrans; |
30 |
import org.cresques.cts.IProjection; |
31 |
import org.gvsig.i18n.Messages; |
32 |
import org.gvsig.raster.dataset.io.GdalDriver; |
33 |
import org.gvsig.raster.dataset.io.IRegistrableRasterFormat; |
34 |
import org.gvsig.raster.dataset.io.MemoryRasterDriver; |
35 |
import org.gvsig.raster.dataset.io.MemoryRasterDriverParam; |
36 |
import org.gvsig.raster.dataset.io.rmf.ParsingException; |
37 |
import org.gvsig.raster.dataset.io.rmf.RmfBlocksManager; |
38 |
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation; |
39 |
import org.gvsig.raster.dataset.properties.DatasetHistogram; |
40 |
import org.gvsig.raster.dataset.properties.DatasetMetadata; |
41 |
import org.gvsig.raster.dataset.properties.DatasetStatistics; |
42 |
import org.gvsig.raster.dataset.serializer.GeoInfoRmfSerializer; |
43 |
import org.gvsig.raster.datastruct.ColorTable; |
44 |
import org.gvsig.raster.datastruct.Extent; |
45 |
import org.gvsig.raster.datastruct.Transparency; |
46 |
import org.gvsig.raster.hierarchy.IHistogramable; |
47 |
import org.gvsig.raster.util.RasterUtilities; |
48 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
49 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
50 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
51 |
|
52 |
/**
|
53 |
* Manejador de ficheros raster georeferenciados.
|
54 |
*
|
55 |
* Esta clase abstracta es el ancestro de todas las clases que proporcionan
|
56 |
* soporte para ficheros raster georeferenciados.<br>
|
57 |
* Actua tambien como una 'Fabrica', ocultando al cliente la manera en que
|
58 |
* se ha implementado ese manejo. Una clase nueva que soportara un nuevo
|
59 |
* tipo de raster tendr?a que registrar su extensi?n o extensiones usando
|
60 |
* el m?todo @see registerExtension.<br>
|
61 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>*
|
62 |
*/
|
63 |
|
64 |
public abstract class RasterDataset extends GeoInfo { |
65 |
|
66 |
public static final int CANCEL_HISTOGRAM = IHistogramable.CANCEL_HISTOGRAM; |
67 |
public static final int CANCEL_READ = 2; |
68 |
|
69 |
protected boolean[] cancel = new boolean[1]; |
70 |
|
71 |
/**
|
72 |
* Flag que representa a la banda del Rojo
|
73 |
*/
|
74 |
public static final int RED_BAND = 0x01; |
75 |
|
76 |
/**
|
77 |
* Flag que representa a la banda del Verde
|
78 |
*/
|
79 |
public static final int GREEN_BAND = 0x02; |
80 |
|
81 |
/**
|
82 |
* Flag que representa a la banda del Azul
|
83 |
*/
|
84 |
public static final int BLUE_BAND = 0x04; |
85 |
private boolean verifySize = false; |
86 |
/**
|
87 |
* Asignaci?n de banda del Rojo a una banda de la imagen
|
88 |
*/
|
89 |
protected int rBandNr = 1; |
90 |
|
91 |
/**
|
92 |
* Asignaci?n de banda del Verde a una banda de la imagen
|
93 |
*/
|
94 |
protected int gBandNr = 1; |
95 |
|
96 |
/**
|
97 |
* Asignaci?n de banda del Azul a una banda de la imagen
|
98 |
*/
|
99 |
protected int bBandNr = 1; |
100 |
|
101 |
/**
|
102 |
* N?mero de bandas de la imagen
|
103 |
*/
|
104 |
protected int bandCount = 1; |
105 |
private int dataType = IBuffer.TYPE_BYTE; |
106 |
|
107 |
protected DatasetStatistics stats = new DatasetStatistics(this); |
108 |
protected DatasetHistogram histogram = null; |
109 |
protected Object param = null; |
110 |
protected RmfBlocksManager rmfBlocksManager = null; |
111 |
|
112 |
static {
|
113 |
Messages.addResourceFamily("org.cresques.translations.text", "org.cresques.ui"); |
114 |
} |
115 |
|
116 |
/*
|
117 |
* (non-Javadoc)
|
118 |
* @see java.lang.Object#clone()
|
119 |
*/
|
120 |
public Object clone() { |
121 |
try {
|
122 |
RasterDataset dataset = RasterDataset.open(proj, param); |
123 |
//Estas van por referencia
|
124 |
dataset.histogram = histogram; |
125 |
dataset.stats = stats; |
126 |
return dataset;
|
127 |
} catch (NotSupportedExtensionException e) {
|
128 |
e.printStackTrace(); |
129 |
} catch (RasterDriverException e) {
|
130 |
e.printStackTrace(); |
131 |
} |
132 |
return null; |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Constructor
|
137 |
*/
|
138 |
public RasterDataset() {
|
139 |
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Factoria para abrir distintos tipos de raster.
|
144 |
*
|
145 |
* @param proj Proyecci?n en la que est? el raster.
|
146 |
* @param fName Nombre del fichero.
|
147 |
* @return GeoRasterFile, o null si hay problemas.
|
148 |
*/
|
149 |
public static RasterDataset open(IProjection proj, Object param) throws NotSupportedExtensionException, RasterDriverException { |
150 |
String idFormat = null; |
151 |
|
152 |
if(param instanceof String) |
153 |
idFormat = ((String)param).toLowerCase().substring(((String)param).lastIndexOf('.') + 1); |
154 |
if(param instanceof IRegistrableRasterFormat) |
155 |
idFormat = ((IRegistrableRasterFormat)param).getFormatID(); |
156 |
|
157 |
RasterDataset grf = null;
|
158 |
|
159 |
Class clase = null; |
160 |
if(param instanceof MemoryRasterDriverParam) |
161 |
clase = MemoryRasterDriver.class; |
162 |
|
163 |
if(clase == null){ |
164 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
165 |
ExtensionPoint extensionPoint = (ExtensionPoint)extensionPoints.get("RasterReader");
|
166 |
if(extensionPoint == null) |
167 |
return null; |
168 |
clase = (Class)extensionPoint.get(idFormat);
|
169 |
} |
170 |
|
171 |
if(clase == null) |
172 |
clase = GdalDriver.class; |
173 |
|
174 |
Class [] args = {IProjection.class, Object.class}; |
175 |
try {
|
176 |
Constructor hazNuevo = clase.getConstructor(args);
|
177 |
Object [] args2 = {proj, param}; |
178 |
grf = (RasterDataset) hazNuevo.newInstance(args2); |
179 |
} catch (SecurityException e) { |
180 |
throw new RasterDriverException("Error SecurityException in open"); |
181 |
} catch (NoSuchMethodException e) { |
182 |
throw new RasterDriverException("Error NoSuchMethodException in open"); |
183 |
} catch (IllegalArgumentException e) { |
184 |
throw new RasterDriverException("Error IllegalArgumentException in open"); |
185 |
} catch (InstantiationException e) { |
186 |
throw new RasterDriverException("Error InstantiationException in open"); |
187 |
} catch (IllegalAccessException e) { |
188 |
throw new RasterDriverException("Error IllegalAccessException in open"); |
189 |
} catch (InvocationTargetException e) { |
190 |
throw new NotSupportedExtensionException("Error in open"); |
191 |
} |
192 |
return grf;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* Acciones de inicilizaci?n comunes a todos los drivers.
|
197 |
* Este m?todo debe ser llamado explicitamente por el constructor de cada driver.
|
198 |
* Estas son acciones de inicializaci?n que se ejecutan despu?s del constructor de cada driver.
|
199 |
* Las acciones que hayan de ser realizadas antes se definen en el constructor de RasterDataset.
|
200 |
*/
|
201 |
protected void init() { |
202 |
//Creamos el gestor de Rmf
|
203 |
int last = getFName().lastIndexOf("."); |
204 |
if(last == -1) |
205 |
last = getFName().length(); |
206 |
String f = getFName().substring(0, last); |
207 |
f = f + ".rmf";
|
208 |
rmfBlocksManager = new RmfBlocksManager(f);
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* Tipo de fichero soportado.
|
213 |
* Devuelve true si el tipo de fichero (extension) est? soportado, si no
|
214 |
* devuelve false.
|
215 |
*
|
216 |
* @param fName Fichero raster
|
217 |
* @return true si est? soportado, si no false.
|
218 |
*/
|
219 |
public static boolean fileIsSupported(String fName) { |
220 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
221 |
ExtensionPoint extensionPoint = (ExtensionPoint)extensionPoints.get("RasterReader");
|
222 |
return (extensionPoint.get(fName.substring(fName.lastIndexOf(".") + 1, fName.length())) == null) ? false : true; |
223 |
} |
224 |
|
225 |
/**
|
226 |
* Constructor
|
227 |
* @param proj Proyecci?n
|
228 |
* @param name Nombre del fichero de imagen.
|
229 |
*/
|
230 |
public RasterDataset(IProjection proj, Object param) { |
231 |
super(proj, param);
|
232 |
if(param instanceof String) |
233 |
setFileSize(new File(getFName()).length()); |
234 |
} |
235 |
|
236 |
|
237 |
/**
|
238 |
* Carga un fichero raster. Puede usarse para calcular el extent e instanciar
|
239 |
* un objeto de este tipo.
|
240 |
*/
|
241 |
abstract public GeoInfo load(); |
242 |
|
243 |
/**
|
244 |
* Cierra el fichero y libera los recursos.
|
245 |
*/
|
246 |
abstract public void close(); |
247 |
|
248 |
/**
|
249 |
* Carga georreferenciaci?n desde el fichero Rmf si la hay
|
250 |
* @param fName Nombre del fichero
|
251 |
* @throws ParsingException
|
252 |
*/
|
253 |
public void loadFromRmf(RmfBlocksManager manager) throws ParsingException { |
254 |
GeoInfoRmfSerializer ser = new GeoInfoRmfSerializer(this); |
255 |
if(!manager.checkRmf())
|
256 |
return;
|
257 |
if(!new File(manager.getPath()).exists()) |
258 |
return;
|
259 |
manager.addClient(ser); |
260 |
manager.read(null);
|
261 |
manager.removeClient(ser.getClass()); |
262 |
} |
263 |
|
264 |
/**
|
265 |
* Salva la georreferenciaci?n a fichero rmf.
|
266 |
* @param fName
|
267 |
* @throws IOException
|
268 |
*/
|
269 |
public void saveToRmf(RmfBlocksManager manager) throws IOException { |
270 |
GeoInfoRmfSerializer ser = new GeoInfoRmfSerializer(this); |
271 |
if(!manager.checkRmf())
|
272 |
return;
|
273 |
manager.addClient(ser); |
274 |
RasterUtilities.copyFile(manager.getPath(), manager.getPath() + "~");
|
275 |
manager.write(); |
276 |
manager.removeClient(ser.getClass()); |
277 |
} |
278 |
|
279 |
/**
|
280 |
* Salva la georreferenciaci?n a fichero rmf.
|
281 |
* @param fName
|
282 |
* @throws IOException
|
283 |
*/
|
284 |
public void saveGeoToRmf() throws IOException { |
285 |
saveToRmf(rmfBlocksManager); |
286 |
} |
287 |
|
288 |
/**
|
289 |
* Obtiene el ancho de la imagen
|
290 |
* @return Ancho de la imagen
|
291 |
*/
|
292 |
abstract public int getWidth(); |
293 |
|
294 |
/**
|
295 |
* Obtiene el ancho de la imagen
|
296 |
* @return Ancho de la imagen
|
297 |
*/
|
298 |
abstract public int getHeight(); |
299 |
|
300 |
/**
|
301 |
* Reproyecci?n.
|
302 |
* @param rp Coordenadas de la transformaci?n
|
303 |
*/
|
304 |
abstract public void reProject(ICoordTrans rp); |
305 |
|
306 |
/**
|
307 |
* Asigna un nuevo Extent
|
308 |
* @param e Extent
|
309 |
*/
|
310 |
abstract public void setView(Extent e); |
311 |
|
312 |
/**
|
313 |
* Obtiene el extent asignado
|
314 |
* @return Extent
|
315 |
*/
|
316 |
abstract public Extent getView(); |
317 |
|
318 |
/**
|
319 |
* Obtiene el valor del raster en la coordenada que se le pasa.
|
320 |
* El valor ser? Double, Int, Byte, etc. dependiendo del tipo de
|
321 |
* raster.
|
322 |
* @param x coordenada X
|
323 |
* @param y coordenada Y
|
324 |
* @return
|
325 |
*/
|
326 |
abstract public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException; |
327 |
|
328 |
/**
|
329 |
* Obtiene el n?nero de bandas del fichero
|
330 |
* @return Entero que representa el n?mero de bandas
|
331 |
*/
|
332 |
public int getBandCount() { |
333 |
return bandCount;
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* @return Returns the dataType.
|
338 |
*/
|
339 |
public int getDataType() { |
340 |
return dataType;
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* @param dataType The dataType to set.
|
345 |
*/
|
346 |
public void setDataType(int dataType) { |
347 |
this.dataType = dataType;
|
348 |
} |
349 |
|
350 |
/**
|
351 |
* Cosulta si hay que verificar la relaci?n de aspecto de la imagen, es decir comprueba que el ancho/alto
|
352 |
* pasados a updateImage coinciden con el ancho/alto solicitado en setView a la imagen
|
353 |
* @return true si est? verificando la relaci?n de aspecto.
|
354 |
*/
|
355 |
public boolean mustVerifySize() { |
356 |
return verifySize;
|
357 |
} |
358 |
|
359 |
/**
|
360 |
* Asigna el flag que dice si hay que verificar la relaci?n de aspecto de la imagen, es decir
|
361 |
* comprueba que el ancho/alto pasados a updateImage coinciden con el ancho/alto solicitado
|
362 |
* en setView a la imagen.
|
363 |
* @return true si est? verificando la relaci?n de aspecto.
|
364 |
*/
|
365 |
public void setMustVerifySize(boolean verifySize) { |
366 |
this.verifySize = verifySize;
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
371 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
|
372 |
* pixeles de disco.
|
373 |
* @param ulx Posici?n X superior izquierda
|
374 |
* @param uly Posici?n Y superior izquierda
|
375 |
* @param lrx Posici?n X inferior derecha
|
376 |
* @param lry Posici?n Y inferior derecha
|
377 |
* @param rasterBuf Buffer de datos
|
378 |
* @param bandList
|
379 |
* @return Buffer de datos
|
380 |
*/
|
381 |
abstract public IBuffer getWindowRaster(double ulx, double uly, double lrx, double lry, BandList bandList, IBuffer rasterBuf); |
382 |
|
383 |
/**
|
384 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
385 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
|
386 |
* pixeles de disco.
|
387 |
* @param x Posici?n X superior izquierda
|
388 |
* @param y Posici?n Y superior izquierda
|
389 |
* @param w Ancho en coordenadas reales
|
390 |
* @param h Alto en coordenadas reales
|
391 |
* @param rasterBuf Buffer de datos
|
392 |
* @param bandList
|
393 |
* @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
|
394 |
* @return Buffer de datos
|
395 |
*/
|
396 |
abstract public IBuffer getWindowRaster(double x, double y, double w, double h, BandList bandList, IBuffer rasterBuf, boolean adjustToExtent); |
397 |
|
398 |
/**
|
399 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
400 |
* Se aplica supersampleo o subsampleo dependiendo del tama?o del buffer especificado.
|
401 |
*
|
402 |
* @param minX Posici?n m?nima X superior izquierda
|
403 |
* @param minY Posici?n m?nima Y superior izquierda
|
404 |
* @param maxX Posici?n m?xima X inferior derecha
|
405 |
* @param maxY Posici?n m?xima Y inferior derecha
|
406 |
* @param bufWidth Ancho del buffer de datos
|
407 |
* @param bufHeight Alto del buffer de datos
|
408 |
* @param rasterBuf Buffer de datos
|
409 |
* @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
|
410 |
* @param bandList
|
411 |
* @return Buffer de datos
|
412 |
*/
|
413 |
abstract public IBuffer getWindowRaster(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, BandList bandList, IBuffer rasterBuf, boolean adjustToExtent); |
414 |
|
415 |
/**
|
416 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas pixel.
|
417 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
|
418 |
* pixeles de disco.
|
419 |
* @param x Posici?n X superior izquierda
|
420 |
* @param y Posici?n Y superior izquierda
|
421 |
* @param w Ancho en coordenadas reales
|
422 |
* @param h Alto en coordenadas reales
|
423 |
* @param rasterBuf Buffer de datos
|
424 |
* @param bandList
|
425 |
* @return Buffer de datos
|
426 |
*/
|
427 |
abstract public IBuffer getWindowRaster(int x, int y, int w, int h, BandList bandList, IBuffer rasterBuf); |
428 |
|
429 |
/**
|
430 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas pixel.
|
431 |
* Se aplica supersampleo o subsampleo dependiendo del tama?o del buffer especificado.
|
432 |
*
|
433 |
* @param x Posici?n X superior izquierda
|
434 |
* @param y Posici?n Y superior izquierda
|
435 |
* @param w Ancho en coordenadas reales
|
436 |
* @param h Alto en coordenadas reales
|
437 |
* @param bufWidth Ancho del buffer de datos
|
438 |
* @param bufHeight Alto del buffer de datos
|
439 |
* @param rasterBuf Buffer de datos
|
440 |
* @param bandList
|
441 |
* @return Buffer de datos
|
442 |
*/
|
443 |
abstract public IBuffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight, BandList bandList, IBuffer rasterBuf); |
444 |
|
445 |
abstract public int getBlockSize(); |
446 |
|
447 |
/**
|
448 |
* Obtiene el objeto que contiene los metadatos. Este m?todo debe ser redefinido por los
|
449 |
* drivers si necesitan devolver metadatos.
|
450 |
* @return
|
451 |
*/
|
452 |
public DatasetMetadata getMetadata(){
|
453 |
return null; |
454 |
} |
455 |
|
456 |
/**
|
457 |
* Obtiene el objeto que contiene que contiene la interpretaci?n de
|
458 |
* color por banda
|
459 |
* @return
|
460 |
*/
|
461 |
public DatasetColorInterpretation getColorInterpretation(){
|
462 |
return null; |
463 |
} |
464 |
|
465 |
/**
|
466 |
* Dice si el fichero tiene georreferenciaci?n o no.
|
467 |
* @return true si tiene georreferenciaci?n y false si no la tiene
|
468 |
*/
|
469 |
public boolean isGeoreferenced(){ |
470 |
return true; |
471 |
} |
472 |
|
473 |
/**
|
474 |
* Obtiene el objeto paleta. Esta paleta es la que tiene adjunta el fichero de disco. Si es
|
475 |
* null este objeto quiere decir que no tiene paleta para su visualizaci?n.
|
476 |
* @return Palette
|
477 |
*/
|
478 |
public ColorTable getColorTable() {
|
479 |
return null; |
480 |
} |
481 |
|
482 |
/**
|
483 |
* Obtiene el estado de transparencia de un GeoRasterFile.
|
484 |
* @return Objeto TransparencyFileStatus
|
485 |
*/
|
486 |
public Transparency getTransparencyDatasetStatus() { |
487 |
return null; |
488 |
} |
489 |
|
490 |
/**
|
491 |
* Dado unas coordenadas reales, un tama?o de buffer y un tama?o de raster.
|
492 |
* Si el buffer es de mayor tama?o que el raster (supersampleo) quiere decir que
|
493 |
* por cada pixel de buffer se repiten varios del raster. Esta funci?n calcula el
|
494 |
* n?mero de pixels de desplazamiento en X e Y que corresponden al primer pixel del
|
495 |
* buffer en la esquina superior izquierda. Esto es necesario porque la coordenada
|
496 |
* solicitada es real y puede no caer sobre un pixel completo. Este calculo es
|
497 |
* util cuando un cliente quiere supersamplear sobre un buffer y que no se lo haga
|
498 |
* el driver autom?ticamente.
|
499 |
* @param dWorldTLX Coordenada real X superior izquierda
|
500 |
* @param dWorldTLY Coordenada real Y superior izquierda
|
501 |
* @param dWorldBRX Coordenada real X inferior derecha
|
502 |
* @param dWorldBRY Coordenada real Y inferior derecha
|
503 |
* @param nWidth Ancho del raster
|
504 |
* @param nHeight Alto del raster
|
505 |
* @param bufWidth Ancho del buffer
|
506 |
* @param bufHeight Alto del buffer
|
507 |
* @return Array de dos elementos con el desplazamiento en X e Y.
|
508 |
*/
|
509 |
public int[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY, |
510 |
double nWidth, double nHeight, int bufWidth, int bufHeight){ |
511 |
|
512 |
Point2D p1 = new Point2D.Double(dWorldTLX, dWorldTLY); |
513 |
Point2D p2 = new Point2D.Double(dWorldBRX, dWorldBRY); |
514 |
|
515 |
Point2D tl = worldToRaster(new Point2D.Double(p1.getX(), p1.getY())); |
516 |
Point2D br = worldToRaster(new Point2D.Double(p2.getX(), p2.getY())); |
517 |
|
518 |
int x = (int) tl.getX(); |
519 |
int y = (int) tl.getY(); |
520 |
|
521 |
int stpX = (int)(((tl.getX() - x) * bufWidth) / Math.abs(br.getX() - tl.getX())); |
522 |
int stpY = (int)(((tl.getY() - y) * bufHeight) / Math.abs(br.getY() - tl.getY())); |
523 |
|
524 |
return new int[]{stpX, stpY}; |
525 |
} |
526 |
|
527 |
/**
|
528 |
* Lee una l?nea completa del raster y devuelve un array del tipo correcto. Esta funci?n es util
|
529 |
* para una lectura rapida de todo el fichero sin necesidad de asignar vista.
|
530 |
* @param nLine N?mero de l?nea a leer
|
531 |
* @param band Banda requerida
|
532 |
* @return Object que es un array unidimendional del tipo de datos del raster
|
533 |
* @throws InvalidSetViewException
|
534 |
* @throws FileNotOpenException
|
535 |
* @throws RasterDriverException
|
536 |
*/
|
537 |
abstract public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException; |
538 |
|
539 |
/**
|
540 |
* Lee un bloque completo de datos del raster y devuelve un array tridimensional del tipo correcto. Esta funci?n es util
|
541 |
* para una lectura rapida de todo el fichero sin necesidad de asignar vista.
|
542 |
* @param pos Posici?n donde se empieza a leer
|
543 |
* @param blockHeight Altura m?xima del bloque leido
|
544 |
* @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
|
545 |
* @throws InvalidSetViewException
|
546 |
* @throws FileNotOpenException
|
547 |
* @throws RasterDriverException
|
548 |
*/
|
549 |
abstract public Object readBlock(int pos, int blockHeight)throws InvalidSetViewException, FileNotOpenException, RasterDriverException; |
550 |
|
551 |
/**
|
552 |
* Convierte un punto desde coordenadas pixel a coordenadas del mundo.
|
553 |
* @param pt Punto a transformar
|
554 |
* @return punto transformado en coordenadas del mundo
|
555 |
*/
|
556 |
public Point2D rasterToWorld(Point2D pt) { |
557 |
Point2D p = new Point2D.Double(); |
558 |
externalTransformation.transform(pt, p); |
559 |
return p;
|
560 |
} |
561 |
|
562 |
/**
|
563 |
* Convierte un punto desde del mundo a coordenadas pixel.
|
564 |
* @param pt Punto a transformar
|
565 |
* @return punto transformado en coordenadas pixel
|
566 |
*/
|
567 |
public Point2D worldToRaster(Point2D pt) { |
568 |
Point2D p = new Point2D.Double(); |
569 |
try {
|
570 |
externalTransformation.inverseTransform(pt, p); |
571 |
} catch (NoninvertibleTransformException e) { |
572 |
return pt;
|
573 |
} |
574 |
return p;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* Calcula el extent en coordenadas del mundo real
|
579 |
* @return Extent
|
580 |
*/
|
581 |
public Extent getExtent() {
|
582 |
return new Extent( rasterToWorld(new Point2D.Double(0, 0)), |
583 |
rasterToWorld(new Point2D.Double(getWidth(), getHeight())), |
584 |
rasterToWorld(new Point2D.Double(getWidth(), 0)), |
585 |
rasterToWorld(new Point2D.Double(0, getHeight()))); |
586 |
} |
587 |
|
588 |
/**
|
589 |
* Calcula el extent en coordenadas del mundo real sin rotaci?n. Solo coordenadas y tama?o de pixel
|
590 |
* @return Extent
|
591 |
*/
|
592 |
public Extent getExtentWithoutRot() {
|
593 |
AffineTransform at = new AffineTransform( externalTransformation.getScaleX(), 0, |
594 |
0, externalTransformation.getScaleY(),
|
595 |
externalTransformation.getTranslateX(), externalTransformation.getTranslateY()); |
596 |
Point2D p1 = new Point2D.Double(0, 0); |
597 |
Point2D p2 = new Point2D.Double(getWidth(), getHeight()); |
598 |
at.transform(p1, p1); |
599 |
at.transform(p2, p2); |
600 |
return new Extent(p1, p2); |
601 |
} |
602 |
|
603 |
/**
|
604 |
* ASigna el par?metro de inicializaci?n del driver.
|
605 |
*/
|
606 |
public void setParam(Object param) { |
607 |
this.param = param;
|
608 |
} |
609 |
|
610 |
/**
|
611 |
* Obtiene las estadisticas asociadas al fichero
|
612 |
* @return Objeto con las estadisticas
|
613 |
*/
|
614 |
public DatasetStatistics getStatistics() {
|
615 |
return stats;
|
616 |
} |
617 |
|
618 |
/**
|
619 |
* Obtiene el histograma asociado al dataset. Este puede ser obtenido
|
620 |
* completo o seg?n una lista de clases pasada.
|
621 |
*
|
622 |
* @return Histograma asociado al dataset.
|
623 |
*/
|
624 |
public DatasetHistogram getHistogram() {
|
625 |
if (histogram == null) |
626 |
histogram = new DatasetHistogram(this); |
627 |
return histogram;
|
628 |
} |
629 |
|
630 |
public void resetPercent() { |
631 |
if (histogram != null) histogram.resetPercent(); |
632 |
} |
633 |
|
634 |
public int getPercent() { |
635 |
if (histogram != null) return histogram.getPercent(); |
636 |
return 0; |
637 |
} |
638 |
|
639 |
public void setCanceled(boolean value, int process) { |
640 |
if(process == CANCEL_HISTOGRAM || process == 0) { |
641 |
if (histogram != null) |
642 |
histogram.setCanceled(value, DatasetHistogram.CANCEL_CREATEHISTOGRAM); |
643 |
} |
644 |
} |
645 |
|
646 |
public boolean isCanceled(int process) { |
647 |
if(process == CANCEL_HISTOGRAM) {
|
648 |
if (histogram != null) |
649 |
return histogram.isCanceled(DatasetHistogram.CANCEL_CREATEHISTOGRAM);
|
650 |
} |
651 |
return false; |
652 |
} |
653 |
|
654 |
/**
|
655 |
* Obtiene el gestor de ficheros RMF
|
656 |
* @return RmfBloksManager
|
657 |
*/
|
658 |
public RmfBlocksManager getRmfBlocksManager() {
|
659 |
return rmfBlocksManager;
|
660 |
} |
661 |
|
662 |
/**
|
663 |
* Escribe sobre el rmf todos los cambios que haya para salvar, es decir, para cada
|
664 |
* Objeto registrado en el manager volcar? su contenido al fichero rmf. ANtes de salvar realizar?
|
665 |
* una copia de seguridad sobre un fichero rmf de backup .rm~
|
666 |
* @throws IOException
|
667 |
*/
|
668 |
public void saveRmfModification() throws IOException { |
669 |
RasterUtilities.copyFile(rmfBlocksManager.getPath(), rmfBlocksManager.getPath() + "~");
|
670 |
rmfBlocksManager.write(); |
671 |
} |
672 |
|
673 |
/**
|
674 |
* Informa de si el punto en coordenadas del mundo real pasado por par?metro cae dentro del
|
675 |
* raster o fuera. Para este calculo cogeremos el punto a averiguar si est? dentro del raster
|
676 |
* y le aplicaremos la transformaci?n inversa de la transformaci?n af?n aplicada. Una vez hecho
|
677 |
* esto ya se puede comprobar si est? dentro de los l?mites del extent del raster.
|
678 |
* @param p Punto a comprobar en coordenadas reales
|
679 |
* @return true si el punto est? dentro y false si est? fuera.
|
680 |
*/
|
681 |
public boolean isInside(Point2D p){ |
682 |
//Realizamos los calculos solo si el punto est? dentro del extent de la imagen rotada, as? nos ahorramos los calculos
|
683 |
//cuando el puntero est? fuera
|
684 |
|
685 |
Point2D pt = new Point2D.Double(); |
686 |
try {
|
687 |
|
688 |
getAffineTransform().inverseTransform(p, pt); |
689 |
if( pt.getX() >= 0 && pt.getX() < getWidth() && |
690 |
pt.getY() >= 0 && pt.getY() < getHeight())
|
691 |
return true; |
692 |
} catch (NoninvertibleTransformException e) { |
693 |
return false; |
694 |
} |
695 |
|
696 |
return false; |
697 |
} |
698 |
|
699 |
/**
|
700 |
* Consulta de si un raster tiene rotaci?n o no.
|
701 |
* @return true si tiene rotaci?n y false si no la tiene.
|
702 |
*/
|
703 |
public boolean isRotated() { |
704 |
if(externalTransformation.getShearX() != 0 || externalTransformation.getShearY() != 0) |
705 |
return true; |
706 |
return false; |
707 |
} |
708 |
} |