gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / store / DefaultRasterStore.java @ 2311
History | View | Annotate | Download (32.6 KB)
1 |
package org.gvsig.raster.impl.store; |
---|---|
2 |
|
3 |
import java.awt.Image; |
4 |
import java.awt.geom.AffineTransform; |
5 |
import java.awt.geom.Point2D; |
6 |
import java.awt.geom.Rectangle2D; |
7 |
import java.io.File; |
8 |
import java.util.ArrayList; |
9 |
import java.util.Collection; |
10 |
import java.util.List; |
11 |
|
12 |
import org.cresques.cts.IProjection; |
13 |
import org.gvsig.compat.net.ICancellable; |
14 |
import org.gvsig.fmap.crs.CRSFactory; |
15 |
import org.gvsig.fmap.dal.DALLocator; |
16 |
import org.gvsig.fmap.dal.DataStoreParameters; |
17 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
18 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
19 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
20 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
21 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList; |
22 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
23 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
24 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
25 |
import org.gvsig.fmap.dal.coverage.exception.CloneException; |
26 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
27 |
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException; |
28 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
29 |
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException; |
30 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
31 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
32 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
33 |
import org.gvsig.fmap.dal.coverage.exception.OperationNotSupportedException; |
34 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
35 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
36 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
37 |
import org.gvsig.fmap.dal.coverage.exception.TimeException; |
38 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
39 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
40 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
41 |
import org.gvsig.fmap.dal.coverage.grid.render.Render; |
42 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
43 |
import org.gvsig.fmap.dal.coverage.store.parameter.MultiDimensionalStoreParameters; |
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.HistogramComputer; |
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.exception.InitializeException; |
53 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
54 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
55 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
56 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
57 |
import org.gvsig.fmap.geom.GeometryLocator; |
58 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
59 |
import org.gvsig.fmap.geom.primitive.Envelope; |
60 |
import org.gvsig.raster.cache.tile.Tile; |
61 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
62 |
import org.gvsig.raster.impl.DefaultRasterManager; |
63 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
64 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
65 |
import org.gvsig.raster.impl.grid.roi.VectorialROIsReader; |
66 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
67 |
import org.gvsig.raster.impl.provider.RasterProvider; |
68 |
import org.gvsig.raster.impl.provider.TiledRasterProvider; |
69 |
import org.gvsig.raster.impl.store.properties.MultiDataStoreMetadata; |
70 |
import org.gvsig.raster.roi.ROI; |
71 |
import org.gvsig.raster.roi.ROIReader; |
72 |
import org.gvsig.raster.util.persistence.PersistencyFilterParam; |
73 |
import org.gvsig.timesupport.Interval; |
74 |
import org.gvsig.timesupport.Time; |
75 |
import org.gvsig.tools.ToolsLocator; |
76 |
import org.gvsig.tools.dynobject.DynStruct; |
77 |
import org.gvsig.tools.persistence.PersistenceManager; |
78 |
import org.gvsig.tools.persistence.PersistentState; |
79 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
80 |
import org.slf4j.Logger; |
81 |
import org.slf4j.LoggerFactory; |
82 |
|
83 |
/**
|
84 |
* Default data store for raster
|
85 |
*
|
86 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
87 |
*/
|
88 |
public class DefaultRasterStore extends AbstractRasterDataStore { |
89 |
public static final String PERSISTENT_NAME = "DefaultRasterStore_Persistent"; |
90 |
public static final String PERSISTENT_DESCRIPTION = "DefaultRasterStore Persistent"; |
91 |
private static final Logger logger = LoggerFactory.getLogger(DefaultRasterStore.class); |
92 |
|
93 |
/*
|
94 |
* TODO: Refactoring de ROIS
|
95 |
* Una capa r?ster deber?a poder tener ROIs de tipo r?ster y de tipo vectorial asociados. Adem?s
|
96 |
* debe poder tener una lista de estos por lo que ser?a necesario un interfaz en la que se pueda
|
97 |
* seleccionar la capa de ROIs a utilizar.
|
98 |
*
|
99 |
* Por otro lado, las ROIs deben ser del proveedor de datos. Este con tendr? una lista de estos.
|
100 |
* Las ROIs deber?an modelarse como proveedores de datos de tipo r?ster o de tipo vectorial, ya que
|
101 |
* tener una lista de geometr?as en memoria como hasta ahora puede ser muy poco eficiente en caso
|
102 |
* de que la lista de ROIs sea muy grande. Adem?s deber?a optimizarse el acceso isInside para que las
|
103 |
* operaciones con ROIs asociados sean lo m?s r?pidas posible.
|
104 |
*/
|
105 |
private List<ROI> rois = null; |
106 |
|
107 |
//protected boolean forceToMemory = false;
|
108 |
|
109 |
public DefaultRasterStore() {
|
110 |
super();
|
111 |
} |
112 |
|
113 |
public void reload() { |
114 |
provider.reload(); |
115 |
} |
116 |
|
117 |
public void setProvider(RasterProvider provider) { |
118 |
this.provider = provider;
|
119 |
parameters = (DataStoreParameters)provider.getDataParameters(); |
120 |
initializeBandList(); |
121 |
} |
122 |
|
123 |
public void setParameters(DataStoreParameters p) { |
124 |
this.parameters = p;
|
125 |
} |
126 |
|
127 |
public void setProvider(CoverageStoreProvider prov) { |
128 |
if(prov instanceof RasterProvider) |
129 |
setProvider((RasterProvider)prov); |
130 |
} |
131 |
|
132 |
public String getName() { |
133 |
if(provider != null) |
134 |
return provider.getURI();
|
135 |
return null; |
136 |
} |
137 |
|
138 |
public boolean needEnhanced() { |
139 |
if(provider != null) |
140 |
return provider.needEnhanced();
|
141 |
return false; |
142 |
} |
143 |
|
144 |
public boolean isTiled() { |
145 |
return provider.isTiled();
|
146 |
} |
147 |
|
148 |
public boolean isMosaic() { |
149 |
return provider.isMosaic();
|
150 |
} |
151 |
|
152 |
public Tile getTile(SpiRasterQuery q) throws TileGettingException { |
153 |
TiledRasterProvider tiledProv = ((TiledRasterProvider)provider); |
154 |
return tiledProv.getTile(q);
|
155 |
} |
156 |
|
157 |
//******************************
|
158 |
//Setters and Getters
|
159 |
//******************************
|
160 |
|
161 |
/**
|
162 |
* Calcula el tama?o de los ficheros en disco
|
163 |
* @return tama?o en bytes de todos los ficheros de la lista
|
164 |
*/
|
165 |
public long getFileSize() { |
166 |
if(provider != null) { |
167 |
long size = 0; |
168 |
long[] fSize = provider.getFileSizeByProvider(); |
169 |
if(fSize != null && fSize.length > 0) { |
170 |
for (int j = 0; j < fSize.length; j++) { |
171 |
size += fSize[j]; |
172 |
} |
173 |
} |
174 |
return size;
|
175 |
} |
176 |
return 0; |
177 |
} |
178 |
|
179 |
public double getHeight() { |
180 |
return provider.getHeight();
|
181 |
} |
182 |
|
183 |
public double getWidth() { |
184 |
return provider.getWidth();
|
185 |
} |
186 |
|
187 |
public double getCellSize() { |
188 |
try {
|
189 |
Extent e = getExtent(); |
190 |
double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
|
191 |
return dCellsize;
|
192 |
} catch (NullPointerException e) { |
193 |
return 1; |
194 |
} |
195 |
} |
196 |
|
197 |
public int getBandCount() { |
198 |
return provider.getBandCount();
|
199 |
} |
200 |
|
201 |
public int[] getDataType() { |
202 |
return provider.getDataType();
|
203 |
} |
204 |
|
205 |
public BandList getBands() {
|
206 |
return storeBandList;
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Obtiene la coordenada X m?nima de toda la lista
|
211 |
* @return Coordenada X m?nima
|
212 |
*/
|
213 |
public double getMinX() { |
214 |
return provider.getExtent().getMin().getX();
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Obtiene la coordenada Y m?nima de toda la lista
|
219 |
* @return Coordenada Y m?nima
|
220 |
*/
|
221 |
public double getMinY() { |
222 |
return provider.getExtent().getMin().getY();
|
223 |
} |
224 |
|
225 |
/**
|
226 |
* Obtiene la coordenada Y m?xima de toda la lista
|
227 |
* @return Coordenada Y m?xima
|
228 |
*/
|
229 |
public double getMaxX() { |
230 |
return provider.getExtent().getMax().getX(); }
|
231 |
|
232 |
/**
|
233 |
* Obtiene la coordenada Y m?xima de toda la lista
|
234 |
* @return Coordenada Y m?xima
|
235 |
*/
|
236 |
public double getMaxY() { |
237 |
return provider.getExtent().getMax().getY();
|
238 |
} |
239 |
|
240 |
public NoData getNoDataValue() {
|
241 |
if(provider != null) |
242 |
return provider.getNoDataValue();
|
243 |
return null; |
244 |
} |
245 |
|
246 |
public void setNoDataValue(NoData value) { |
247 |
provider.setNoDataValue(value); |
248 |
} |
249 |
|
250 |
public Extent getExtent() {
|
251 |
Extent e = provider.getExtent(); |
252 |
if (coordTrans != null) { |
253 |
e = e.convert(coordTrans); |
254 |
} |
255 |
return e;
|
256 |
} |
257 |
|
258 |
/**
|
259 |
* Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el
|
260 |
* extent m?ximo del raster. Para un raster sin rotar ser? igual al extent
|
261 |
* pero para un raster rotado ser? igual al extent del raster como si no
|
262 |
* tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la
|
263 |
* vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing
|
264 |
* aplicado.
|
265 |
* @return Extent
|
266 |
*/
|
267 |
public Extent getExtentForRequest() {
|
268 |
return provider.getExtentWithoutRot();
|
269 |
} |
270 |
|
271 |
public Extent getLastSelectedView(){
|
272 |
return provider.getView();
|
273 |
} |
274 |
|
275 |
public ColorTable getColorTable(int i){ |
276 |
return provider.getColorTable();
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* Obtiene la lista de paletas correspondiente a todos los ficheros que forman el GeoMultiRasterFile
|
281 |
* @return Paleta asociada a este o null si no tiene. Una posici?n null en el array tambi?n indica que
|
282 |
* para ese fichero no hay paletas asociadas.
|
283 |
*/
|
284 |
public ColorTable getColorTables() {
|
285 |
return provider.getColorTable();
|
286 |
} |
287 |
|
288 |
public ColorTable getColorTable() {
|
289 |
//Solo tiene sentido si tiene un fichero y ese fichero tiene una sola banda
|
290 |
if(provider != null) |
291 |
return provider.getColorTable();
|
292 |
return null; |
293 |
} |
294 |
|
295 |
/**
|
296 |
* Sets the color table
|
297 |
* @param colorTable
|
298 |
*/
|
299 |
public void setColorTable(ColorTable colorTable) { |
300 |
provider.setColorTable(colorTable); |
301 |
} |
302 |
|
303 |
public ColorTable getColorTable(String fileName){ |
304 |
return provider.getColorTable();
|
305 |
} |
306 |
|
307 |
public Point2D rasterToWorld(Point2D pt) { |
308 |
return provider.rasterToWorld(pt);
|
309 |
} |
310 |
|
311 |
public Point2D worldToRaster(Point2D pt) { |
312 |
return provider.worldToRaster(pt);
|
313 |
} |
314 |
|
315 |
public boolean isGeoreferenced() { |
316 |
return provider.isGeoreferenced();
|
317 |
} |
318 |
|
319 |
public double getPixelSizeX() { |
320 |
return provider.getPixelSizeX();
|
321 |
} |
322 |
|
323 |
public double getPixelSizeY() { |
324 |
return provider.getPixelSizeY();
|
325 |
} |
326 |
|
327 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
328 |
return provider.getData(x, y, band);
|
329 |
} |
330 |
|
331 |
public String getWktProjection() throws RasterDriverException { |
332 |
if(provider != null) |
333 |
return provider.getWktProjection();
|
334 |
return null; |
335 |
} |
336 |
|
337 |
public boolean isInside(Point2D p) { |
338 |
if(provider != null) |
339 |
return provider.isInside(p);
|
340 |
return false; |
341 |
} |
342 |
|
343 |
public RasterDataStore getDataStore() {
|
344 |
return this; |
345 |
} |
346 |
|
347 |
public AffineTransform getAffineTransform(int band){ |
348 |
return provider.getAffineTransform();
|
349 |
} |
350 |
|
351 |
public void setAffineTransform(AffineTransform transf) { |
352 |
provider.setAffineTransform(transf); |
353 |
} |
354 |
|
355 |
/**
|
356 |
* Obtiene la matriz de transformaci?n del propio raster. Esta matriz es la encargada
|
357 |
* de convertir las coordenadas de la petici?n en coordenadas a las que se pide a la libreria.
|
358 |
* En gdal, por ejemplo, se piden las coordenadas a la libreria en coordenadas pixel por lo que
|
359 |
* esta matriz tendr? la georreferenciaci?n asociada en el worldfile o cabecera. Otras librerias como
|
360 |
* ermapper la petici?n a la libreria se hace en coordenadas geograficas que son las mismas en las
|
361 |
* que pide el usuario de gvSIG por lo que esta matriz en este caso se inicializa con la identidad.
|
362 |
* @return
|
363 |
*/
|
364 |
public AffineTransform getOwnTransformation() { |
365 |
return provider.getOwnAffineTransform();
|
366 |
} |
367 |
|
368 |
public boolean isRotated() { |
369 |
if(provider != null) |
370 |
return provider.isRotated();
|
371 |
return false; |
372 |
} |
373 |
|
374 |
public void setDrawableBands(int[] db) { |
375 |
getBands().setDrawableBands(db); |
376 |
} |
377 |
|
378 |
public int[] getDrawableBands() { |
379 |
return getBands().getDrawableBands();
|
380 |
} |
381 |
|
382 |
public void clearDrawableBands() { |
383 |
getBands().clearDrawableBands(); |
384 |
} |
385 |
|
386 |
public void addDrawableBand(int posRasterBuf, int imageBand) { |
387 |
getBands().addDrawableBand(posRasterBuf, imageBand); |
388 |
} |
389 |
|
390 |
/*public boolean isReadOnly() {
|
391 |
return readOnly;
|
392 |
}
|
393 |
|
394 |
public void setReadOnly(boolean readOnly) {
|
395 |
this.readOnly = readOnly;
|
396 |
if(readOnly)
|
397 |
this.forceToMemory = false;
|
398 |
}
|
399 |
|
400 |
public void setMemoryBuffer(boolean memory) {
|
401 |
this.forceToMemory = memory;
|
402 |
if(memory)
|
403 |
this.readOnly = false;
|
404 |
}
|
405 |
|
406 |
public boolean isMemoryBuffer() {
|
407 |
return forceToMemory;
|
408 |
}*/
|
409 |
|
410 |
public void deleteLayerFromCache() { |
411 |
provider.deleteLayerFromCache(); |
412 |
} |
413 |
|
414 |
public boolean isMultiFile() { |
415 |
return provider.isMultiFile();
|
416 |
} |
417 |
|
418 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
419 |
return provider.getOverviewWidth(band, overview);
|
420 |
} |
421 |
|
422 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
423 |
return provider.getOverviewHeight(band, overview);
|
424 |
} |
425 |
|
426 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
427 |
if(band >= getBandCount())
|
428 |
throw new BandAccessException("Wrong band"); |
429 |
return provider.getOverviewCount(band);
|
430 |
} |
431 |
|
432 |
public boolean overviewsSupport() { |
433 |
if(provider != null) |
434 |
return provider.isOverviewsSupported();
|
435 |
return false; |
436 |
} |
437 |
|
438 |
public void saveGeoreferencingToRmf() throws RmfSerializerException { |
439 |
provider.saveObjectToRmf(AbstractRasterProvider.class, provider); |
440 |
} |
441 |
|
442 |
public void saveSerialInfoToRmf(TimeSeries serialInfo) throws RmfSerializerException { |
443 |
provider.saveObjectToRmf(TimeSeries.class, serialInfo); |
444 |
} |
445 |
|
446 |
public void saveColorTableToRmf(ColorTable table) throws RmfSerializerException { |
447 |
provider.saveObjectToRmf(ColorTable.class, table); |
448 |
} |
449 |
|
450 |
public void saveGeoPointListToRmf(GeoPointList pointList) throws RmfSerializerException { |
451 |
provider.saveObjectToRmf(GeoPointList.class, pointList); |
452 |
} |
453 |
|
454 |
public void saveROIFileListToRmf(List<File> fileList) throws RmfSerializerException { |
455 |
provider.saveObjectToRmf(List.class, fileList);
|
456 |
} |
457 |
|
458 |
public List<File> getROIFileListFromRmf() { |
459 |
try {
|
460 |
List<File> fileList = new ArrayList<File>(); |
461 |
provider.loadObjectFromRmf(List.class, fileList);
|
462 |
return fileList;
|
463 |
} catch (RmfSerializerException e) {
|
464 |
} |
465 |
return null; |
466 |
} |
467 |
|
468 |
public boolean loadSerialInfoFromRmf(TimeSeries serialInfo) { |
469 |
try {
|
470 |
provider.loadObjectFromRmf(TimeSeries.class, serialInfo); |
471 |
return true; |
472 |
} catch (RmfSerializerException e) {
|
473 |
//Prueba hasta que alguno tiene la informaci?n
|
474 |
} |
475 |
return false; |
476 |
} |
477 |
|
478 |
public Extent getView() {
|
479 |
if(provider != null) |
480 |
return provider.getView();
|
481 |
return null; |
482 |
} |
483 |
|
484 |
public Extent getExtentWithoutRot() {
|
485 |
if(provider != null) |
486 |
return provider.getExtentWithoutRot();
|
487 |
return null; |
488 |
} |
489 |
|
490 |
public AffineTransform getOwnAffineTransform() { |
491 |
if(provider != null) |
492 |
return provider.getOwnAffineTransform();
|
493 |
return null; |
494 |
} |
495 |
|
496 |
public AffineTransform getAffineTransform() { |
497 |
if(provider != null) { |
498 |
AffineTransform at = provider.getAffineTransform();
|
499 |
/*if (coordTrans != null) {
|
500 |
Point2D scale = new Point2D.Double(at.getTranslateX() + at.getScaleX(), at.getTranslateY() + at.getScaleY());
|
501 |
Point2D translate = new Point2D.Double(at.getTranslateX(), at.getTranslateY());
|
502 |
scale = coordTrans.convert(scale, scale);
|
503 |
translate = coordTrans.convert(translate, translate);
|
504 |
double sX = scale.getX() - translate.getX();
|
505 |
double sY = scale.getY() - translate.getY();
|
506 |
at = new AffineTransform(
|
507 |
sX,
|
508 |
at.getShearY(),
|
509 |
at.getShearX(),
|
510 |
sY,
|
511 |
translate.getX(),
|
512 |
translate.getY());
|
513 |
}*/
|
514 |
return at;
|
515 |
} |
516 |
return null; |
517 |
} |
518 |
|
519 |
public IProjection getProjection() {
|
520 |
if(provider != null) |
521 |
return provider.getProjection();
|
522 |
return null; |
523 |
} |
524 |
|
525 |
public void setProjection(IProjection proj, boolean persist) throws RmfSerializerException { |
526 |
if(provider != null) |
527 |
provider.setProjection(proj, persist); |
528 |
} |
529 |
|
530 |
public Statistics getStatistics() {
|
531 |
if(provider != null) |
532 |
return provider.getStatistics();
|
533 |
return null; |
534 |
} |
535 |
|
536 |
public void setStatistics(Statistics stats) throws RmfSerializerException { |
537 |
if(provider != null) |
538 |
provider.setStatistics(stats); |
539 |
} |
540 |
|
541 |
public HistogramComputer getHistogramComputer() {
|
542 |
if(provider != null) |
543 |
return provider.getHistogramComputer();
|
544 |
return null; |
545 |
} |
546 |
|
547 |
public Metadata getMetadata() {
|
548 |
if(provider != null) |
549 |
return provider.getMetadata();
|
550 |
return null; |
551 |
} |
552 |
|
553 |
public Transparency getTransparency() { |
554 |
if(provider != null) { |
555 |
provider.getTransparency().setNoData(getNoDataValue()); |
556 |
return provider.getTransparency();
|
557 |
} |
558 |
return null; |
559 |
} |
560 |
|
561 |
public ColorInterpretation getColorInterpretation() {
|
562 |
return provider.getColorInterpretation();
|
563 |
} |
564 |
|
565 |
public boolean isReproyectable() { |
566 |
if(provider != null) |
567 |
return (provider.isReproyectable());
|
568 |
return false; |
569 |
} |
570 |
|
571 |
public String getMetadataName() { |
572 |
if(provider != null) |
573 |
return provider.getName();
|
574 |
return null; |
575 |
} |
576 |
|
577 |
public RasterDataStore cloneDataStore() throws CloneException { |
578 |
DefaultRasterStore ds = new DefaultRasterStore();
|
579 |
ds.parameters = getParameters(); |
580 |
ds.provider = provider.cloneProvider(); |
581 |
|
582 |
int[] bands = new int[1]; |
583 |
bands[0] = provider.getBandCount();
|
584 |
ds.metadata = new MultiDataStoreMetadata(bands);
|
585 |
((MultiDataStoreMetadata)ds.metadata).add(provider.getMetadata()); |
586 |
|
587 |
ds.storeBandList = (BandListImpl)storeBandList.clone(); |
588 |
return ds;
|
589 |
} |
590 |
|
591 |
public boolean isOpen() { |
592 |
if(provider == null) |
593 |
return false; |
594 |
return provider.isOpen();
|
595 |
} |
596 |
|
597 |
public CoverageStoreProvider getProvider() {
|
598 |
return provider;
|
599 |
} |
600 |
|
601 |
public String getInfoByPoint(double x, double y, ICancellable cancellable) throws InfoByPointException { |
602 |
return ((RasterProvider)getProvider()).getInfoByPoint(x, y, cancellable);
|
603 |
} |
604 |
|
605 |
public String getInfoByPoint(double x, double y, Extent bbox, int w, int h, ICancellable cancellable) throws InfoByPointException { |
606 |
return ((RasterProvider)getProvider()).getInfoByPoint((int)x, (int)y, bbox, w, h, cancellable); |
607 |
} |
608 |
|
609 |
public void goTo(int position) throws OperationNotSupportedException { |
610 |
if(!isTimeSupportedByTheProvider())
|
611 |
throw new OperationNotSupportedException("Not supported for a RasterDataset"); |
612 |
if(getParameters() instanceof MultiDimensionalStoreParameters) { |
613 |
((MultiDimensionalStoreParameters)getParameters()).goTo(position); |
614 |
} |
615 |
} |
616 |
|
617 |
public void selectNext() throws OperationNotSupportedException { |
618 |
if(!isTimeSupportedByTheProvider())
|
619 |
throw new OperationNotSupportedException("Not supported for a RasterDataset"); |
620 |
if(getParameters() instanceof MultiDimensionalStoreParameters) { |
621 |
((MultiDimensionalStoreParameters)getParameters()).selectNextInstant(); |
622 |
} |
623 |
} |
624 |
|
625 |
public void selectPrev() throws OperationNotSupportedException { |
626 |
if(!isTimeSupportedByTheProvider())
|
627 |
throw new OperationNotSupportedException("Not supported for a RasterDataset"); |
628 |
if(getParameters() instanceof MultiDimensionalStoreParameters) { |
629 |
((MultiDimensionalStoreParameters)getParameters()).selectPrevInstant(); |
630 |
} |
631 |
} |
632 |
|
633 |
public void setTime(Time time) throws TimeException, OperationNotSupportedException { |
634 |
if(!isTimeSupportedByTheProvider())
|
635 |
throw new OperationNotSupportedException("Not supported for a RasterDataset"); |
636 |
|
637 |
} |
638 |
|
639 |
/**
|
640 |
* Returns true whether all providers support time
|
641 |
* @return
|
642 |
*/
|
643 |
private boolean isTimeSupportedByTheProvider() { |
644 |
if(provider != null) |
645 |
return provider.isTimeSupported();
|
646 |
return false; |
647 |
} |
648 |
|
649 |
public boolean isRasterEnclosed() { |
650 |
if(provider != null) |
651 |
return provider.isRasterEnclosed();
|
652 |
return false; |
653 |
} |
654 |
|
655 |
public Extent getCoordsInLevel(Point2D viewCenter, int level, int w, int h) { |
656 |
try {
|
657 |
return ((TiledRasterProvider)provider).getCoordsInLevel(viewCenter, level, w, h);
|
658 |
} catch (ClassCastException e) { |
659 |
return null; |
660 |
} |
661 |
} |
662 |
|
663 |
public Extent getCoordsInTheNearestLevel(Extent extent, int w, int h) { |
664 |
try {
|
665 |
return ((TiledRasterProvider)provider).getCoordsInTheNearestLevel(extent, w, h);
|
666 |
} catch (ClassCastException e) { |
667 |
return null; |
668 |
} |
669 |
} |
670 |
|
671 |
public int getZoomLevels() { |
672 |
try {
|
673 |
return ((TiledRasterProvider)provider).getZoomLevels();
|
674 |
} catch (ClassCastException e) { |
675 |
return -1; |
676 |
} |
677 |
} |
678 |
|
679 |
public int getNearestLevel(double pixelSize) { |
680 |
try {
|
681 |
return ((TiledRasterProvider)provider).getNearestLevel(pixelSize);
|
682 |
} catch (ClassCastException e) { |
683 |
return -1; |
684 |
} |
685 |
} |
686 |
|
687 |
public void setTileServer(Class<?> tileServer) throws InitializeException { |
688 |
if(provider instanceof TiledRasterProvider) { |
689 |
((TiledRasterProvider)provider).setTileServer(tileServer); |
690 |
} |
691 |
} |
692 |
|
693 |
public RasterDataParameters getInternalParameters() {
|
694 |
if(provider instanceof TiledRasterProvider) { |
695 |
AbstractRasterProvider prov = (AbstractRasterProvider)((TiledRasterProvider)provider).getInternalProvider(); |
696 |
return prov.getDataParameters();
|
697 |
} |
698 |
return (RasterDataParameters)getParameters();
|
699 |
} |
700 |
|
701 |
public RasterDataStore newDataStore() {
|
702 |
if(provider != null) { |
703 |
RasterManager manager = (DefaultRasterManager)RasterLocator.getManager(); |
704 |
RasterDataStore newDataStore = null;
|
705 |
try {
|
706 |
newDataStore = manager.getProviderServices().open((DataStoreParameters)parameters); |
707 |
if(newDataStore instanceof DefaultRasterStore) { |
708 |
((DefaultRasterStore)newDataStore).setStatistics(getStatistics()); |
709 |
} |
710 |
return newDataStore;
|
711 |
} catch (NotSupportedExtensionException e) {
|
712 |
return null; |
713 |
} catch (RasterDriverException e) {
|
714 |
return null; |
715 |
} catch (RmfSerializerException e) {
|
716 |
return newDataStore;
|
717 |
} |
718 |
} |
719 |
return null; |
720 |
} |
721 |
|
722 |
public RasterDataStore newNotTiledDataStore() {
|
723 |
if(provider != null) { |
724 |
RasterManager manager = (DefaultRasterManager)RasterLocator.getManager(); |
725 |
RasterDataStore newDataStore = null;
|
726 |
try {
|
727 |
DataStoreParameters newParams = (DataStoreParameters)parameters; |
728 |
if(this.isTiled()) { |
729 |
newParams = ((TiledRasterProvider)getProvider()).getInternalProvider().getDataParameters(); |
730 |
} |
731 |
|
732 |
newDataStore = manager.getProviderServices().open(newParams); |
733 |
if(newDataStore instanceof DefaultRasterStore) { |
734 |
((DefaultRasterStore)newDataStore).setStatistics(getStatistics()); |
735 |
} |
736 |
return newDataStore;
|
737 |
} catch (NotSupportedExtensionException e) {
|
738 |
return null; |
739 |
} catch (RasterDriverException e) {
|
740 |
return null; |
741 |
} catch (RmfSerializerException e) {
|
742 |
return newDataStore;
|
743 |
} |
744 |
} |
745 |
return null; |
746 |
} |
747 |
|
748 |
public String[] getURIByProvider() { |
749 |
return provider.getURIByProvider();
|
750 |
} |
751 |
|
752 |
public long[] getFileSizeByProvider() { |
753 |
return provider.getFileSizeByProvider();
|
754 |
} |
755 |
|
756 |
public int getProviderCount() { |
757 |
return provider.getInternalProviderCount();
|
758 |
} |
759 |
|
760 |
public int[] getBandCountByProvider() { |
761 |
return provider.getBandCountByProvider();
|
762 |
} |
763 |
|
764 |
public RasterDataParameters[] getDataParametersByProvider() { |
765 |
RasterDataParameters[] res = new RasterDataParameters[getProviderCount()]; |
766 |
for (int i = 0; i < res.length; i++) { |
767 |
res[i] = (RasterDataParameters)provider.getInternalProvider(i).getDataParameters(); |
768 |
} |
769 |
return res;
|
770 |
} |
771 |
|
772 |
public Metadata[] getMetadataByProvider() { |
773 |
Metadata[] res = new Metadata[getProviderCount()]; |
774 |
for (int i = 0; i < res.length; i++) { |
775 |
res[i] = provider.getInternalProvider(i).getMetadata(); |
776 |
} |
777 |
return res;
|
778 |
} |
779 |
|
780 |
public int[] getOverviewCountByProvider(int band) throws BandAccessException { |
781 |
int[] res = new int[getProviderCount()]; |
782 |
for (int i = 0; i < res.length; i++) { |
783 |
try {
|
784 |
res[i] = provider.getInternalProvider(i).getOverviewCount(band); |
785 |
} catch (RasterDriverException e) {
|
786 |
throw new BandAccessException("", e); |
787 |
} |
788 |
} |
789 |
return res;
|
790 |
} |
791 |
|
792 |
public String[] getOverviewSizeByProvider(int band, int overview) throws BandAccessException { |
793 |
String[] res = new String[getProviderCount()]; |
794 |
for (int i = 0; i < res.length; i++) { |
795 |
try {
|
796 |
res[i] = provider.getInternalProvider(i).getOverviewWidth(band, overview) + |
797 |
"x" +
|
798 |
provider.getInternalProvider(i).getOverviewHeight(band, overview); |
799 |
} catch (RasterDriverException e) {
|
800 |
throw new BandAccessException("", e); |
801 |
} |
802 |
} |
803 |
return res;
|
804 |
} |
805 |
|
806 |
public AffineTransform[] getAffineTransformByProvider() { |
807 |
AffineTransform[] res = new AffineTransform[getProviderCount()]; |
808 |
for (int i = 0; i < res.length; i++) { |
809 |
res[i] = provider.getInternalProvider(i).getAffineTransform(); |
810 |
} |
811 |
return res;
|
812 |
} |
813 |
|
814 |
public double[] getHeightByProvider() { |
815 |
double[] res = new double[getProviderCount()]; |
816 |
for (int i = 0; i < res.length; i++) { |
817 |
res[i] = provider.getInternalProvider(i).getHeight(); |
818 |
} |
819 |
return res;
|
820 |
} |
821 |
|
822 |
public double[] getWidthByProvider() { |
823 |
double[] res = new double[getProviderCount()]; |
824 |
for (int i = 0; i < res.length; i++) { |
825 |
res[i] = provider.getInternalProvider(i).getWidth(); |
826 |
} |
827 |
return res;
|
828 |
} |
829 |
|
830 |
public void addFile(String file) throws InvalidSourceException { |
831 |
provider.addFile(file); |
832 |
} |
833 |
|
834 |
public void removeFile(String file) { |
835 |
provider.removeFile(file); |
836 |
storeBandList.removeBands(file); |
837 |
} |
838 |
|
839 |
public String getURIByBand(int band) { |
840 |
return provider.getURIByBand(band);
|
841 |
} |
842 |
|
843 |
/**
|
844 |
* Gets the {@link Interval} of the store, that means the temporal
|
845 |
* interval where the store has valid data.
|
846 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
847 |
* by the provider.
|
848 |
* @return
|
849 |
* a time interval or null if there is not time support
|
850 |
*/
|
851 |
public Interval getInterval() {
|
852 |
return provider.getInterval();
|
853 |
} |
854 |
|
855 |
/**
|
856 |
* Gets all the possible values of time for which the store has data.
|
857 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
858 |
* by the provider.
|
859 |
* @return
|
860 |
* a collection of {@link Time} objects.
|
861 |
*/
|
862 |
public Collection<?> getTimes() { |
863 |
return provider.getTimes();
|
864 |
} |
865 |
|
866 |
/**
|
867 |
* Gets all the possible values of time for which the store has data
|
868 |
* and intersects with an interval.
|
869 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
870 |
* by the provider.
|
871 |
* @param interval
|
872 |
* the interval of time
|
873 |
* @return
|
874 |
* a collection of {@link Time} objects.
|
875 |
*/
|
876 |
public Collection<?> getTimes(Interval interval) { |
877 |
return provider.getTimes(interval);
|
878 |
} |
879 |
|
880 |
public Image getImageLegend() { |
881 |
if(provider != null) |
882 |
return provider.getImageLegend();
|
883 |
return null; |
884 |
} |
885 |
|
886 |
/**
|
887 |
* Gets the list of geo points associated to this provider
|
888 |
* @return
|
889 |
*/
|
890 |
public GeoPointList getGeoPointList() {
|
891 |
return provider.getGeoPointList();
|
892 |
} |
893 |
|
894 |
/**
|
895 |
* Sets the list of geo points associated to this provider
|
896 |
*/
|
897 |
public void setGeoPointList(GeoPointList geoPointList) { |
898 |
provider.setGeoPointList(geoPointList); |
899 |
} |
900 |
|
901 |
public Envelope getFullEnvelope() {
|
902 |
Rectangle2D e = getExtent().toRectangle2D();
|
903 |
try {
|
904 |
return GeometryLocator.getGeometryManager().createEnvelope(e.getX(), e.getY(), e.getMaxX(), e
|
905 |
.getMaxY(), SUBTYPES.GEOM2D); |
906 |
} catch (CreateEnvelopeException e1) {
|
907 |
logger.error("Error creating the envelope", e);
|
908 |
return null; |
909 |
} |
910 |
} |
911 |
|
912 |
public List<ROI> getRois(String epsg) throws ROIException { |
913 |
IProjection proj = CRSFactory.getCRS(epsg); |
914 |
return getRois(proj);
|
915 |
} |
916 |
|
917 |
public List<ROI> getRois(IProjection defaultProjection) throws ROIException { |
918 |
if(rois == null) { |
919 |
try {
|
920 |
List<File> fileList = getDataStore().getROIFileListFromRmf(); |
921 |
if(fileList != null && fileList.size() > 0 && fileList.get(0) != null) { |
922 |
File f = fileList.get(0); |
923 |
IProjection proj = getProjection(); |
924 |
if(proj == null) { |
925 |
proj = defaultProjection; |
926 |
} |
927 |
ROIReader reader = new VectorialROIsReader(
|
928 |
f.getPath(), |
929 |
getDataStore(), |
930 |
proj, |
931 |
getFullEnvelope()); |
932 |
rois = new ArrayList<ROI>(); |
933 |
rois = reader.read(rois); |
934 |
} |
935 |
} catch (Exception e) { |
936 |
throw new ROIException("error_getting_ROIS", e); |
937 |
} |
938 |
} |
939 |
return rois;
|
940 |
} |
941 |
|
942 |
public void setRois(List<ROI> rois) { |
943 |
this.rois = rois;
|
944 |
} |
945 |
|
946 |
public void setROIsFiles(List<File> file) throws RmfSerializerException { |
947 |
getDataStore().saveROIFileListToRmf(file); |
948 |
} |
949 |
|
950 |
public List<File> getROIsFiles() throws RmfSerializerException { |
951 |
return getDataStore().getROIFileListFromRmf();
|
952 |
} |
953 |
|
954 |
public void loadFromState(PersistentState state) |
955 |
throws PersistenceException {
|
956 |
if(parameters == null) |
957 |
this.parameters = (RasterDataParameters)state.get("parameters"); |
958 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
959 |
try {
|
960 |
this.provider = (AbstractRasterProvider)dataManager.createProvider(this, this.parameters); |
961 |
} catch (InitializeException e) {
|
962 |
//throw new PersistenceException(e);
|
963 |
} catch (ProviderNotRegisteredException e) {
|
964 |
throw new PersistenceException(e); |
965 |
} |
966 |
this.storeBandList = (BandListImpl)state.get("bandList"); |
967 |
if(parameters instanceof AbstractRasterFileDataParameters && !this.provider.isMultiFile()) { |
968 |
//Esto solo es por si al cargar un proyecto se ha cambiado el fichero de sitio y el usuario
|
969 |
//lo introduce manualmente. En ese caso el bandList debe contener la misma ruta al fichero que el
|
970 |
//provider y no la que se grab? inicialmente
|
971 |
for (int i = 0; i < storeBandList.getBandCount(); i++) { |
972 |
storeBandList.getBand(i).setFileName(provider.getURI()); |
973 |
} |
974 |
} |
975 |
this.metadata = (Metadata)state.get("metadata"); |
976 |
setRender((Render)state.get("render"));
|
977 |
ColorInterpretation ci = getRender().getRenderColorInterpretation(); //Evitamos que las bandas que fueron cargadas se machaquen ahora
|
978 |
getRender().setDataStore(this);
|
979 |
getRender().setRenderColorInterpretation(ci); |
980 |
if(getRender().getRenderingTransparency() != null) |
981 |
getRender().getRenderingTransparency().setNoData(getNoDataValue()); |
982 |
|
983 |
loadFiltersFromProject(state); |
984 |
|
985 |
} |
986 |
|
987 |
@SuppressWarnings("unchecked") |
988 |
private void loadFiltersFromProject(PersistentState state) throws PersistenceException { |
989 |
RasterFilterList fList = (RasterFilterList)state.get("filterList");
|
990 |
fList.addEnvParam("SrcStatistics", getStatistics());
|
991 |
getRender().setFilterList(fList); |
992 |
|
993 |
List<PersistencyFilterParam> listFilterUsed = state.getList("paramlist"); |
994 |
|
995 |
ArrayList<Exception> exc = new ArrayList<Exception>(); |
996 |
for (int i = 0; i < listFilterUsed.size(); i++) { |
997 |
try {
|
998 |
PersistencyFilterParam pfp = (PersistencyFilterParam) listFilterUsed.get(i); |
999 |
if(pfp != null && pfp.getFilterClass() != null && pfp.getFilterParam() != null) { |
1000 |
RasterFilterListManager filterManager = fList.getManagerByFilterClass(pfp.getFilterClass()); |
1001 |
filterManager.setFilterList(fList); |
1002 |
if(filterManager != null) |
1003 |
filterManager.addFilter(pfp.getFilterClass(), pfp.getFilterParam()); |
1004 |
} |
1005 |
} catch (FilterTypeException e) {
|
1006 |
exc.add(e); |
1007 |
} catch (FilterManagerException e) {
|
1008 |
exc.add(e); |
1009 |
} |
1010 |
} |
1011 |
|
1012 |
if(exc.size() != 0) { |
1013 |
throw new PersistenceException("error_adding_filters", exc.get(0)); |
1014 |
} |
1015 |
} |
1016 |
|
1017 |
public void saveToState(PersistentState state) throws PersistenceException { |
1018 |
state.set("parameters", provider.getDataParameters());
|
1019 |
state.set("bandList", storeBandList);
|
1020 |
state.set("metadata", metadata);
|
1021 |
state.set("render", getRender());
|
1022 |
state.set("filterList", getRender().getFilterList());
|
1023 |
|
1024 |
RasterFilterList list = getRender().getFilterList(); |
1025 |
ArrayList<PersistencyFilterParam> filters = new ArrayList<PersistencyFilterParam>(); |
1026 |
for (int i = 0; i < list.lenght(); i++) { |
1027 |
RasterFilter f = list.get(i); |
1028 |
Params uipar = f.getUIParams(f.getName()); |
1029 |
PersistencyFilterParam param = new PersistencyFilterParam();
|
1030 |
param.setFilterParam(uipar); |
1031 |
param.setFilterClass(f.getClass()); |
1032 |
param.setFilterName(f.getName()); |
1033 |
filters.add(param); |
1034 |
} |
1035 |
state.set("paramlist", filters);
|
1036 |
//state.set("rois", rois);
|
1037 |
} |
1038 |
|
1039 |
public static void registerPersistence() { |
1040 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
1041 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
1042 |
if( definition == null ) { |
1043 |
definition = manager.addDefinition( |
1044 |
DefaultRasterStore.class, |
1045 |
PERSISTENT_NAME, |
1046 |
PERSISTENT_DESCRIPTION, |
1047 |
null,
|
1048 |
null
|
1049 |
); |
1050 |
|
1051 |
definition.addDynFieldObject("parameters").setClassOfValue(RasterDataParameters.class).setMandatory(true); |
1052 |
definition.addDynFieldObject("bandList").setClassOfValue(BandList.class).setMandatory(false); |
1053 |
definition.addDynFieldObject("metadata").setClassOfValue(Metadata.class).setMandatory(false); |
1054 |
definition.addDynFieldObject("render").setClassOfValue(Render.class).setMandatory(true); |
1055 |
|
1056 |
definition.addDynFieldObject("filterList").setClassOfValue(RasterFilterList.class).setMandatory(false); |
1057 |
definition.addDynFieldList("paramlist").setClassOfItems(PersistencyFilterParam.class).setMandatory(false); |
1058 |
|
1059 |
//definition.addDynFieldList("rois").setClassOfItems(ROI.class).setMandatory(false);
|
1060 |
} |
1061 |
} |
1062 |
|
1063 |
public void close() { |
1064 |
if(provider != null) |
1065 |
provider.close(); |
1066 |
if(storeBandList != null) |
1067 |
storeBandList.clear(); |
1068 |
provider = null;
|
1069 |
storeBandList = null;
|
1070 |
super.close();
|
1071 |
try {
|
1072 |
finalize(); |
1073 |
} catch (Throwable e) { |
1074 |
} |
1075 |
} |
1076 |
|
1077 |
protected void finalize() throws Throwable { |
1078 |
provider = null;
|
1079 |
storeBandList = null;
|
1080 |
metadata = null;
|
1081 |
if(rois != null) { |
1082 |
rois.clear(); |
1083 |
rois = null;
|
1084 |
} |
1085 |
super.finalize();
|
1086 |
} |
1087 |
} |