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