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 @ 1401

History | View | Annotate | Download (19.3 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
         * Sets the provider projection
309
         * @return IProjection
310
         */
311
        public IProjection getProjection();
312
        
313
        /**
314
         * Gets the provider projection
315
         * @return IProjection
316
         */
317
        public void setProjection(IProjection proj);
318
        
319
        /**
320
         * Obtiene el extent asignado
321
         * @return        Extent
322
         */
323
        public Extent getView();
324
        
325
        /**
326
         * Gets a DatasetMetadata object
327
         * @return
328
         */
329
        public Metadata getMetadata();
330
        
331
        /**
332
         * Gets the object with the color interpretation by band
333
         * @return ColorInterpretation
334
         */
335
        public ColorInterpretation getColorInterpretation();
336
        
337
        /**
338
         * Assigns the object with the color interpretation by band
339
         * @param ci
340
         */
341
        public void setColorInterpretation(ColorInterpretation ci);
342
        
343
        /**
344
         * Define el objeto paleta. Si se define null quiere decir que no tiene paleta
345
         * para su visualizaci?n.
346
         * @param value
347
         */
348
        public void setColorTable(ColorTable value);
349
        
350
        /**
351
         * Gets the {@link ColorTable} or null if the raster
352
         * does not have
353
         * @return
354
         */
355
        public ColorTable getColorTable();
356
        
357
        /**
358
         * Gets the legend as a image. The store could not have implemented this method .
359
         * This is useful above all for WMS but whatever raster layer 
360
         * could return a legend as image.
361
         * @return
362
         */
363
        public Image getImageLegend();
364
        
365
        /**
366
         * Obtiene el estado de transparencia a partir de los estados de transparencia de todos
367
         * los ficheros que lo componen. Si varios de los ficheros que lo componen tienen banda de 
368
         * transparencia estas tendr?n que ser mezcladas sobre una banda de transparencia ?nica.
369
         * @return Objeto FileTransparency con el estado de transparencia
370
         */
371
        public Transparency getTransparency();
372
        
373
        /**
374
         * Cierra los raster asociados.
375
         */
376
        public void close();
377
        
378
        /**
379
         * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
380
         * @param pt Punto a transformar
381
         * @return punto transformado en coordenadas del mundo
382
         */
383
        public Point2D rasterToWorld(Point2D pt);
384
        
385
        /**
386
         * Convierte un punto desde del mundo a coordenadas pixel.
387
         * @param pt Punto a transformar
388
         * @return punto transformado en coordenadas pixel
389
         */
390
        public Point2D worldToRaster(Point2D pt);
391
        
392
        /**
393
         * Asigna una transformaci?n al raster para que se tenga en cuenta en la
394
         * asignaci?n del setView. Esta asignaci?n recalcula el extent, el
395
         * requestExtent y asigna el AffineTransform que se usar? para la
396
         * transformaci?n. Esta transformaci?n ser? considerada como si la imagen
397
         * tuviera asociado un rmf.
398
         * @param t Transformaci?n af?n a aplicar
399
         */
400
        public void setAffineTransform(AffineTransform t);
401
        
402
        /**
403
         * Gets the pixel size
404
         * @return
405
         */
406
        public double getCellSize();
407
        
408
        /**
409
         * Obtiene el tama?o de pixel en X
410
         * @return tama?o de pixel en X
411
         */
412
        public double getPixelSizeX();
413

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

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

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

    
631
        /**
632
         * Gets the set of data selected in the {@link RasterQuery}
633
         * @param q
634
         * @return
635
         * @throws RasterDriverException 
636
         * @throws ProcessInterruptedException 
637
         */
638
        public Buffer getDataSet(RasterQuery query) throws ProcessInterruptedException, RasterDriverException;
639
        
640
}