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