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