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 @ 2236
History | View | Annotate | Download (31.7 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 |
getDefaultBandList(); |
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 MultiRasterDataset"); |
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 MultiRasterDataset"); |
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 MultiRasterDataset"); |
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 MultiRasterDataset"); |
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 String[] getURIByProvider() { |
723 |
return provider.getURIByProvider();
|
724 |
} |
725 |
|
726 |
public long[] getFileSizeByProvider() { |
727 |
return provider.getFileSizeByProvider();
|
728 |
} |
729 |
|
730 |
public int getProviderCount() { |
731 |
return provider.getInternalProviderCount();
|
732 |
} |
733 |
|
734 |
public int[] getBandCountByProvider() { |
735 |
return provider.getBandCountByProvider();
|
736 |
} |
737 |
|
738 |
public RasterDataParameters[] getDataParametersByProvider() { |
739 |
RasterDataParameters[] res = new RasterDataParameters[getProviderCount()]; |
740 |
for (int i = 0; i < res.length; i++) { |
741 |
res[i] = (RasterDataParameters)provider.getInternalProvider(i).getDataParameters(); |
742 |
} |
743 |
return res;
|
744 |
} |
745 |
|
746 |
public Metadata[] getMetadataByProvider() { |
747 |
Metadata[] res = new Metadata[getProviderCount()]; |
748 |
for (int i = 0; i < res.length; i++) { |
749 |
res[i] = provider.getInternalProvider(i).getMetadata(); |
750 |
} |
751 |
return res;
|
752 |
} |
753 |
|
754 |
public int[] getOverviewCountByProvider(int band) throws BandAccessException { |
755 |
int[] res = new int[getProviderCount()]; |
756 |
for (int i = 0; i < res.length; i++) { |
757 |
try {
|
758 |
res[i] = provider.getInternalProvider(i).getOverviewCount(band); |
759 |
} catch (RasterDriverException e) {
|
760 |
throw new BandAccessException("", e); |
761 |
} |
762 |
} |
763 |
return res;
|
764 |
} |
765 |
|
766 |
public String[] getOverviewSizeByProvider(int band, int overview) throws BandAccessException { |
767 |
String[] res = new String[getProviderCount()]; |
768 |
for (int i = 0; i < res.length; i++) { |
769 |
try {
|
770 |
res[i] = provider.getInternalProvider(i).getOverviewWidth(band, overview) + |
771 |
"x" +
|
772 |
provider.getInternalProvider(i).getOverviewHeight(band, overview); |
773 |
} catch (RasterDriverException e) {
|
774 |
throw new BandAccessException("", e); |
775 |
} |
776 |
} |
777 |
return res;
|
778 |
} |
779 |
|
780 |
public AffineTransform[] getAffineTransformByProvider() { |
781 |
AffineTransform[] res = new AffineTransform[getProviderCount()]; |
782 |
for (int i = 0; i < res.length; i++) { |
783 |
res[i] = provider.getInternalProvider(i).getAffineTransform(); |
784 |
} |
785 |
return res;
|
786 |
} |
787 |
|
788 |
public double[] getHeightByProvider() { |
789 |
double[] res = new double[getProviderCount()]; |
790 |
for (int i = 0; i < res.length; i++) { |
791 |
res[i] = provider.getInternalProvider(i).getHeight(); |
792 |
} |
793 |
return res;
|
794 |
} |
795 |
|
796 |
public double[] getWidthByProvider() { |
797 |
double[] res = new double[getProviderCount()]; |
798 |
for (int i = 0; i < res.length; i++) { |
799 |
res[i] = provider.getInternalProvider(i).getWidth(); |
800 |
} |
801 |
return res;
|
802 |
} |
803 |
|
804 |
public void addFile(String file) throws InvalidSourceException { |
805 |
provider.addFile(file); |
806 |
} |
807 |
|
808 |
public void removeFile(String file) { |
809 |
provider.removeFile(file); |
810 |
storeBandList.removeBands(file); |
811 |
} |
812 |
|
813 |
public String getURIByBand(int band) { |
814 |
return provider.getURIByBand(band);
|
815 |
} |
816 |
|
817 |
/**
|
818 |
* Gets the {@link Interval} of the store, that means the temporal
|
819 |
* interval where the store has valid data.
|
820 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
821 |
* by the provider.
|
822 |
* @return
|
823 |
* a time interval or null if there is not time support
|
824 |
*/
|
825 |
public Interval getInterval() {
|
826 |
return provider.getInterval();
|
827 |
} |
828 |
|
829 |
/**
|
830 |
* Gets all the possible values of time for which the store has data.
|
831 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
832 |
* by the provider.
|
833 |
* @return
|
834 |
* a collection of {@link Time} objects.
|
835 |
*/
|
836 |
public Collection<?> getTimes() { |
837 |
return provider.getTimes();
|
838 |
} |
839 |
|
840 |
/**
|
841 |
* Gets all the possible values of time for which the store has data
|
842 |
* and intersects with an interval.
|
843 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
844 |
* by the provider.
|
845 |
* @param interval
|
846 |
* the interval of time
|
847 |
* @return
|
848 |
* a collection of {@link Time} objects.
|
849 |
*/
|
850 |
public Collection<?> getTimes(Interval interval) { |
851 |
return provider.getTimes(interval);
|
852 |
} |
853 |
|
854 |
public Image getImageLegend() { |
855 |
if(provider != null) |
856 |
return provider.getImageLegend();
|
857 |
return null; |
858 |
} |
859 |
|
860 |
/**
|
861 |
* Gets the list of geo points associated to this provider
|
862 |
* @return
|
863 |
*/
|
864 |
public GeoPointList getGeoPointList() {
|
865 |
return provider.getGeoPointList();
|
866 |
} |
867 |
|
868 |
/**
|
869 |
* Sets the list of geo points associated to this provider
|
870 |
*/
|
871 |
public void setGeoPointList(GeoPointList geoPointList) { |
872 |
provider.setGeoPointList(geoPointList); |
873 |
} |
874 |
|
875 |
public Envelope getFullEnvelope() {
|
876 |
Rectangle2D e = getExtent().toRectangle2D();
|
877 |
try {
|
878 |
return GeometryLocator.getGeometryManager().createEnvelope(e.getX(), e.getY(), e.getMaxX(), e
|
879 |
.getMaxY(), SUBTYPES.GEOM2D); |
880 |
} catch (CreateEnvelopeException e1) {
|
881 |
logger.error("Error creating the envelope", e);
|
882 |
return null; |
883 |
} |
884 |
} |
885 |
|
886 |
public List<ROI> getRois(String epsg) throws ROIException { |
887 |
IProjection proj = CRSFactory.getCRS(epsg); |
888 |
return getRois(proj);
|
889 |
} |
890 |
|
891 |
public List<ROI> getRois(IProjection defaultProjection) throws ROIException { |
892 |
if(rois == null) { |
893 |
try {
|
894 |
List<File> fileList = getDataStore().getROIFileListFromRmf(); |
895 |
if(fileList != null & fileList.size() > 0 && fileList.get(0) != null) { |
896 |
File f = fileList.get(0); |
897 |
IProjection proj = getProjection(); |
898 |
if(proj == null) { |
899 |
proj = defaultProjection; |
900 |
} |
901 |
ROIReader reader = new VectorialROIsReader(
|
902 |
f.getPath(), |
903 |
getDataStore(), |
904 |
proj, |
905 |
getFullEnvelope()); |
906 |
rois = new ArrayList<ROI>(); |
907 |
rois = reader.read(rois); |
908 |
} |
909 |
} catch (Exception e) { |
910 |
throw new ROIException("error_getting_ROIS", e); |
911 |
} |
912 |
} |
913 |
return rois;
|
914 |
} |
915 |
|
916 |
public void setRois(List<ROI> rois) { |
917 |
this.rois = rois;
|
918 |
} |
919 |
|
920 |
public void setROIsFiles(List<File> file) throws RmfSerializerException { |
921 |
getDataStore().saveROIFileListToRmf(file); |
922 |
} |
923 |
|
924 |
public List<File> getROIsFiles() throws RmfSerializerException { |
925 |
return getDataStore().getROIFileListFromRmf();
|
926 |
} |
927 |
|
928 |
public void loadFromState(PersistentState state) |
929 |
throws PersistenceException {
|
930 |
if(parameters == null) |
931 |
this.parameters = (RasterDataParameters)state.get("parameters"); |
932 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
933 |
try {
|
934 |
this.provider = (AbstractRasterProvider)dataManager.createProvider(this, this.parameters); |
935 |
} catch (InitializeException e) {
|
936 |
//throw new PersistenceException(e);
|
937 |
} catch (ProviderNotRegisteredException e) {
|
938 |
throw new PersistenceException(e); |
939 |
} |
940 |
this.storeBandList = (BandListImpl)state.get("bandList"); |
941 |
if(parameters instanceof AbstractRasterFileDataParameters && !this.provider.isMultiFile()) { |
942 |
//Esto solo es por si al cargar un proyecto se ha cambiado el fichero de sitio y el usuario
|
943 |
//lo introduce manualmente. En ese caso el bandList debe contener la misma ruta al fichero que el
|
944 |
//provider y no la que se grab? inicialmente
|
945 |
for (int i = 0; i < storeBandList.getBandCount(); i++) { |
946 |
storeBandList.getBand(i).setFileName(provider.getURI()); |
947 |
} |
948 |
} |
949 |
this.metadata = (Metadata)state.get("metadata"); |
950 |
setRender((Render)state.get("render"));
|
951 |
int[] rb = getRender().getRenderBands(); //Evitamos que las bandas que fueron cargadas se machaquen ahora |
952 |
getRender().setDataStore(this);
|
953 |
getRender().setRenderBands(rb); |
954 |
if(getRender().getLastTransparency() != null) |
955 |
getRender().getLastTransparency().setNoData(getNoDataValue()); |
956 |
|
957 |
loadFiltersFromProject(state); |
958 |
|
959 |
} |
960 |
|
961 |
@SuppressWarnings("unchecked") |
962 |
private void loadFiltersFromProject(PersistentState state) throws PersistenceException { |
963 |
RasterFilterList fList = (RasterFilterList)state.get("filterList");
|
964 |
fList.addEnvParam("IStatistics", getStatistics());
|
965 |
fList.addEnvParam("MultiRasterDataset", this); |
966 |
getRender().setFilterList(fList); |
967 |
|
968 |
List<PersistencyFilterParam> listFilterUsed = state.getList("paramlist"); |
969 |
|
970 |
ArrayList<Exception> exc = new ArrayList<Exception>(); |
971 |
for (int i = 0; i < listFilterUsed.size(); i++) { |
972 |
try {
|
973 |
PersistencyFilterParam pfp = (PersistencyFilterParam) listFilterUsed.get(i); |
974 |
if(pfp != null && pfp.getFilterClass() != null && pfp.getFilterParam() != null) { |
975 |
RasterFilterListManager filterManager = fList.getManagerByFilterClass(pfp.getFilterClass()); |
976 |
filterManager.setFilterList(fList); |
977 |
if(filterManager != null) |
978 |
filterManager.addFilter(pfp.getFilterClass(), pfp.getFilterParam()); |
979 |
} |
980 |
} catch (FilterTypeException e) {
|
981 |
exc.add(e); |
982 |
} catch (FilterManagerException e) {
|
983 |
exc.add(e); |
984 |
} |
985 |
} |
986 |
|
987 |
if(exc.size() != 0) { |
988 |
throw new PersistenceException("error_adding_filters", exc.get(0)); |
989 |
} |
990 |
} |
991 |
|
992 |
public void saveToState(PersistentState state) throws PersistenceException { |
993 |
state.set("parameters", provider.getDataParameters());
|
994 |
state.set("bandList", storeBandList);
|
995 |
state.set("metadata", metadata);
|
996 |
state.set("render", getRender());
|
997 |
state.set("filterList", getRender().getFilterList());
|
998 |
|
999 |
RasterFilterList list = getRender().getFilterList(); |
1000 |
ArrayList<PersistencyFilterParam> filters = new ArrayList<PersistencyFilterParam>(); |
1001 |
for (int i = 0; i < list.lenght(); i++) { |
1002 |
RasterFilter f = list.get(i); |
1003 |
Params uipar = f.getUIParams(f.getName()); |
1004 |
PersistencyFilterParam param = new PersistencyFilterParam();
|
1005 |
param.setFilterParam(uipar); |
1006 |
param.setFilterClass(f.getClass()); |
1007 |
param.setFilterName(f.getName()); |
1008 |
filters.add(param); |
1009 |
} |
1010 |
state.set("paramlist", filters);
|
1011 |
//state.set("rois", rois);
|
1012 |
} |
1013 |
|
1014 |
public static void registerPersistence() { |
1015 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
1016 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
1017 |
if( definition == null ) { |
1018 |
definition = manager.addDefinition( |
1019 |
DefaultRasterStore.class, |
1020 |
PERSISTENT_NAME, |
1021 |
PERSISTENT_DESCRIPTION, |
1022 |
null,
|
1023 |
null
|
1024 |
); |
1025 |
|
1026 |
definition.addDynFieldObject("parameters").setClassOfValue(RasterDataParameters.class).setMandatory(true); |
1027 |
definition.addDynFieldObject("bandList").setClassOfValue(BandList.class).setMandatory(false); |
1028 |
definition.addDynFieldObject("metadata").setClassOfValue(Metadata.class).setMandatory(false); |
1029 |
definition.addDynFieldObject("render").setClassOfValue(Render.class).setMandatory(true); |
1030 |
|
1031 |
definition.addDynFieldObject("filterList").setClassOfValue(RasterFilterList.class).setMandatory(false); |
1032 |
definition.addDynFieldList("paramlist").setClassOfItems(PersistencyFilterParam.class).setMandatory(false); |
1033 |
|
1034 |
//definition.addDynFieldList("rois").setClassOfItems(ROI.class).setMandatory(false);
|
1035 |
} |
1036 |
} |
1037 |
|
1038 |
public void close() { |
1039 |
if(provider != null) |
1040 |
provider.close(); |
1041 |
if(storeBandList != null) |
1042 |
storeBandList.clear(); |
1043 |
provider = null;
|
1044 |
storeBandList = null;
|
1045 |
super.close();
|
1046 |
try {
|
1047 |
finalize(); |
1048 |
} catch (Throwable e) { |
1049 |
} |
1050 |
} |
1051 |
|
1052 |
protected void finalize() throws Throwable { |
1053 |
provider = null;
|
1054 |
storeBandList = null;
|
1055 |
metadata = null;
|
1056 |
if(rois != null) { |
1057 |
rois.clear(); |
1058 |
rois = null;
|
1059 |
} |
1060 |
super.finalize();
|
1061 |
} |
1062 |
} |