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 | 2443 | nbrodin | 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 | 4181 | fdiaz | import java.net.URI; |
9 | 2443 | nbrodin | import java.util.ArrayList; |
10 | import java.util.Collection; |
||
11 | import java.util.List; |
||
12 | |||
13 | import org.cresques.cts.IProjection; |
||
14 | 4181 | fdiaz | |
15 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
84 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
97 | 2443 | nbrodin | /*
|
98 | 4181 | fdiaz | * TODO: Refactoring de ROIS
|
99 | 2443 | nbrodin | * 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 | 4181 | fdiaz | *
|
103 | 2443 | nbrodin | * Por otro lado, las ROIs deben ser del proveedor de datos. Este con tendr? una lista de estos.
|
104 | 4181 | fdiaz | * Las ROIs deber?an modelarse como proveedores de datos de tipo r?ster o de tipo vectorial, ya que
|
105 | 2443 | nbrodin | * 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 | 4181 | fdiaz | |
111 | 4439 | fdiaz | /**
|
112 | * Constructor
|
||
113 | */
|
||
114 | 2443 | nbrodin | public DefaultRasterStore() {
|
115 | super();
|
||
116 | } |
||
117 | 4181 | fdiaz | |
118 | 2443 | nbrodin | public void reload() { |
119 | provider.reload(); |
||
120 | } |
||
121 | |||
122 | 4439 | fdiaz | /**
|
123 | * @param provider
|
||
124 | */
|
||
125 | 2443 | nbrodin | public void setProvider(RasterProvider provider) { |
126 | this.provider = provider;
|
||
127 | parameters = (DataStoreParameters)provider.getDataParameters(); |
||
128 | initializeBandList(); |
||
129 | } |
||
130 | 4181 | fdiaz | |
131 | 2443 | nbrodin | public void setParameters(DataStoreParameters p) { |
132 | this.parameters = p;
|
||
133 | } |
||
134 | 4181 | fdiaz | |
135 | 2443 | nbrodin | public void setProvider(CoverageStoreProvider prov) { |
136 | if(prov instanceof RasterProvider) |
||
137 | setProvider((RasterProvider)prov); |
||
138 | } |
||
139 | 4181 | fdiaz | |
140 | 2443 | nbrodin | public String getName() { |
141 | if(provider != null) |
||
142 | 2888 | jjdelcerro | return provider.getName();
|
143 | 2443 | nbrodin | return null; |
144 | } |
||
145 | 4181 | fdiaz | |
146 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
156 | 2443 | nbrodin | public boolean isMosaic() { |
157 | return provider.isMosaic();
|
||
158 | } |
||
159 | 4181 | fdiaz | |
160 | 2443 | nbrodin | 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 | 4181 | fdiaz | size += fSize[j]; |
180 | 2443 | nbrodin | } |
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 | 4439 | fdiaz | /**
|
280 | * @return the extent
|
||
281 | */
|
||
282 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
299 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
306 | 2443 | nbrodin | /**
|
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 | 4181 | fdiaz | |
354 | 2443 | nbrodin | public RasterDataStore getDataStore() {
|
355 | return this; |
||
356 | } |
||
357 | |||
358 | 4439 | fdiaz | /**
|
359 | * @param band
|
||
360 | * @return the affine transform
|
||
361 | */
|
||
362 | 2443 | nbrodin | 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 | 4439 | fdiaz | * @return the own affine transform
|
378 | 2443 | nbrodin | */
|
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 | 4181 | fdiaz | |
393 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
409 | 2443 | nbrodin | public boolean isMultiFile() { |
410 | return provider.isMultiFile();
|
||
411 | } |
||
412 | 4181 | fdiaz | |
413 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
433 | 2443 | nbrodin | public void saveGeoreferencingToRmf() throws RmfSerializerException { |
434 | provider.saveObjectToRmf(AbstractRasterProvider.class, provider); |
||
435 | } |
||
436 | 4181 | fdiaz | |
437 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
445 | 2443 | nbrodin | public void saveGeoPointListToRmf(GeoPointList pointList) throws RmfSerializerException { |
446 | provider.saveObjectToRmf(GeoPointList.class, pointList); |
||
447 | } |
||
448 | 4181 | fdiaz | |
449 | 2443 | nbrodin | public void saveROIFileListToRmf(List<File> fileList) throws RmfSerializerException { |
450 | provider.saveObjectToRmf(List.class, fileList);
|
||
451 | } |
||
452 | 4181 | fdiaz | |
453 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
463 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
479 | 2443 | nbrodin | public Extent getExtentWithoutRot() {
|
480 | if(provider != null) |
||
481 | return provider.getExtentWithoutRot();
|
||
482 | return null; |
||
483 | } |
||
484 | 4181 | fdiaz | |
485 | 2443 | nbrodin | public AffineTransform getOwnAffineTransform() { |
486 | if(provider != null) |
||
487 | return provider.getOwnAffineTransform();
|
||
488 | return null; |
||
489 | } |
||
490 | 4181 | fdiaz | |
491 | 2443 | nbrodin | 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 | 4181 | fdiaz | sX,
|
503 | at.getShearY(),
|
||
504 | at.getShearX(),
|
||
505 | sY,
|
||
506 | translate.getX(),
|
||
507 | 2443 | nbrodin | translate.getY());
|
508 | }*/
|
||
509 | return at;
|
||
510 | } |
||
511 | return null; |
||
512 | } |
||
513 | 4181 | fdiaz | |
514 | 2443 | nbrodin | public IProjection getProjection() {
|
515 | if(provider != null) |
||
516 | return provider.getProjection();
|
||
517 | return null; |
||
518 | } |
||
519 | 4181 | fdiaz | |
520 | 2443 | nbrodin | public void setProjection(IProjection proj, boolean persist) throws RmfSerializerException { |
521 | if(provider != null) |
||
522 | provider.setProjection(proj, persist); |
||
523 | } |
||
524 | 4181 | fdiaz | |
525 | 2443 | nbrodin | public Statistics getStatistics() {
|
526 | if(provider != null) |
||
527 | return provider.getStatistics();
|
||
528 | return null; |
||
529 | } |
||
530 | 4181 | fdiaz | |
531 | 2443 | nbrodin | public void setStatistics(Statistics stats) throws RmfSerializerException { |
532 | if(provider != null) |
||
533 | provider.setStatistics(stats); |
||
534 | } |
||
535 | 4181 | fdiaz | |
536 | 2443 | nbrodin | public HistogramComputer getHistogramComputer() {
|
537 | if(provider != null) |
||
538 | return provider.getHistogramComputer();
|
||
539 | return null; |
||
540 | } |
||
541 | 4181 | fdiaz | |
542 | 2443 | nbrodin | public Metadata getMetadata() {
|
543 | if(provider != null) |
||
544 | return provider.getMetadata();
|
||
545 | return null; |
||
546 | } |
||
547 | 4181 | fdiaz | |
548 | 2443 | nbrodin | public Transparency getTransparency() { |
549 | if(provider != null) { |
||
550 | provider.getTransparency().setNoData(getNoDataValue()); |
||
551 | return provider.getTransparency();
|
||
552 | } |
||
553 | return null; |
||
554 | } |
||
555 | 4181 | fdiaz | |
556 | 2443 | nbrodin | public ColorInterpretation getColorInterpretation() {
|
557 | return provider.getColorInterpretation();
|
||
558 | } |
||
559 | 4181 | fdiaz | |
560 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
570 | 2443 | nbrodin | public String getMetadataName() { |
571 | if(provider != null) |
||
572 | return provider.getName();
|
||
573 | return null; |
||
574 | } |
||
575 | 4181 | fdiaz | |
576 | 2443 | nbrodin | public RasterDataStore cloneDataStore() throws CloneException { |
577 | DefaultRasterStore ds = new DefaultRasterStore();
|
||
578 | ds.parameters = getParameters(); |
||
579 | ds.provider = provider.cloneProvider(); |
||
580 | 4181 | fdiaz | |
581 | 2443 | nbrodin | int[] bands = new int[1]; |
582 | bands[0] = provider.getBandCount();
|
||
583 | ds.metadata = new MultiDataStoreMetadata(bands);
|
||
584 | ((MultiDataStoreMetadata)ds.metadata).add(provider.getMetadata()); |
||
585 | 4181 | fdiaz | |
586 | 2443 | nbrodin | ds.storeBandList = (BandListImpl)storeBandList.clone(); |
587 | return ds;
|
||
588 | } |
||
589 | 4181 | fdiaz | |
590 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
600 | 2443 | nbrodin | public String getInfoByPoint(double x, double y, ICancellable cancellable) throws InfoByPointException { |
601 | return ((RasterProvider)getProvider()).getInfoByPoint(x, y, cancellable);
|
||
602 | } |
||
603 | 4181 | fdiaz | |
604 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
632 | 2443 | nbrodin | public void setTime(Time time) throws TimeException, OperationNotSupportedException { |
633 | if(!isTimeSupportedByTheProvider())
|
||
634 | throw new OperationNotSupportedException("Not supported for a RasterDataset"); |
||
635 | 4181 | fdiaz | |
636 | 2443 | nbrodin | } |
637 | 4181 | fdiaz | |
638 | 2443 | nbrodin | /**
|
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 | 4181 | fdiaz | |
648 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
686 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
721 | 2443 | nbrodin | 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 | 4181 | fdiaz | } |
730 | |||
731 | 2443 | nbrodin | 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 | 4181 | fdiaz | public URI[] getURIByProvider() { |
748 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
759 | 2443 | nbrodin | public int[] getBandCountByProvider() { |
760 | return provider.getBandCountByProvider();
|
||
761 | } |
||
762 | 4181 | fdiaz | |
763 | 2443 | nbrodin | public RasterDataParameters[] getDataParametersByProvider() { |
764 | RasterDataParameters[] res = new RasterDataParameters[getProviderCount()]; |
||
765 | for (int i = 0; i < res.length; i++) { |
||
766 | 4181 | fdiaz | res[i] = (RasterDataParameters)provider.getInternalProvider(i).getDataParameters(); |
767 | 2443 | nbrodin | } |
768 | return res;
|
||
769 | } |
||
770 | 4181 | fdiaz | |
771 | 2443 | nbrodin | public Metadata[] getMetadataByProvider() { |
772 | Metadata[] res = new Metadata[getProviderCount()]; |
||
773 | for (int i = 0; i < res.length; i++) { |
||
774 | 4181 | fdiaz | res[i] = provider.getInternalProvider(i).getMetadata(); |
775 | 2443 | nbrodin | } |
776 | return res;
|
||
777 | } |
||
778 | 4181 | fdiaz | |
779 | 2443 | nbrodin | 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 | 4181 | fdiaz | } |
787 | 2443 | nbrodin | } |
788 | return res;
|
||
789 | } |
||
790 | 4181 | fdiaz | |
791 | 2443 | nbrodin | 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 | 4181 | fdiaz | res[i] = provider.getInternalProvider(i).getOverviewWidth(band, overview) + |
796 | "x" +
|
||
797 | 2443 | nbrodin | provider.getInternalProvider(i).getOverviewHeight(band, overview); |
798 | } catch (RasterDriverException e) {
|
||
799 | throw new BandAccessException("", e); |
||
800 | 4181 | fdiaz | } |
801 | 2443 | nbrodin | } |
802 | return res;
|
||
803 | } |
||
804 | 4181 | fdiaz | |
805 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
813 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
821 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
829 | public void addFile(File file) throws InvalidSourceException { |
||
830 | 2443 | nbrodin | provider.addFile(file); |
831 | } |
||
832 | 4181 | fdiaz | |
833 | public void removeFile(File file) { |
||
834 | 2443 | nbrodin | provider.removeFile(file); |
835 | 4181 | fdiaz | storeBandList.removeBands(file.getPath()); |
836 | 2443 | nbrodin | } |
837 | 4181 | fdiaz | |
838 | public URI getURIByBand(int band) { |
||
839 | 2443 | nbrodin | return provider.getURIByBand(band);
|
840 | } |
||
841 | 4181 | fdiaz | |
842 | 2443 | nbrodin | /**
|
843 | * Gets the {@link Interval} of the store, that means the temporal
|
||
844 | * interval where the store has valid data.
|
||
845 | 4181 | fdiaz | * In raster this method has sense in a mosaic. Therefore this has to be implemented
|
846 | 2443 | nbrodin | * 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 | 4181 | fdiaz | |
854 | 2443 | nbrodin | /**
|
855 | 4181 | fdiaz | * 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 | 2443 | nbrodin | * by the provider.
|
858 | * @return
|
||
859 | * a collection of {@link Time} objects.
|
||
860 | */
|
||
861 | public Collection<?> getTimes() { |
||
862 | return provider.getTimes();
|
||
863 | } |
||
864 | 4181 | fdiaz | |
865 | 2443 | nbrodin | /**
|
866 | * Gets all the possible values of time for which the store has data
|
||
867 | * and intersects with an interval.
|
||
868 | 4181 | fdiaz | * In raster this method has sense in a mosaic. Therefore this has to be implemented
|
869 | 2443 | nbrodin | * 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 | 4181 | fdiaz | |
879 | 2443 | nbrodin | public Image getImageLegend() { |
880 | if(provider != null) |
||
881 | return provider.getImageLegend();
|
||
882 | return null; |
||
883 | } |
||
884 | 4181 | fdiaz | |
885 | 2443 | nbrodin | /**
|
886 | * Gets the list of geo points associated to this provider
|
||
887 | 4439 | fdiaz | * @return GeoPointList
|
888 | 2443 | nbrodin | */
|
889 | public GeoPointList getGeoPointList() {
|
||
890 | return provider.getGeoPointList();
|
||
891 | } |
||
892 | 4181 | fdiaz | |
893 | 2443 | nbrodin | /**
|
894 | * Sets the list of geo points associated to this provider
|
||
895 | */
|
||
896 | public void setGeoPointList(GeoPointList geoPointList) { |
||
897 | provider.setGeoPointList(geoPointList); |
||
898 | } |
||
899 | 4181 | fdiaz | |
900 | 4439 | fdiaz | /**
|
901 | * @return the full envelope
|
||
902 | */
|
||
903 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
914 | 2443 | nbrodin | public List<ROI> getRois(String epsg) throws ROIException { |
915 | IProjection proj = CRSFactory.getCRS(epsg); |
||
916 | return getRois(proj);
|
||
917 | } |
||
918 | 4181 | fdiaz | |
919 | 2443 | nbrodin | 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 | 4181 | fdiaz | f.getPath(), |
931 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
948 | 4439 | fdiaz | /**
|
949 | * @param file
|
||
950 | * @throws RmfSerializerException
|
||
951 | */
|
||
952 | 2443 | nbrodin | public void setROIsFiles(List<File> file) throws RmfSerializerException { |
953 | getDataStore().saveROIFileListToRmf(file); |
||
954 | } |
||
955 | 4181 | fdiaz | |
956 | 4439 | fdiaz | /**
|
957 | * @return the ROI files
|
||
958 | * @throws RmfSerializerException
|
||
959 | */
|
||
960 | 2443 | nbrodin | public List<File> getROIsFiles() throws RmfSerializerException { |
961 | return getDataStore().getROIFileListFromRmf();
|
||
962 | } |
||
963 | 4181 | fdiaz | |
964 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
978 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
989 | 2443 | nbrodin | //******************************
|
990 | //Persistence
|
||
991 | //******************************
|
||
992 | 4181 | fdiaz | |
993 | 4439 | fdiaz | /**
|
994 | * Register persistence
|
||
995 | */
|
||
996 | 2443 | nbrodin | 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 | 4181 | fdiaz | null,
|
1005 | 2443 | nbrodin | null
|
1006 | ); |
||
1007 | 4181 | fdiaz | |
1008 | 2443 | nbrodin | definition.addDynFieldObject("parameters")
|
1009 | .setClassOfValue(RasterDataParameters.class) |
||
1010 | .setMandatory(true);
|
||
1011 | 4181 | fdiaz | |
1012 | 2443 | nbrodin | definition.addDynFieldString("explorername")
|
1013 | .setMandatory(false);
|
||
1014 | 4181 | fdiaz | |
1015 | 2443 | nbrodin | definition.addDynFieldObject("bandList")
|
1016 | .setClassOfValue(BandList.class) |
||
1017 | .setMandatory(false);
|
||
1018 | 4181 | fdiaz | |
1019 | 2443 | nbrodin | definition.addDynFieldObject("metadata")
|
1020 | .setClassOfValue(Metadata.class) |
||
1021 | .setMandatory(false);
|
||
1022 | 4181 | fdiaz | |
1023 | 2443 | nbrodin | definition.addDynFieldObject("render")
|
1024 | .setClassOfValue(Render.class) |
||
1025 | .setMandatory(false);
|
||
1026 | } |
||
1027 | } |
||
1028 | 4181 | fdiaz | |
1029 | 2443 | nbrodin | public void loadFromState(PersistentState state) |
1030 | throws PersistenceException {
|
||
1031 | this.parameters = (RasterDataParameters)state.get("parameters"); |
||
1032 | 4181 | fdiaz | |
1033 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
1040 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
1049 | 2443 | nbrodin | 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 | 4181 | fdiaz | //lo introduce manualmente. En ese caso el bandList debe contener la misma ruta al fichero que el
|
1053 | 2443 | nbrodin | //provider y no la que se grab? inicialmente
|
1054 | for (int i = 0; i < storeBandList.getBandCount(); i++) { |
||
1055 | 4181 | fdiaz | storeBandList.getBand(i).setFileName(provider.getURI().getPath()); |
1056 | 2443 | nbrodin | } |
1057 | } |
||
1058 | this.metadata = (Metadata)state.get("metadata"); |
||
1059 | 4181 | fdiaz | |
1060 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
1070 | 2443 | nbrodin | public void saveToState(PersistentState state) throws PersistenceException { |
1071 | 4181 | fdiaz | state.set("parameters", provider.getDataParameters());
|
1072 | 2443 | nbrodin | 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 | 4181 | fdiaz | } |
1078 | |||
1079 | 2443 | nbrodin | /**
|
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 | 4181 | fdiaz | |
1090 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
1098 | 2443 | nbrodin | explorerParams = explorer.getParameters(); |
1099 | explorerParams.setDynValue("host", providerParams.getURI());
|
||
1100 | 4181 | fdiaz | |
1101 | 2443 | nbrodin | if(!explorer.isHostReachable()) {
|
1102 | return null; |
||
1103 | } |
||
1104 | 4181 | fdiaz | |
1105 | 2443 | nbrodin | try {
|
1106 | explorer.connect(null);
|
||
1107 | } catch (ConnectException exc) { |
||
1108 | return null; |
||
1109 | } |
||
1110 | 4181 | fdiaz | |
1111 | 2443 | nbrodin | 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 | 4181 | fdiaz | |
1123 | 2443 | nbrodin | 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 | } |