Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / provider / RasterProvider.java @ 1367

History | View | Annotate | Download (19.2 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.impl.provider;
23

    
24
import java.awt.Image;
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.Point2D;
27

    
28
import org.cresques.cts.IProjection;
29
import org.gvsig.compat.net.ICancellable;
30
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
31
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
32
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
33
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
34
import org.gvsig.fmap.dal.coverage.exception.CloneException;
35
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
36
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException;
37
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
38
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
39
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
40
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
41
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
42
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
43
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
44
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
45
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
46
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
47
import org.gvsig.fmap.dal.coverage.store.props.Histogramable;
48
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
49
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
50
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries;
51
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
52
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
53
import org.gvsig.raster.cache.tile.provider.TileServer;
54

    
55
/**
56
 * Interfaz que deben implementar cualquier fuente de datos raster. Estas pueden estar
57
 * compuestas por N datasets. B?sicamente hay dos fuentes que deben implementar este interfaz, 
58
 * MultiRasterDataset y CompositeDataset. La primera es un dataset compuesto por varios ficheros
59
 * con el mismo Extent de N bandas cada uno. MultiRasterDataset proporciona una encapsulaci?n al acceso
60
 * a datos de todos ellos. CompositeDataset es un dataset compuesto de N MultiRasterDatasets cuya extensi?n
61
 * es continua formando un Grid de datasets con continuidad espacial. IRasterDataSource proporciona
62
 * una visi?n de acceso a datos com?n para ambos.
63
 * 
64
 * @author Nacho Brodin (nachobrodin@gmail.com)
65
 *
66
 */
67
public interface RasterProvider extends CoverageStoreProvider, Histogramable {
68
        
69
        /**
70
         * Gets a list of sizes. If the provider doesn't have files it will return null.
71
         * If the provider has one file it will return an array of one element with the
72
         * size of this file. If the provider contains others with one file each one.
73
         * @return
74
         */
75
        public long[] getFileSizeByProvider();
76
        
77
        /**
78
         * Gets a list of file names or URI. Each element of this array is the name of a 
79
         * provider 
80
         * @return
81
         */
82
        public String[] getURIByProvider();
83
        
84
        /**
85
         * Gets the URI of the first provider.
86
         * @return String 
87
         *         File name or URI
88
         */
89
        public String getURIOfFirstProvider();
90
        
91
        /**
92
         * Gets the number of bands by provider. 
93
         * @return
94
         */
95
        public int[] getBandCountByProvider();
96
        
97
        /**
98
         * Selecting a number of band this function returns the number of band
99
         * inside the file. If this provider has only one file the result
100
         * will be band parameter.
101
         * @param band
102
         * @return
103
         */
104
        public int getBandPositionByProvider(int band);
105
        
106
        /**
107
         * Returns the number of internal providers that it has
108
         * @return
109
         */
110
        public int getInternalProviderCount();
111
        
112
        /**
113
         * Gets the internal provider of the i position
114
         * @param i
115
         * @return
116
         */
117
        public RasterProvider getInternalProvider(int i);
118
        
119
        /**
120
         * Gets the URI of the source. If the provider has only one band
121
         * the result will be the URI. If it is multifile will have to choose
122
         * among several sources.
123
         * @param band
124
         * @return
125
         */
126
        public String getURIByBand(int band);
127
        
128
        /**
129
         * Gets the uniform resource identifier
130
         * @return
131
         */
132
        public String getURI();
133
        
134
        /**
135
         * Gets the number of subdatasets
136
         * @return
137
         */
138
        public int getSubdatasetCount();
139
        
140
        /**
141
         * Adds a new file. The behavior of this function depends on 
142
         * the kind of provider and its implementation.
143
         * @param file
144
         * @throws InvalidSourceException 
145
         */
146
        public void addFile(String file) throws InvalidSourceException;
147
        
148
        /**
149
         * Removes a file. The behavior of this function depends on 
150
         * the kind of provider and its implementation.
151
         * @param file
152
         */
153
        public void removeFile(String file);
154
        
155
        /**
156
         * Obtiene el n?mero de bandas del raster
157
         * @return N?mero de bandas
158
         */
159
        public int getBandCount();
160
        
161
        /**
162
         * Obtiene el tipo de dato por banda
163
         * @return tipo de dato por banda
164
         */
165
        public int[] getDataType();
166
        
167
        /**
168
         * Obtiene la altura del raster en p?xeles.
169
         * @return altura
170
         */
171
        public double getHeight();
172

    
173
        /**
174
         * Obtiene la anchura del raster en p?xeles.
175
         * @return anchura
176
         */
177
        public double getWidth();
178
        
179
        /**
180
         * Devuelve si el Dataset es reproyectable
181
         * @return
182
         */
183
        public boolean isReproyectable();
184
        
185
        /**
186
         * Returns true if this raster has rotation and false if don't
187
         */
188
        public boolean isRotated();
189
        
190
        /**
191
         * Returns true if this provider is open and false if don't
192
         * @return
193
         */
194
        public boolean isOpen();
195
        
196
        /**
197
         * Returns true if this provider supports time.
198
         * @return
199
         */
200
        public boolean isTimeSupported();
201
        
202
        /**
203
         * Returns true if the provider support tiles
204
         * @return
205
         */
206
        public boolean isTiled();
207
        
208
        /**
209
         * Informa de si el dataset soporta overviews o no.
210
         * @return true si soporta overviews y false si no las soporta.
211
         */
212
        public boolean isOverviewsSupported();
213
        
214
        /**
215
         * Obtiene el n?mero de overviews de una banda
216
         * @return
217
         */
218
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException;
219

    
220
        /**
221
         * Obtiene el ancho de una overview de una banda
222
         * @return
223
         */
224
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException;
225

    
226
        /**
227
         * Obtiene el alto de una overview de una banda
228
         * @return
229
         */
230
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException;
231

    
232
        
233
        /**
234
         * Informa de si el punto en coordenadas del mundo real pasado por par?metro cae dentro del
235
         * raster o fuera. Para este calculo cogeremos el punto a averiguar si est? dentro del raster
236
         * y le aplicaremos la transformaci?n inversa de la transformaci?n af?n aplicada. Una vez hecho
237
         * esto ya se puede comprobar si est? dentro de los l?mites del extent del raster.
238
         * @param p Punto a comprobar en coordenadas reales
239
         * @return true si el punto est? dentro y false si est? fuera.
240
         */
241
        public boolean isInside(Point2D p);
242
        
243
        /**
244
         * Gets the nodata value.
245
         * @return
246
         */
247
        public NoData getNoDataValue();
248
        
249
        /**
250
         * Gets statistics of this provider
251
         * @return MultiFileStatistics
252
         */
253
        public Statistics getStatistics();
254
        
255
        /**
256
         * Sets the statistics of this provider. Be careful using this method. 
257
         * Statistics shouldn't be assigned unless you had cloned this provider. 
258
         */
259
        public void setStatistics(Statistics stats);
260
        
261
        /**
262
         * Obtiene el extent del raster.
263
         * @return Extent
264
         */
265
        public Extent getExtent();
266
        
267
        /**
268
         * Gets the suffix of the source file 
269
         * @return
270
         */
271
        public String getFileSuffix();
272
        
273
        /**
274
         * Este es el extent sobre el que se ajusta una petici?n para que esta no
275
         * exceda el extent m?ximo del raster. Para un raster sin rotar ser? igual al
276
         * extent pero para un raster rotado ser? igual al extent del raster como si
277
         * no tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace
278
         * sobre la vista y las peticiones han de hacerse en coordenadas de la imagen
279
         * sin shearing aplicado.
280
         * @return Extent
281
         */
282
        public Extent getExtentWithoutRot();
283
        
284
        /**
285
         * Obtiene la matriz de transformaci?n del propio raster. Esta matriz es la
286
         * encargada de convertir las coordenadas de la petici?n en coordenadas a las
287
         * que se pide a la libreria. En gdal, por ejemplo, se piden las coordenadas a
288
         * la libreria en coordenadas pixel por lo que esta matriz tendr? la
289
         * georreferenciaci?n asociada en el worldfile o cabecera. Otras librerias
290
         * como ermapper la petici?n a la libreria se hace en coordenadas geograficas
291
         * que son las mismas en las que pide el usuario de gvSIG por lo que esta
292
         * matriz en este caso se inicializa con la identidad.
293
         * @return
294
         */
295
        public AffineTransform getOwnAffineTransform();
296
        
297
        /**
298
         * Obtiene la transformaci?n afin aplicada en las peticiones con coordenadas
299
         * reales. Esta corresponde al producto matricial entre la transformaci?n de
300
         * la propia georreferenciaci?n del raster (ownTransformation) y la
301
         * transformaci?n que se le aplique de forma externa. Si esta ?ltima no existe
302
         * ser? la matriz identidad.
303
         * @return Matriz de la transformaci?n af?n.
304
         */
305
        public AffineTransform getAffineTransform();
306
        
307
        /**
308
         * Obtiene la proyecci?n del dataset
309
         * @return IProjection
310
         */
311
        public IProjection getProjection();
312
        
313
        /**
314
         * Obtiene el extent asignado
315
         * @return        Extent
316
         */
317
        public Extent getView();
318
        
319
        /**
320
         * Gets a DatasetMetadata object
321
         * @return
322
         */
323
        public Metadata getMetadata();
324
        
325
        /**
326
         * Gets the object with the color interpretation by band
327
         * @return ColorInterpretation
328
         */
329
        public ColorInterpretation getColorInterpretation();
330
        
331
        /**
332
         * Assigns the object with the color interpretation by band
333
         * @param ci
334
         */
335
        public void setColorInterpretation(ColorInterpretation ci);
336
        
337
        /**
338
         * Define el objeto paleta. Si se define null quiere decir que no tiene paleta
339
         * para su visualizaci?n.
340
         * @param value
341
         */
342
        public void setColorTable(ColorTable value);
343
        
344
        /**
345
         * Gets the {@link ColorTable} or null if the raster
346
         * does not have
347
         * @return
348
         */
349
        public ColorTable getColorTable();
350
        
351
        /**
352
         * Gets the legend as a image. The store could not have implemented this method .
353
         * This is useful above all for WMS but whatever raster layer 
354
         * could return a legend as image.
355
         * @return
356
         */
357
        public Image getImageLegend();
358
        
359
        /**
360
         * Obtiene el estado de transparencia a partir de los estados de transparencia de todos
361
         * los ficheros que lo componen. Si varios de los ficheros que lo componen tienen banda de 
362
         * transparencia estas tendr?n que ser mezcladas sobre una banda de transparencia ?nica.
363
         * @return Objeto FileTransparency con el estado de transparencia
364
         */
365
        public Transparency getTransparency();
366
        
367
        /**
368
         * Cierra los raster asociados.
369
         */
370
        public void close();
371
        
372
        /**
373
         * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
374
         * @param pt Punto a transformar
375
         * @return punto transformado en coordenadas del mundo
376
         */
377
        public Point2D rasterToWorld(Point2D pt);
378
        
379
        /**
380
         * Convierte un punto desde del mundo a coordenadas pixel.
381
         * @param pt Punto a transformar
382
         * @return punto transformado en coordenadas pixel
383
         */
384
        public Point2D worldToRaster(Point2D pt);
385
        
386
        /**
387
         * Asigna una transformaci?n al raster para que se tenga en cuenta en la
388
         * asignaci?n del setView. Esta asignaci?n recalcula el extent, el
389
         * requestExtent y asigna el AffineTransform que se usar? para la
390
         * transformaci?n. Esta transformaci?n ser? considerada como si la imagen
391
         * tuviera asociado un rmf.
392
         * @param t Transformaci?n af?n a aplicar
393
         */
394
        public void setAffineTransform(AffineTransform t);
395
        
396
        /**
397
         * Gets the pixel size
398
         * @return
399
         */
400
        public double getCellSize();
401
        
402
        /**
403
         * Obtiene el tama?o de pixel en X
404
         * @return tama?o de pixel en X
405
         */
406
        public double getPixelSizeX();
407

    
408
        /**
409
         * Obtiene el tama?o de pixel en Y
410
         * @return tama?o de pixel en Y
411
         */
412
        public double getPixelSizeY();
413
        
414
        /**
415
         * Obtiene el valor del raster en la coordenada que se le pasa.
416
         * El valor ser? Double, Int, Byte, etc. dependiendo del tipo de
417
         * raster.
418
         * @param x        coordenada X
419
         * @param y coordenada Y
420
         * @return
421
         */
422
        public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException;
423

    
424
        /**
425
         * Obtiene la proyecci?n asociada al raster. Como todos los dataset del 
426
         * multiDataset deben tener la misma proyecci?n obtenemos esta del primer
427
         * dataset.
428
         * @return Proyecci?n en formato cadena
429
         * @throws RasterDriverException
430
         */
431
        public String getWktProjection() throws RasterDriverException;
432
        
433
        /**
434
         * Dado unas coordenadas reales, un tama?o de buffer y un tama?o de raster. 
435
         * Si el buffer es de mayor tama?o que el raster (supersampleo) quiere decir que 
436
         * por cada pixel de buffer se repiten varios del raster. Esta funci?n calcula el 
437
         * n?mero de pixels de desplazamiento en X e Y que corresponden al primer pixel del
438
         * buffer en la esquina superior izquierda. Esto es necesario porque la coordenada
439
         * solicitada es real y puede no caer sobre un pixel completo. Este calculo es
440
         * util cuando un cliente quiere supersamplear sobre un buffer y que no se lo haga
441
         * el driver autom?ticamente.
442
         * @param dWorldTLX Coordenada real X superior izquierda
443
         * @param dWorldTLY Coordenada real Y superior izquierda
444
         * @param nWidth Ancho del raster
445
         * @param nHeight Alto del raster
446
         * @param bufWidth Ancho del buffer
447
         * @param bufHeight Alto del buffer
448
         * @return Array de cuatro. Los dos primeros elementos son el desplazamiento en X e Y y los dos segundos
449
         * el tama?o en pixels de buffer de un pixel de la imagen en ancho y alto.  
450
         */
451
        public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY,
452
                        double nWidth, double nHeight, int bufWidth, int bufHeight);
453
        
454
        /**
455
         * Sets the nodata value
456
         * @return
457
         */
458
        public void setNoDataValue(NoData value);
459
        
460
        /**
461
         * Obtiene el flag que dice si el raster est? o no georreferenciado
462
         * @return true si est? georreferenciado y false si no lo est?.
463
         */
464
        public boolean isGeoreferenced();
465
        
466
        /**
467
         * Returns true if the provider has several files and all of them has the same extension
468
         * @return
469
         */
470
        public boolean isMultiFile();
471
        
472
        /**
473
         * Returns true if the source of data is a mosaic of images
474
         * @return
475
         */
476
        public boolean isMosaic();
477
        
478
        /**
479
         * Deletes the cache of this layer composed by the files in the provider list
480
         */
481
        public void deleteLayerFromCache();
482
        
483
        /**
484
         * Clone this RasterProvider
485
         * @return
486
         */
487
        public RasterProvider cloneProvider() throws CloneException;
488
        
489
        /**
490
         * Returs the DataParameters
491
         * @return
492
         */
493
        public RasterDataParameters getDataParameters();
494
        
495
        /**
496
         * Lee un bloque completo de datos del raster y devuelve un array tridimensional del tipo correcto. Esta funci?n es util
497
         * para una lectura rapida de todo el fichero sin necesidad de asignar vista.
498
         * @param pos Posici?n donde se empieza  a leer
499
         * @param blockHeight Altura m?xima del bloque leido
500
         * @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
501
         * @throws InvalidSetViewException
502
         * @throws FileNotOpenException
503
         * @throws RasterDriverException
504
         */
505
        public Object readBlock(int pos, int blockHeight, double scale)
506
                throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException;
507

    
508
        
509
        /**
510
         * Carga un objecto desde un serializador usando el tipo del mismo objeto pasado por parametro.
511
         * Usa value para iniciar dicho serializador
512
         * @param class1
513
         * @param value
514
         * @return
515
         * @throws RmfSerializerException
516
         */
517
        @SuppressWarnings("unchecked")
518
        public Object loadObjectFromRmf(Class class1, Object value) throws RmfSerializerException;
519
        
520
        /**
521
         * Guarda en el RMF el objecto actual en caso de que exista un serializador para el.
522
         * El tipo del objeto se especifica en el parametro class1.
523
         * Esto nos puede permitir poder poner a null un valor y encontrar su serializador.
524
         * @param class1
525
         * @param value
526
         * @throws RmfSerializerException 
527
         */
528
        @SuppressWarnings("unchecked")
529
        public void saveObjectToRmf(Class class1, Object value) throws RmfSerializerException;
530
        
531
        /**
532
         * Sets the status information using other provider of the same type. The first action
533
         * of this method should be to check the type of the parameter.
534
         * @param provider
535
         */
536
        public void setStatus(RasterProvider provider);
537
        
538
        /**
539
         * Gets the information in a real point
540
         * @param x
541
         * @param y
542
         * @return
543
         * @throws RemoteServiceException 
544
         */
545
        public String getInfoByPoint(double x, double y, ICancellable cancellable) throws InfoByPointException;
546
        
547
        /**
548
         * Gets the information in a pixel point. Some services need additional 
549
         * information as the window where the request is done 
550
         * @param x
551
         *        X Pixel position
552
         * @param y
553
         *        Y pixel position
554
         * @param bbox
555
         *        Bounding box of the window
556
         * @param w
557
         *        Width in pixels of the window
558
         * @param h
559
         *        Height in pixels of the window
560
         * @param cancellable
561
         * @return
562
         * @throws RemoteServiceException
563
         */
564
        public String getInfoByPoint(int x, int y, Extent bbox, int w, int h, ICancellable cancellable) throws InfoByPointException;
565
        
566
        /**
567
         * Gets the tile cache data server
568
         * @return
569
         */
570
        public TileServer getTileServer();
571
        
572
        /**
573
         * Some sevices has neither limits nor pixel size. For instance, WebMapService 
574
         * is a service of this type if the size is not fixed. Other services, like
575
         * WMTS are enclosed too but in this case it will have resolution by level.
576
         * This method returns true if the data source is enclosed.
577
         * @return
578
         */
579
        public boolean isRasterEnclosed();
580
        
581
        /**
582
         * Gets the rmf file path. This method will have to be redefined by providers
583
         * with a different path
584
         * @return
585
         */
586
        public String getRMFFile();
587
        
588
        /**
589
         * Selects the subdataset.
590
         */
591
        public void selectSubdataset();
592
        
593
        /**
594
         * Gets the list of supported formats
595
         * @return
596
         */
597
        public String[] getFormatList();
598
        
599
        /**
600
         * Returns the source type (FILE, POSTGIS, REMOTE,...)
601
         * @return
602
         */
603
        public int getSourceType();
604
        
605
        /**
606
         * This function returns true if the image to be loaded needs a enhanced filter or
607
         * doesn't. It depends on the format, number of bands, type of data and so on.
608
         * @return The default value is false but each driver can change this value.
609
         */
610
        public boolean needEnhanced();
611
        
612
        /**
613
         * Gets the time serial information
614
         * @return
615
         * @throws RmfSerializerException 
616
         */
617
        public TimeSeries getTimeSerials() throws RmfSerializerException;
618
        
619
        /**
620
         * Sets the time serial information
621
         * @throws RmfSerializerException 
622
         */
623
        public void setTimeSerials(TimeSeries serialInfo) throws RmfSerializerException;
624

    
625
        /**
626
         * Gets the set of data selected in the {@link RasterQuery}
627
         * @param q
628
         * @return
629
         * @throws RasterDriverException 
630
         * @throws ProcessInterruptedException 
631
         */
632
        public Buffer getDataSet(RasterQuery query) throws ProcessInterruptedException, RasterDriverException;
633
        
634
}