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 / provider / DefaultRasterProvider.java @ 1356
History | View | Annotate | Download (45.9 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.provider; |
23 |
|
24 |
import java.awt.Image; |
25 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.NoninvertibleTransformException; |
27 |
import java.awt.geom.Point2D; |
28 |
import java.io.File; |
29 |
import java.util.ArrayList; |
30 |
import java.util.Collection; |
31 |
import java.util.Date; |
32 |
import java.util.Iterator; |
33 |
|
34 |
import org.cresques.cts.IProjection; |
35 |
import org.gvsig.compat.net.ICancellable; |
36 |
import org.gvsig.fmap.dal.DALLocator; |
37 |
import org.gvsig.fmap.dal.DataServerExplorer; |
38 |
import org.gvsig.fmap.dal.DataStoreParameters; |
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
40 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
41 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
42 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
43 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
44 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
45 |
import org.gvsig.fmap.dal.coverage.exception.CloneException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
47 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
48 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
49 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
50 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
51 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
52 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
53 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
54 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
55 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
56 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
57 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterFileStoreParameters; |
58 |
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
59 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
60 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
61 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
62 |
import org.gvsig.fmap.dal.coverage.store.props.Metadata; |
63 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
64 |
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries; |
65 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
66 |
import org.gvsig.fmap.dal.coverage.util.FileUtils; |
67 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
68 |
import org.gvsig.fmap.dal.exception.InitializeException; |
69 |
import org.gvsig.fmap.dal.exception.OpenException; |
70 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
71 |
import org.gvsig.fmap.dal.exception.ReadException; |
72 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
73 |
import org.gvsig.fmap.dal.raster.spi.AbstractCoverageStoreProvider; |
74 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
75 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
76 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
77 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
78 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
79 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
80 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
81 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
82 |
import org.gvsig.raster.impl.buffer.DefaultRasterQuery; |
83 |
import org.gvsig.raster.impl.datastruct.DefaultNoData; |
84 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
85 |
import org.gvsig.raster.impl.datastruct.serializer.ColorTableRmfSerializer; |
86 |
import org.gvsig.raster.impl.datastruct.serializer.NoDataRmfSerializer; |
87 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
88 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
89 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
90 |
import org.gvsig.raster.impl.store.properties.SimpleProviderHistogramComputer; |
91 |
import org.gvsig.raster.impl.store.properties.SimpleProviderStatistics; |
92 |
import org.gvsig.raster.impl.store.rmf.ClassSerializer; |
93 |
import org.gvsig.raster.impl.store.rmf.RmfBlocksManager; |
94 |
import org.gvsig.raster.impl.store.serializer.ColorInterpretationRmfSerializer; |
95 |
import org.gvsig.raster.impl.store.serializer.GeoInfoRmfSerializer; |
96 |
import org.gvsig.raster.impl.store.serializer.ProjectionRmfSerializer; |
97 |
import org.gvsig.raster.impl.store.serializer.StatisticsRmfSerializer; |
98 |
import org.gvsig.raster.util.DefaultProviderServices; |
99 |
import org.gvsig.timesupport.Interval; |
100 |
import org.gvsig.timesupport.Time; |
101 |
import org.gvsig.tools.dynobject.DynObject; |
102 |
import org.gvsig.tools.task.TaskStatus; |
103 |
|
104 |
/**
|
105 |
* Base class for all raster providers.
|
106 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
107 |
*/
|
108 |
public abstract class DefaultRasterProvider extends AbstractCoverageStoreProvider implements RasterProvider { |
109 |
/**
|
110 |
* Flags que representan a las bandas visualizables
|
111 |
*/
|
112 |
public static final int RED_BAND = 0x01; |
113 |
public static final int GREEN_BAND = 0x02; |
114 |
public static final int BLUE_BAND = 0x04; |
115 |
public static final int ALPHA_BAND = 0x08; |
116 |
|
117 |
protected int bandCount = 1; |
118 |
private int[] dataType = null; |
119 |
protected NoData noData = null; |
120 |
protected String wktProjection = ""; |
121 |
|
122 |
protected Statistics stats = null; |
123 |
protected HistogramComputer histogram = null; |
124 |
protected DataStoreParameters param = null; |
125 |
protected DataStoreProviderServices storeServices = null; |
126 |
protected RmfBlocksManager rmfBlocksManager = null; |
127 |
protected ColorTable colorTable = null; |
128 |
private ColorInterpretation colorInterpretation = null; |
129 |
protected TimeSeries serialInfo = null; |
130 |
protected Transparency transparency = null; |
131 |
protected TileServer tileServer = null; |
132 |
|
133 |
protected FileUtils fileUtil = RasterLocator.getManager().getFileUtils();
|
134 |
protected RasterUtils rasterUtil = RasterLocator.getManager().getRasterUtils();
|
135 |
|
136 |
protected IProjection proj = null; |
137 |
protected long fileSize = 0; |
138 |
protected long bytesReaded = 0; |
139 |
protected long lineCnt = 0; |
140 |
protected String uri; |
141 |
protected String selectedSubdatasetID = null; |
142 |
|
143 |
/**
|
144 |
* Transformaci?n creada a partir de la informaci?n de georreferencia de la
|
145 |
* propia imagen. Esta informaci?n est? en la cabecera o en ficheros
|
146 |
* worldfile.
|
147 |
*/
|
148 |
protected AffineTransform ownTransformation = null; |
149 |
/**
|
150 |
* Transformaci?n asignada de forma externa, bien desde el fichero rmf o
|
151 |
* asignada directamente por el usuario.
|
152 |
*/
|
153 |
protected AffineTransform externalTransformation = null; |
154 |
|
155 |
public DefaultRasterProvider(AbstractRasterDataParameters params,
|
156 |
DataStoreProviderServices storeServices, DynObject metadata) { |
157 |
super(params, storeServices, metadata);
|
158 |
if(params.getURI() != null) { |
159 |
File f = new File(params.getURI()); |
160 |
if(f.exists())
|
161 |
setFileSize(f.length()); |
162 |
} |
163 |
|
164 |
if(params.getURI() != null) |
165 |
uri = translateFileName(params.getURI()); |
166 |
|
167 |
ownTransformation = new AffineTransform(); |
168 |
externalTransformation = new AffineTransform(); |
169 |
} |
170 |
|
171 |
public DefaultRasterProvider(DataStoreParameters params,
|
172 |
DataStoreProviderServices storeServices, DynObject metadata) { |
173 |
super(params, storeServices, metadata);
|
174 |
if(((RasterDataParameters)params).getURI() != null) { |
175 |
File f = new File(((RasterDataParameters)params).getURI()); |
176 |
if(f.exists())
|
177 |
setFileSize(f.length()); |
178 |
if(params instanceof RemoteStoreParameters) |
179 |
uri = translateFileName(((RasterDataParameters)params).getURI()); |
180 |
} |
181 |
|
182 |
ownTransformation = new AffineTransform(); |
183 |
externalTransformation = new AffineTransform(); |
184 |
} |
185 |
|
186 |
public DefaultRasterProvider(String params) { |
187 |
super();
|
188 |
} |
189 |
|
190 |
public DefaultRasterProvider() {
|
191 |
super(null, null, null); |
192 |
} |
193 |
|
194 |
public String getFullName() { |
195 |
return getName();
|
196 |
} |
197 |
|
198 |
public String getProviderName() { |
199 |
return getName();
|
200 |
} |
201 |
|
202 |
/*
|
203 |
* (non-Javadoc)
|
204 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFormatList()
|
205 |
*/
|
206 |
public String[] getFormatList() { |
207 |
return null; |
208 |
} |
209 |
|
210 |
/**
|
211 |
* Acciones de inicilizaci?n comunes a todos los drivers.
|
212 |
* Este m?todo debe ser llamado explicitamente por el constructor de cada driver.
|
213 |
* Estas son acciones de inicializaci?n que se ejecutan despu?s del constructor de cada driver.
|
214 |
* Las acciones que hayan de ser realizadas antes se definen en el constructor de RasterDataset.
|
215 |
*/
|
216 |
protected void init() { |
217 |
} |
218 |
|
219 |
/*
|
220 |
* (non-Javadoc)
|
221 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isTiled()
|
222 |
*/
|
223 |
public boolean isTiled() { |
224 |
return false; |
225 |
} |
226 |
|
227 |
/*
|
228 |
* (non-Javadoc)
|
229 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isTimeSupported()
|
230 |
*/
|
231 |
public boolean isTimeSupported() { |
232 |
return false; |
233 |
} |
234 |
|
235 |
/*
|
236 |
* (non-Javadoc)
|
237 |
* @see java.lang.Object#clone()
|
238 |
*/
|
239 |
public RasterProvider cloneProvider() throws CloneException { |
240 |
try {
|
241 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
242 |
DefaultRasterProvider provider = (DefaultRasterProvider)dataManager.createProvider(storeServices, param); |
243 |
//DefaultRasterProvider provider = singleDatasetInstance(storeServices, param);
|
244 |
// Estas van por referencia
|
245 |
provider.histogram = histogram; |
246 |
provider.stats = stats; |
247 |
return provider;
|
248 |
} catch (ProviderNotRegisteredException e) {
|
249 |
e.printStackTrace(); |
250 |
} catch (InitializeException e) {
|
251 |
e.printStackTrace(); |
252 |
} |
253 |
return null; |
254 |
} |
255 |
|
256 |
/**
|
257 |
* Factoria para abrir distintos tipos de raster.
|
258 |
* @param fName Nombre del fichero.
|
259 |
*
|
260 |
* @return SingleDataset, o null si hay problemas.
|
261 |
*/
|
262 |
/*public static DefaultRasterProvider singleDatasetInstance(DataStoreProviderServices storeServices, DataStoreParameters param) throws RasterDriverException {
|
263 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager();
|
264 |
try {
|
265 |
return (DefaultRasterProvider)dataManager.createProvider(storeServices, param);
|
266 |
} catch (InitializeException e) {
|
267 |
throw new RasterDriverException("Error initializing provider", e);
|
268 |
} catch (ProviderNotRegisteredException e) {
|
269 |
throw new RasterDriverException("Provider not register error", e);
|
270 |
}
|
271 |
}*/
|
272 |
|
273 |
/**
|
274 |
* Factoria para abrir distintos tipos de raster.
|
275 |
* @param fName Nombre del fichero.
|
276 |
*
|
277 |
* @return SingleDataset, o null si hay problemas.
|
278 |
*/
|
279 |
public static DefaultRasterProvider singleDatasetInstance(DataStoreProviderServices storeServices, String param) throws RasterDriverException { |
280 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
281 |
//We have to locate a provider's name which manages the selected file
|
282 |
//A FilesystemServerExplorer will give a getProviderNames service
|
283 |
|
284 |
FilesystemServerExplorer serverExplorer = null;
|
285 |
try {
|
286 |
FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
287 |
paramsExplorer.setRoot(File.separator);
|
288 |
serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer); |
289 |
} catch (ValidateDataParametersException e) {
|
290 |
throw new RasterDriverException("Error validating parameters", e); |
291 |
} catch (InitializeException e) {
|
292 |
throw new RasterDriverException("Error creating a server explorer ", e); |
293 |
} catch (ProviderNotRegisteredException e) {
|
294 |
throw new RasterDriverException("Provider not registered", e); |
295 |
} |
296 |
|
297 |
//Gets the list of provider's name to manage the file
|
298 |
File file = new File(param); |
299 |
ArrayList<String> provName = serverExplorer.getProviderNameList(file); |
300 |
if(provName.size() > 0) { |
301 |
for (int i = 0; i < provName.size(); i++) { |
302 |
//Gets the first provider what is not a TileProvider
|
303 |
if(provName.get(i).compareTo("Tile Store") != 0) { |
304 |
DataStoreParameters newparams; |
305 |
try {
|
306 |
newparams = dataManager.createStoreParameters(provName.get(i)); |
307 |
((FilesystemStoreParameters)newparams).setFile(file); |
308 |
if(storeServices == null) |
309 |
storeServices = new DefaultRasterStore();
|
310 |
return (DefaultRasterProvider)dataManager.createProvider(storeServices, newparams);
|
311 |
} catch (InitializeException e) {
|
312 |
throw new RasterDriverException("Error creating a server explorer ", e); |
313 |
} catch (ProviderNotRegisteredException e) {
|
314 |
throw new RasterDriverException("Provider not registered", e); |
315 |
} |
316 |
} |
317 |
} |
318 |
} |
319 |
return null; |
320 |
} |
321 |
|
322 |
/**
|
323 |
* Carga un fichero raster. Puede usarse para calcular el extent e instanciar
|
324 |
* un objeto de este tipo.
|
325 |
*/
|
326 |
abstract public RasterProvider load(); |
327 |
|
328 |
/**
|
329 |
* Obtiene el ancho de la imagen
|
330 |
* @return Ancho de la imagen
|
331 |
*/
|
332 |
abstract public double getWidth(); |
333 |
|
334 |
/**
|
335 |
* Obtiene el ancho de la imagen
|
336 |
* @return Ancho de la imagen
|
337 |
*/
|
338 |
abstract public double getHeight(); |
339 |
|
340 |
/**
|
341 |
* Asigna un nuevo Extent
|
342 |
* @param e Extent
|
343 |
*/
|
344 |
public abstract void setView(Extent e); |
345 |
|
346 |
/**
|
347 |
* Obtiene el extent asignado
|
348 |
* @return Extent
|
349 |
*/
|
350 |
public abstract Extent getView(); |
351 |
|
352 |
/**
|
353 |
* Obtiene el valor del raster en la coordenada que se le pasa.
|
354 |
* El valor ser? Double, Int, Byte, etc. dependiendo del tipo de
|
355 |
* raster.
|
356 |
* @param x coordenada X
|
357 |
* @param y coordenada Y
|
358 |
* @return
|
359 |
*/
|
360 |
abstract public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException; |
361 |
|
362 |
/**
|
363 |
* Gets the set of data selected in the {@link RasterQuery}
|
364 |
* @param q
|
365 |
* @return
|
366 |
* @throws RasterDriverException
|
367 |
* @throws ProcessInterruptedException
|
368 |
*/
|
369 |
public Buffer getDataSet(RasterQuery query) throws ProcessInterruptedException, RasterDriverException { |
370 |
DefaultRasterQuery q = (DefaultRasterQuery)query; |
371 |
if( q.getType() == DefaultRasterQuery.TYPE_ENTIRE ||
|
372 |
q.getType() == DefaultRasterQuery.TYPE_PX_SIZE || |
373 |
q.getType() == DefaultRasterQuery.TYPE_PX) { |
374 |
return getWindow(q.getPixelX(), q.getPixelY(), q.getPixelW(), q.getPixelH(),
|
375 |
q.getBandList(), q.getBuffer(), q.getTaskStatus()); |
376 |
} |
377 |
|
378 |
if(q.getType() == DefaultRasterQuery.TYPE_COORDS_SIZE) {
|
379 |
return getWindow(q.getBBox(), q.getBufWidth(), q.getBufHeight(),
|
380 |
q.getBandList(), q.getBuffer(), q.isAdjustToExtent(), q.getTaskStatus()); |
381 |
} |
382 |
|
383 |
if(q.getType() == DefaultRasterQuery.TYPE_COORDS) {
|
384 |
if(q.getBBox() == null) |
385 |
return getWindow(q.getX(), q.getY(), q.getW(), q.getH(),
|
386 |
q.getBandList(), q.getBuffer(), q.isAdjustToExtent(), q.getTaskStatus()); |
387 |
else
|
388 |
return getWindow(q.getBBox(), q.getBandList(), q.getBuffer(), q.getTaskStatus());
|
389 |
} |
390 |
|
391 |
if(q.getType() == DefaultRasterQuery.TYPE_COORDS_SIZE_TILED) {
|
392 |
getWindow(q.getBBox(), q.getBufWidth(), q.getBufHeight(), |
393 |
q.getBandList(), q.getTileListener(), q.getTaskStatus()); |
394 |
} |
395 |
return null; |
396 |
} |
397 |
|
398 |
/**
|
399 |
* Gets a window of data from the source. The result of this operation could be a list of tiles
|
400 |
* that are sent through the listener.
|
401 |
* @param ex
|
402 |
* @param bufWidth
|
403 |
* @param bufHeight
|
404 |
* @param bandList
|
405 |
* @param listener
|
406 |
* @throws ProcessInterruptedException
|
407 |
* @throws RasterDriverException
|
408 |
*/
|
409 |
abstract protected void getWindow(Extent ex, int bufWidth, int bufHeight, |
410 |
BandList bandList, TileListener listener, TaskStatus taskStatus) throws ProcessInterruptedException, RasterDriverException;
|
411 |
|
412 |
/**
|
413 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
414 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
|
415 |
* pixeles de disco.
|
416 |
* @param ulx Posici?n X superior izquierda
|
417 |
* @param uly Posici?n Y superior izquierda
|
418 |
* @param lrx Posici?n X inferior derecha
|
419 |
* @param lry Posici?n Y inferior derecha
|
420 |
* @param rasterBuf Buffer de datos
|
421 |
* @param bandList
|
422 |
* @return Buffer de datos
|
423 |
*/
|
424 |
abstract protected Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status) |
425 |
throws ProcessInterruptedException, RasterDriverException;
|
426 |
|
427 |
/**
|
428 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
429 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
|
430 |
* pixeles de disco.
|
431 |
* @param x Posici?n X superior izquierda
|
432 |
* @param y Posici?n Y superior izquierda
|
433 |
* @param w Ancho en coordenadas reales
|
434 |
* @param h Alto en coordenadas reales
|
435 |
* @param rasterBuf Buffer de datos
|
436 |
* @param bandList
|
437 |
* @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
|
438 |
* @return Buffer de datos
|
439 |
*/
|
440 |
abstract protected Buffer getWindow(double x, double y, double w, double h, |
441 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException; |
442 |
|
443 |
/**
|
444 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
445 |
* Se aplica supersampleo o subsampleo dependiendo del tama?o del buffer especificado.
|
446 |
*
|
447 |
* @param minX Posici?n m?nima X superior izquierda
|
448 |
* @param minY Posici?n m?nima Y superior izquierda
|
449 |
* @param maxX Posici?n m?xima X inferior derecha
|
450 |
* @param maxY Posici?n m?xima Y inferior derecha
|
451 |
* @param bufWidth Ancho del buffer de datos
|
452 |
* @param bufHeight Alto del buffer de datos
|
453 |
* @param rasterBuf Buffer de datos
|
454 |
* @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
|
455 |
* @param bandList
|
456 |
* @return Buffer de datos
|
457 |
*/
|
458 |
abstract protected Buffer getWindow(Extent extent, |
459 |
int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, |
460 |
boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException; |
461 |
|
462 |
/**
|
463 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas pixel.
|
464 |
* Se aplica supersampleo o subsampleo dependiendo del tama?o del buffer especificado.
|
465 |
*
|
466 |
* @param x Posici?n X superior izquierda
|
467 |
* @param y Posici?n Y superior izquierda
|
468 |
* @param w Ancho en coordenadas reales
|
469 |
* @param h Alto en coordenadas reales
|
470 |
* @param bufWidth Ancho del buffer de datos
|
471 |
* @param bufHeight Alto del buffer de datos
|
472 |
* @param rasterBuf Buffer de datos
|
473 |
* @param bandList
|
474 |
* @return Buffer de datos
|
475 |
*/
|
476 |
abstract protected Buffer getWindow(int x, int y, int w, int h, |
477 |
BandList bandList, Buffer rasterBuf, TaskStatus status)throws ProcessInterruptedException, RasterDriverException; |
478 |
|
479 |
abstract public int getBlockSize(); |
480 |
|
481 |
/*
|
482 |
* (non-Javadoc)
|
483 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewHeight(int, int)
|
484 |
*/
|
485 |
abstract public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException; |
486 |
|
487 |
/**
|
488 |
* Informa de si el dataset soporta overviews o no.
|
489 |
* @return true si soporta overviews y false si no las soporta.
|
490 |
*/
|
491 |
abstract public boolean isOverviewsSupported(); |
492 |
|
493 |
/**
|
494 |
* Returns true if supersampling operation is supported by this provider, i.e if
|
495 |
* a request greater than 1:1 will have a response.
|
496 |
* @return
|
497 |
*/
|
498 |
public boolean isSupersamplingSupported() { |
499 |
return true; |
500 |
} |
501 |
|
502 |
/**
|
503 |
* Carga metadatos desde el fichero Rmf si estos existen
|
504 |
* @param fName Nombre del fichero
|
505 |
* @throws ParsingException
|
506 |
*/
|
507 |
protected void loadFromRmf(RmfBlocksManager manager) throws ParsingException { |
508 |
if (!manager.checkRmf())
|
509 |
return;
|
510 |
|
511 |
if (!new File(manager.getPath()).exists()) |
512 |
return;
|
513 |
|
514 |
GeoInfoRmfSerializer geoInfoSerializer = new GeoInfoRmfSerializer(this); |
515 |
ColorTableRmfSerializer colorTableSerializer = new ColorTableRmfSerializer();
|
516 |
NoDataRmfSerializer noDataSerializer = null;
|
517 |
if(noData == null) |
518 |
noData = new DefaultNoData(null, null, manager.getPath(), getBandCount()); |
519 |
noDataSerializer = new NoDataRmfSerializer((DefaultNoData)noData);
|
520 |
ColorInterpretationRmfSerializer colorInterpSerializer = new ColorInterpretationRmfSerializer();
|
521 |
ProjectionRmfSerializer projectionRmfSerializer = new ProjectionRmfSerializer();
|
522 |
StatisticsRmfSerializer statsRmfSerializer = new StatisticsRmfSerializer(getStatistics());
|
523 |
|
524 |
manager.addClient(geoInfoSerializer); |
525 |
manager.addClient(colorTableSerializer); |
526 |
manager.addClient(noDataSerializer); |
527 |
manager.addClient(colorInterpSerializer); |
528 |
manager.addClient(projectionRmfSerializer); |
529 |
manager.addClient(statsRmfSerializer); |
530 |
|
531 |
manager.read(null);
|
532 |
|
533 |
manager.removeAllClients(); |
534 |
|
535 |
if (colorTableSerializer.getResult() != null) |
536 |
setColorTable((ColorTable) colorTableSerializer.getResult()); |
537 |
|
538 |
if (colorInterpSerializer.getResult() != null) { |
539 |
DataStoreColorInterpretation ci = (DataStoreColorInterpretation) colorInterpSerializer.getResult(); |
540 |
setColorInterpretation(ci); |
541 |
getTransparency().setTransparencyBand(ci.getBand(DataStoreColorInterpretation.ALPHA_BAND)); |
542 |
} |
543 |
|
544 |
if (projectionRmfSerializer.getResult() != null) |
545 |
wktProjection = RasterLocator.getManager().getCRSUtils().convertIProjectionToWkt((IProjection) projectionRmfSerializer.getResult()); |
546 |
} |
547 |
|
548 |
/**
|
549 |
* Obtiene el n?nero de bandas del fichero
|
550 |
* @return Entero que representa el n?mero de bandas
|
551 |
*/
|
552 |
public int getBandCount() { |
553 |
return bandCount;
|
554 |
} |
555 |
|
556 |
/**
|
557 |
* @return Returns the dataType.
|
558 |
*/
|
559 |
public int[] getDataType() { |
560 |
return dataType;
|
561 |
} |
562 |
|
563 |
/**
|
564 |
* @param dataType The dataType to set.
|
565 |
*/
|
566 |
public void setDataType(int[] dataType) { |
567 |
this.dataType = dataType;
|
568 |
} |
569 |
|
570 |
/*
|
571 |
* (non-Javadoc)
|
572 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeX()
|
573 |
*/
|
574 |
public double getPixelSizeX() { |
575 |
return externalTransformation.getScaleX();
|
576 |
} |
577 |
|
578 |
/*
|
579 |
* (non-Javadoc)
|
580 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeY()
|
581 |
*/
|
582 |
public double getPixelSizeY() { |
583 |
return externalTransformation.getScaleY();
|
584 |
} |
585 |
|
586 |
/*
|
587 |
* (non-Javadoc)
|
588 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getNoDataValue()
|
589 |
*/
|
590 |
public NoData getNoDataValue() {
|
591 |
if(noData == null) { |
592 |
noData = RasterLocator.getManager().getDataStructFactory().createNoData(null, null, getRMFFile(), getBandCount()); |
593 |
noData.setDataType(getDataType()[0]);
|
594 |
} |
595 |
return noData;
|
596 |
} |
597 |
|
598 |
/*
|
599 |
* (non-Javadoc)
|
600 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setNoDataValue(org.gvsig.fmap.dal.coverage.datastruct.NoData)
|
601 |
*/
|
602 |
public void setNoDataValue(NoData value) { |
603 |
this.noData = value;
|
604 |
} |
605 |
|
606 |
/**
|
607 |
* Dice si el fichero tiene georreferenciaci?n o no.
|
608 |
* @return true si tiene georreferenciaci?n y false si no la tiene
|
609 |
*/
|
610 |
public boolean isGeoreferenced() { |
611 |
return true; |
612 |
} |
613 |
|
614 |
/**
|
615 |
* Dado unas coordenadas reales, un tama?o de buffer y un tama?o de raster.
|
616 |
* Si el buffer es de mayor tama?o que el raster (supersampleo) quiere decir que
|
617 |
* por cada pixel de buffer se repiten varios del raster. Esta funci?n calcula el
|
618 |
* n?mero de pixels de desplazamiento en X e Y que corresponden al primer pixel del
|
619 |
* buffer en la esquina superior izquierda. Esto es necesario porque la coordenada
|
620 |
* solicitada es real y puede no caer sobre un pixel completo. Este calculo es
|
621 |
* util cuando un cliente quiere supersamplear sobre un buffer y que no se lo haga
|
622 |
* el driver autom?ticamente.
|
623 |
* @param dWorldTLX Coordenada real X superior izquierda
|
624 |
* @param dWorldTLY Coordenada real Y superior izquierda
|
625 |
* @param dWorldBRX Coordenada real X inferior derecha
|
626 |
* @param dWorldBRY Coordenada real Y inferior derecha
|
627 |
* @param nWidth Ancho del raster
|
628 |
* @param nHeight Alto del raster
|
629 |
* @param bufWidth Ancho del buffer
|
630 |
* @param bufHeight Alto del buffer
|
631 |
* @return Array de dos elementos con el desplazamiento en X e Y.
|
632 |
*/
|
633 |
public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY, |
634 |
double nWidth, double nHeight, int bufWidth, int bufHeight) { |
635 |
|
636 |
Point2D p1 = new Point2D.Double(dWorldTLX, dWorldTLY); |
637 |
Point2D p2 = new Point2D.Double(dWorldBRX, dWorldBRY); |
638 |
|
639 |
Point2D tl = worldToRaster(new Point2D.Double(p1.getX(), p1.getY())); |
640 |
Point2D br = worldToRaster(new Point2D.Double(p2.getX(), p2.getY())); |
641 |
|
642 |
double wPx = (bufWidth / Math.abs(br.getX() - tl.getX())); |
643 |
double hPx = (bufHeight / Math.abs(br.getY() - tl.getY())); |
644 |
|
645 |
int x = (int)((tl.getX() > br.getX()) ? Math.floor(br.getX()) : Math.floor(tl.getX())); |
646 |
int y = (int)((tl.getY() > br.getY()) ? Math.floor(br.getY()) : Math.floor(tl.getY())); |
647 |
|
648 |
double a = (tl.getX() > br.getX()) ? (Math.abs(br.getX() - x)) : (Math.abs(tl.getX() - x)); |
649 |
double b = (tl.getY() > br.getY()) ? (Math.abs(br.getY() - y)) : (Math.abs(tl.getY() - y)); |
650 |
|
651 |
double stpX = (int)((a * bufWidth) / Math.abs(br.getX() - tl.getX())); |
652 |
double stpY = (int)((b * bufHeight) / Math.abs(br.getY() - tl.getY())); |
653 |
|
654 |
return new double[]{stpX, stpY, wPx, hPx}; |
655 |
} |
656 |
|
657 |
/**
|
658 |
* Convierte un punto desde coordenadas pixel a coordenadas del mundo.
|
659 |
* @param pt Punto a transformar
|
660 |
* @return punto transformado en coordenadas del mundo
|
661 |
*/
|
662 |
public Point2D rasterToWorld(Point2D pt) { |
663 |
Point2D p = new Point2D.Double(); |
664 |
externalTransformation.transform(pt, p); |
665 |
return p;
|
666 |
} |
667 |
|
668 |
/**
|
669 |
* Convierte un punto desde del mundo a coordenadas pixel.
|
670 |
* @param pt Punto a transformar
|
671 |
* @return punto transformado en coordenadas pixel
|
672 |
*/
|
673 |
public Point2D worldToRaster(Point2D pt) { |
674 |
Point2D p = new Point2D.Double(); |
675 |
try {
|
676 |
externalTransformation.inverseTransform(pt, p); |
677 |
} catch (NoninvertibleTransformException e) { |
678 |
return pt;
|
679 |
} |
680 |
return p;
|
681 |
} |
682 |
|
683 |
/**
|
684 |
* Calcula el extent en coordenadas del mundo real
|
685 |
* @return Extent
|
686 |
*/
|
687 |
public Extent getExtent() {
|
688 |
return new ExtentImpl( rasterToWorld(new Point2D.Double(0, 0)), |
689 |
rasterToWorld(new Point2D.Double(getWidth(), getHeight())), |
690 |
rasterToWorld(new Point2D.Double(getWidth(), 0)), |
691 |
rasterToWorld(new Point2D.Double(0, getHeight()))); |
692 |
} |
693 |
|
694 |
/**
|
695 |
* Calcula el extent en coordenadas del mundo real sin rotaci?n. Solo coordenadas y tama?o de pixel
|
696 |
* @return Extent
|
697 |
*/
|
698 |
public Extent getExtentWithoutRot() {
|
699 |
AffineTransform at = new AffineTransform( externalTransformation.getScaleX(), 0, |
700 |
0, externalTransformation.getScaleY(),
|
701 |
externalTransformation.getTranslateX(), externalTransformation.getTranslateY()); |
702 |
Point2D p1 = new Point2D.Double(0, 0); |
703 |
Point2D p2 = new Point2D.Double(getWidth(), getHeight()); |
704 |
at.transform(p1, p1); |
705 |
at.transform(p2, p2); |
706 |
return new ExtentImpl(p1, p2); |
707 |
} |
708 |
|
709 |
/**
|
710 |
* ASigna el par?metro de inicializaci?n del driver.
|
711 |
*/
|
712 |
public void setParam(DataStoreProviderServices provServices, DataStoreParameters param) { |
713 |
if(param instanceof RasterDataParameters) |
714 |
this.uri = ((RasterDataParameters)param).getURI();
|
715 |
this.param = param;
|
716 |
this.storeServices = provServices;
|
717 |
} |
718 |
|
719 |
/*
|
720 |
* (non-Javadoc)
|
721 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewWidth(int, int)
|
722 |
*/
|
723 |
abstract public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException; |
724 |
|
725 |
/*
|
726 |
* (non-Javadoc)
|
727 |
* @see org.gvsig.raster.impl.provider.RasterProvider#selectSubdataset()
|
728 |
*/
|
729 |
public void selectSubdataset() {} |
730 |
|
731 |
/**
|
732 |
* Selects the subdataset. This method will select
|
733 |
* the rmf file.
|
734 |
*/
|
735 |
protected void selectSubdataset(String subdataset) { |
736 |
selectedSubdatasetID = subdataset; |
737 |
getRmfBlocksManager().setPath(getRMFFile()); |
738 |
} |
739 |
|
740 |
/**
|
741 |
* Obtiene el gestor de ficheros RMF
|
742 |
* @return RmfBloksManager
|
743 |
*/
|
744 |
public RmfBlocksManager getRmfBlocksManager() {
|
745 |
String fileRMF = getRMFFile();
|
746 |
if(fileRMF != null) { |
747 |
if (rmfBlocksManager == null || fileRMF.compareTo(rmfBlocksManager.getPath()) != 0) { |
748 |
rmfBlocksManager = new RmfBlocksManager(fileRMF);
|
749 |
} |
750 |
} |
751 |
return rmfBlocksManager;
|
752 |
} |
753 |
|
754 |
/*
|
755 |
* (non-Javadoc)
|
756 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getRMFFile()
|
757 |
*/
|
758 |
public String getRMFFile() { |
759 |
String tail = selectedSubdatasetID == null ? ".rmf" : "-sd" + selectedSubdatasetID + ".rmf"; |
760 |
return fileUtil.getNameWithoutExtension(getURI()) + tail;
|
761 |
} |
762 |
|
763 |
/*
|
764 |
* (non-Javadoc)
|
765 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isInside(java.awt.geom.Point2D)
|
766 |
*/
|
767 |
public boolean isInside(Point2D p){ |
768 |
//Realizamos los calculos solo si el punto est? dentro del extent de la imagen rotada, as? nos ahorramos los calculos
|
769 |
//cuando el puntero est? fuera
|
770 |
|
771 |
Point2D pt = new Point2D.Double(); |
772 |
try {
|
773 |
|
774 |
getAffineTransform().inverseTransform(p, pt); |
775 |
if( pt.getX() >= 0 && pt.getX() < getWidth() && |
776 |
pt.getY() >= 0 && pt.getY() < getHeight())
|
777 |
return true; |
778 |
} catch (NoninvertibleTransformException e) { |
779 |
return false; |
780 |
} |
781 |
|
782 |
return false; |
783 |
} |
784 |
|
785 |
/**
|
786 |
* Consulta de si un raster tiene rotaci?n o no.
|
787 |
* @return true si tiene rotaci?n y false si no la tiene.
|
788 |
*/
|
789 |
public boolean isRotated() { |
790 |
if(externalTransformation.getShearX() != 0 || externalTransformation.getShearY() != 0) |
791 |
return true; |
792 |
return false; |
793 |
} |
794 |
|
795 |
/*
|
796 |
* (non-Javadoc)
|
797 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isMultiFile()
|
798 |
*/
|
799 |
public boolean isMultiFile() { |
800 |
return false; |
801 |
} |
802 |
|
803 |
/*
|
804 |
* (non-Javadoc)
|
805 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isMosaic()
|
806 |
*/
|
807 |
public boolean isMosaic() { |
808 |
return false; |
809 |
} |
810 |
|
811 |
/**
|
812 |
* Devuelve si el Dataset es reproyectable
|
813 |
* @return
|
814 |
*/
|
815 |
public boolean isReproyectable() { |
816 |
return true; |
817 |
} |
818 |
|
819 |
public String getWktProjection() { |
820 |
return wktProjection;
|
821 |
} |
822 |
|
823 |
/*
|
824 |
* (non-Javadoc)
|
825 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#saveObjectToRmf(java.lang.Class, java.lang.Object)
|
826 |
*/
|
827 |
@SuppressWarnings("unchecked") |
828 |
public void saveObjectToRmf(Class class1, Object value) throws RmfSerializerException { |
829 |
((DefaultProviderServices)RasterLocator.getManager().getProviderServices()).saveObjectToRmfFile(getRmfBlocksManager(), class1, value); |
830 |
} |
831 |
|
832 |
/**
|
833 |
* Carga un objecto desde un serializador del tipo class1. Usa value para iniciar dicho
|
834 |
* serializador
|
835 |
*
|
836 |
* @param class1
|
837 |
* @param value
|
838 |
* @return
|
839 |
* @throws RmfSerializerException
|
840 |
*/
|
841 |
@SuppressWarnings("unchecked") |
842 |
private static Object loadObjectFromRmfFile(RmfBlocksManager blocksManager, Class class1, Object value) throws RmfSerializerException { |
843 |
ClassSerializer serializerObject = ((DefaultProviderServices)RasterLocator.getManager().getProviderServices()).getSerializerObject(class1, value); |
844 |
|
845 |
if (serializerObject == null) |
846 |
throw new RmfSerializerException("No se ha podido encontrar el serializador para el Rmf"); |
847 |
|
848 |
if (!blocksManager.checkRmf())
|
849 |
throw new RmfSerializerException("Error al comprobar el fichero Rmf"); |
850 |
|
851 |
blocksManager.addClient(serializerObject); |
852 |
try {
|
853 |
blocksManager.read(null);
|
854 |
} catch (ParsingException e) {
|
855 |
throw new RmfSerializerException("Error al leer el fichero Rmf", e); |
856 |
} |
857 |
blocksManager.removeAllClients(); |
858 |
|
859 |
return serializerObject.getResult();
|
860 |
} |
861 |
|
862 |
/*
|
863 |
* (non-Javadoc)
|
864 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#loadObjectFromRmf(java.lang.Class, java.lang.Object)
|
865 |
*/
|
866 |
@SuppressWarnings("unchecked") |
867 |
public Object loadObjectFromRmf(Class class1, Object value) throws RmfSerializerException { |
868 |
return loadObjectFromRmfFile(getRmfBlocksManager(), class1, value);
|
869 |
} |
870 |
|
871 |
/**
|
872 |
* Carga un objeto del fichero RMF especificado por parametro
|
873 |
* @param file
|
874 |
* @param class1
|
875 |
* @param value
|
876 |
* @return
|
877 |
* @throws RmfSerializerException
|
878 |
*/
|
879 |
@SuppressWarnings("unchecked") |
880 |
public static Object loadObjectFromRmfFile(String file, Class class1, Object value) throws RmfSerializerException { |
881 |
String fileRMF = RasterLocator.getManager().getFileUtils().getNameWithoutExtension(file) + ".rmf"; |
882 |
RmfBlocksManager blocksManager = new RmfBlocksManager(fileRMF);
|
883 |
return loadObjectFromRmfFile(blocksManager, class1, value);
|
884 |
} |
885 |
|
886 |
/**
|
887 |
* Guarda en el RMF el objecto actual en caso de que exista un serializador para el
|
888 |
* @param value
|
889 |
* @throws RmfSerializerException
|
890 |
*/
|
891 |
public void saveObjectToRmf(Object value) throws RmfSerializerException { |
892 |
saveObjectToRmf(value.getClass(), value); |
893 |
} |
894 |
|
895 |
/**
|
896 |
* Carga un objecto desde un serializador usando el tipo del mismo objeto pasado por parametro.
|
897 |
* Usa value para iniciar dicho serializador
|
898 |
* @param value
|
899 |
* @return
|
900 |
* @throws RmfSerializerException
|
901 |
*/
|
902 |
public Object loadObjectFromRmf(Object value) throws RmfSerializerException { |
903 |
return loadObjectFromRmf(value.getClass(), value);
|
904 |
} |
905 |
|
906 |
|
907 |
public double getCellSize() { |
908 |
try {
|
909 |
Extent e = getExtent(); |
910 |
double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
|
911 |
return dCellsize;
|
912 |
} catch (NullPointerException e) { |
913 |
return 1; |
914 |
} |
915 |
} |
916 |
|
917 |
|
918 |
public RasterProvider newProvider() {
|
919 |
return null; |
920 |
} |
921 |
|
922 |
/*
|
923 |
* (non-Javadoc)
|
924 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#getColorTable()
|
925 |
*/
|
926 |
public ColorTable getColorTable() {
|
927 |
return colorTable;
|
928 |
} |
929 |
|
930 |
/*
|
931 |
* (non-Javadoc)
|
932 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getImageLegend()
|
933 |
*/
|
934 |
public Image getImageLegend() { |
935 |
return null; |
936 |
} |
937 |
|
938 |
/*
|
939 |
* (non-Javadoc)
|
940 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setColorTable(org.gvsig.fmap.dal.coverage.store.props.ColorTable)
|
941 |
*/
|
942 |
public void setColorTable(ColorTable value) { |
943 |
colorTable = value; |
944 |
} |
945 |
|
946 |
/*
|
947 |
* (non-Javadoc)
|
948 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#getTransparency()
|
949 |
*/
|
950 |
public Transparency getTransparency() { |
951 |
return transparency;
|
952 |
} |
953 |
|
954 |
/*
|
955 |
* (non-Javadoc)
|
956 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getMetadata()
|
957 |
*/
|
958 |
public Metadata getMetadata() {
|
959 |
return null; |
960 |
} |
961 |
|
962 |
/*
|
963 |
* (non-Javadoc)
|
964 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#getColorInterpretation()
|
965 |
*/
|
966 |
public ColorInterpretation getColorInterpretation() {
|
967 |
return this.colorInterpretation; |
968 |
} |
969 |
|
970 |
/**
|
971 |
* Asigna el objeto que contiene que contiene la interpretaci?n de
|
972 |
* color por banda
|
973 |
* @param DataStoreColorInterpretation
|
974 |
*/
|
975 |
public void setColorInterpretation(ColorInterpretation colorInterpretation) { |
976 |
this.colorInterpretation = colorInterpretation;
|
977 |
} |
978 |
|
979 |
/*
|
980 |
* (non-Javadoc)
|
981 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#getStatistics()
|
982 |
*/
|
983 |
public Statistics getStatistics() {
|
984 |
if(stats == null) { |
985 |
stats = new SimpleProviderStatistics(this); |
986 |
} |
987 |
return stats;
|
988 |
} |
989 |
|
990 |
/*
|
991 |
* (non-Javadoc)
|
992 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setStatistics(org.gvsig.fmap.dal.coverage.store.props.Statistics)
|
993 |
*/
|
994 |
public void setStatistics(Statistics stats) { |
995 |
this.stats = stats;
|
996 |
} |
997 |
|
998 |
/*
|
999 |
* (non-Javadoc)
|
1000 |
* @see org.gvsig.fmap.dal.coverage.store.props.Histogramable#getHistogramComputer()
|
1001 |
*/
|
1002 |
public HistogramComputer getHistogramComputer() {
|
1003 |
if (histogram == null) |
1004 |
histogram = new SimpleProviderHistogramComputer(this); |
1005 |
return histogram;
|
1006 |
} |
1007 |
|
1008 |
//****************************************************
|
1009 |
//*********Implementing Disposable methods************
|
1010 |
//****************************************************
|
1011 |
|
1012 |
/*
|
1013 |
* (non-Javadoc)
|
1014 |
* @see org.gvsig.tools.dispose.impl.AbstractDisposable#doDispose()
|
1015 |
*/
|
1016 |
public void doDispose() { |
1017 |
|
1018 |
} |
1019 |
|
1020 |
//****************************************************
|
1021 |
//*****Implementing DataStoreProvider methods*********
|
1022 |
//****************************************************
|
1023 |
|
1024 |
/**
|
1025 |
* Gets the specific parameter. All of them inherit from RasterStoreParameters
|
1026 |
*/
|
1027 |
//public abstract RasterStoreParameters getRasterParameters();
|
1028 |
|
1029 |
@Override
|
1030 |
public DataServerExplorer getExplorer() throws ReadException, |
1031 |
ValidateDataParametersException { |
1032 |
/*DataManager manager = DALLocator.getDataManager();
|
1033 |
FilesystemServerExplorerParameters params;
|
1034 |
try {
|
1035 |
params = (FilesystemServerExplorerParameters) manager
|
1036 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME);
|
1037 |
params.setRoot(((AbstractRasterStoreParameters)this.getDataParameters()).getFile().getParent());
|
1038 |
return manager.createServerExplorer(params);
|
1039 |
} catch (DataException e) {
|
1040 |
throw new ReadException(this.getName(), e);
|
1041 |
}*/
|
1042 |
return null; |
1043 |
} |
1044 |
|
1045 |
|
1046 |
/**
|
1047 |
* Returs the DataParameters
|
1048 |
* @return
|
1049 |
*/
|
1050 |
public RasterDataParameters getDataParameters() {
|
1051 |
if(getDataStoreParameters() instanceof RasterDataParameters) |
1052 |
return (RasterDataParameters)getDataStoreParameters();
|
1053 |
return null; |
1054 |
} |
1055 |
|
1056 |
/*
|
1057 |
* (non-Javadoc)
|
1058 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getChilds()
|
1059 |
*/
|
1060 |
@SuppressWarnings("unchecked") |
1061 |
public Iterator getChilds() { |
1062 |
return null; |
1063 |
} |
1064 |
|
1065 |
/*
|
1066 |
* (non-Javadoc)
|
1067 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getResource()
|
1068 |
*/
|
1069 |
public ResourceProvider getResource() {
|
1070 |
return null; |
1071 |
} |
1072 |
|
1073 |
/*
|
1074 |
* (non-Javadoc)
|
1075 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getSourceId()
|
1076 |
*/
|
1077 |
public Object getSourceId() { |
1078 |
if( this.getDataParameters() instanceof RasterFileStoreParameters) |
1079 |
return ((RasterFileStoreParameters)this.getDataParameters()).getFile(); |
1080 |
else
|
1081 |
return this.getDataParameters().getURI(); |
1082 |
} |
1083 |
|
1084 |
/*
|
1085 |
* (non-Javadoc)
|
1086 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#open()
|
1087 |
*/
|
1088 |
public void open() throws OpenException { |
1089 |
} |
1090 |
|
1091 |
/**
|
1092 |
* Traduce el nombre del fichero por un alias asignado por el propio driver.
|
1093 |
* Cuando es traducido por un alias el driver intentar? abrir el alias y no el
|
1094 |
* fichero. Esto es util porque algunos formatos tienen la extensi?n en el
|
1095 |
* fichero de cabecera pero lo que se abre realmente es el fichero de datos.
|
1096 |
* @param fileName
|
1097 |
* @return
|
1098 |
*/
|
1099 |
public String translateFileName(String fileName) { |
1100 |
return fileName;
|
1101 |
} |
1102 |
|
1103 |
/*
|
1104 |
* (non-Javadoc)
|
1105 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFileSuffix()
|
1106 |
*/
|
1107 |
public String getFileSuffix() { |
1108 |
return getURIOfFirstProvider().substring(getURIOfFirstProvider().lastIndexOf(".") + 1, getURIOfFirstProvider().length()); |
1109 |
} |
1110 |
|
1111 |
/*
|
1112 |
* (non-Javadoc)
|
1113 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getURIOfFirstProvider()
|
1114 |
*/
|
1115 |
public String getURIOfFirstProvider() { |
1116 |
return RasterLocator.getManager().getFileUtils().getFormatedRasterFileName(uri);
|
1117 |
} |
1118 |
|
1119 |
/*
|
1120 |
* (non-Javadoc)
|
1121 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getURI()
|
1122 |
*/
|
1123 |
public String getURI() { |
1124 |
return uri;
|
1125 |
} |
1126 |
|
1127 |
public void setFName(String n) { |
1128 |
uri = n; |
1129 |
} |
1130 |
|
1131 |
/**
|
1132 |
* Gets the size of the file if exists in Bytes
|
1133 |
* @return
|
1134 |
*/
|
1135 |
public long getFileSize() { |
1136 |
return fileSize;
|
1137 |
} |
1138 |
|
1139 |
public void setFileSize(long sz) { |
1140 |
fileSize = sz; |
1141 |
} |
1142 |
|
1143 |
/*
|
1144 |
* (non-Javadoc)
|
1145 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getProjection()
|
1146 |
*/
|
1147 |
public IProjection getProjection() {
|
1148 |
return proj;
|
1149 |
} |
1150 |
|
1151 |
public void setProjection(IProjection p) { |
1152 |
proj = p; |
1153 |
} |
1154 |
|
1155 |
protected long getTime() { |
1156 |
return (new Date()).getTime(); |
1157 |
} |
1158 |
|
1159 |
/*
|
1160 |
* (non-Javadoc)
|
1161 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#setAffineTransform(java.awt.geom.AffineTransform)
|
1162 |
*/
|
1163 |
public void setAffineTransform(AffineTransform t) { |
1164 |
externalTransformation = (AffineTransform) t.clone();
|
1165 |
} |
1166 |
|
1167 |
/*
|
1168 |
* (non-Javadoc)
|
1169 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform()
|
1170 |
*/
|
1171 |
public AffineTransform getAffineTransform() { |
1172 |
return externalTransformation;
|
1173 |
} |
1174 |
|
1175 |
/**
|
1176 |
* Elimina la matriz de transformaci?n asociada al raster y que se tiene en
|
1177 |
* cuenta para el setView. Este reseteo tendr? en cuenta que si el raster
|
1178 |
* tiene asociado un rmf esta transformaci?n no ser? eliminada sino que se
|
1179 |
* asignar? la correspondiente al rmf existente.
|
1180 |
* @return devuelve true si tiene fichero rmf asociado y false si no lo tiene.
|
1181 |
*/
|
1182 |
public void resetAffineTransform() { |
1183 |
externalTransformation.setToIdentity(); |
1184 |
} |
1185 |
|
1186 |
/*
|
1187 |
* (non-Javadoc)
|
1188 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getOwnAffineTransform()
|
1189 |
*/
|
1190 |
public AffineTransform getOwnAffineTransform() { |
1191 |
return ownTransformation;
|
1192 |
} |
1193 |
|
1194 |
/*
|
1195 |
* (non-Javadoc)
|
1196 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getInfoByPoint(double, double)
|
1197 |
*/
|
1198 |
public String getInfoByPoint(double x, double y, ICancellable cancellable) throws RemoteServiceException { |
1199 |
return null; |
1200 |
} |
1201 |
|
1202 |
/*
|
1203 |
* (non-Javadoc)
|
1204 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setTileServer(java.lang.Class)
|
1205 |
*/
|
1206 |
public void setTileServer(Class<?> tileServer) throws InitializeException { |
1207 |
|
1208 |
} |
1209 |
|
1210 |
/*
|
1211 |
* (non-Javadoc)
|
1212 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getTileSize()
|
1213 |
*/
|
1214 |
public int[] getTileSize(int level) { |
1215 |
return new int[]{0, 0}; |
1216 |
} |
1217 |
|
1218 |
/*
|
1219 |
* (non-Javadoc)
|
1220 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isRasterEnclosed()
|
1221 |
*/
|
1222 |
public boolean isRasterEnclosed() { |
1223 |
return false; |
1224 |
} |
1225 |
|
1226 |
/*
|
1227 |
* (non-Javadoc)
|
1228 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getSourceType()
|
1229 |
*/
|
1230 |
public int getSourceType() { |
1231 |
if(getURI().startsWith("PG:host")) |
1232 |
return RasterDataStore.POSTGIS;
|
1233 |
if(getURI().startsWith("http:") || getURI().startsWith("https:")) |
1234 |
return RasterDataStore.REMOTE;
|
1235 |
return RasterDataStore.FILE;
|
1236 |
} |
1237 |
|
1238 |
/**
|
1239 |
* Most of providers don't need tiles. It those cases this method
|
1240 |
* won't execute anything. Only providers that use tile cache will need
|
1241 |
* implement this function, for instance TileProvider and MosaicProvider.
|
1242 |
*/
|
1243 |
public void deleteLayerFromCache() { |
1244 |
|
1245 |
} |
1246 |
|
1247 |
/*
|
1248 |
* (non-Javadoc)
|
1249 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getTimeSerials()
|
1250 |
*/
|
1251 |
public TimeSeries getTimeSerials() throws RmfSerializerException { |
1252 |
if(serialInfo == null) { |
1253 |
serialInfo = new DefaultTimeSerials();
|
1254 |
loadObjectFromRmf(TimeSeries.class, serialInfo); |
1255 |
//Seleccionamos la primera serie por defecto. El usuario seleccionar? otra si la necesita
|
1256 |
serialInfo.selectSerial(0);
|
1257 |
} |
1258 |
return serialInfo;
|
1259 |
} |
1260 |
|
1261 |
/*
|
1262 |
* (non-Javadoc)
|
1263 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setTimeSerials(org.gvsig.fmap.dal.coverage.store.props.TimeSerials)
|
1264 |
*/
|
1265 |
public void setTimeSerials(TimeSeries serialInfo) throws RmfSerializerException { |
1266 |
this.serialInfo = serialInfo;
|
1267 |
saveObjectToRmf(TimeSeries.class, serialInfo); |
1268 |
} |
1269 |
|
1270 |
/*
|
1271 |
* (non-Javadoc)
|
1272 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFileSizeByProvider()
|
1273 |
*/
|
1274 |
public long[] getFileSizeByProvider() { |
1275 |
return new long[]{getFileSize()}; |
1276 |
} |
1277 |
|
1278 |
/*
|
1279 |
* (non-Javadoc)
|
1280 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFileNameByProvider()
|
1281 |
*/
|
1282 |
public String[] getURIByProvider() { |
1283 |
//For providers with one file
|
1284 |
return new String[]{getURIOfFirstProvider()}; |
1285 |
} |
1286 |
|
1287 |
/*
|
1288 |
* (non-Javadoc)
|
1289 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getBandCountByProvider()
|
1290 |
*/
|
1291 |
public int[] getBandCountByProvider() { |
1292 |
return new int[]{getBandCount()}; |
1293 |
} |
1294 |
|
1295 |
/*
|
1296 |
* (non-Javadoc)
|
1297 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getInternalProviderCount()
|
1298 |
*/
|
1299 |
public int getInternalProviderCount() { |
1300 |
return 1; |
1301 |
} |
1302 |
|
1303 |
/*
|
1304 |
* (non-Javadoc)
|
1305 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getInternalProvider(int)
|
1306 |
*/
|
1307 |
public RasterProvider getInternalProvider(int i) { |
1308 |
return this; |
1309 |
} |
1310 |
|
1311 |
/*
|
1312 |
* (non-Javadoc)
|
1313 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getURIByBand(int)
|
1314 |
*/
|
1315 |
public String getURIByBand(int band) { |
1316 |
//No matter which band be selected. In providers with one file is always the first URI
|
1317 |
return getURIOfFirstProvider();
|
1318 |
} |
1319 |
|
1320 |
/*
|
1321 |
* (non-Javadoc)
|
1322 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getBandPositionByProvider(int)
|
1323 |
*/
|
1324 |
public int getBandPositionByProvider(int band) { |
1325 |
return band;
|
1326 |
} |
1327 |
|
1328 |
/*
|
1329 |
* (non-Javadoc)
|
1330 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getSubdatasetCount()
|
1331 |
*/
|
1332 |
public int getSubdatasetCount() { |
1333 |
return 0; |
1334 |
} |
1335 |
|
1336 |
/*
|
1337 |
* (non-Javadoc)
|
1338 |
* @see org.gvsig.raster.impl.provider.RasterProvider#addFile(java.lang.String)
|
1339 |
*/
|
1340 |
public void addFile(String file) throws InvalidSourceException { |
1341 |
//Do nothing
|
1342 |
} |
1343 |
|
1344 |
/*
|
1345 |
* (non-Javadoc)
|
1346 |
* @see org.gvsig.raster.impl.provider.RasterProvider#removeFile(java.lang.String)
|
1347 |
*/
|
1348 |
public void removeFile(String file) { |
1349 |
//Do nothing
|
1350 |
} |
1351 |
|
1352 |
/*
|
1353 |
* (non-Javadoc)
|
1354 |
* @see org.gvsig.raster.impl.provider.RasterProvider#needEnhanced()
|
1355 |
*/
|
1356 |
public boolean needEnhanced() { |
1357 |
return false; |
1358 |
} |
1359 |
|
1360 |
/**
|
1361 |
* Gets the {@link Interval} of the store, that means the temporal
|
1362 |
* interval where the store has valid data.
|
1363 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
1364 |
* by the provider.
|
1365 |
* @return
|
1366 |
* a time interval or null if there is not time support
|
1367 |
*/
|
1368 |
public Interval getInterval() {
|
1369 |
return null; |
1370 |
} |
1371 |
|
1372 |
/**
|
1373 |
* Gets all the possible values of time for which the store has data.
|
1374 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
1375 |
* by the provider.
|
1376 |
* @return
|
1377 |
* a collection of {@link Time} objects.
|
1378 |
*/
|
1379 |
@SuppressWarnings("unchecked") |
1380 |
public Collection getTimes() { |
1381 |
return null; |
1382 |
} |
1383 |
|
1384 |
/**
|
1385 |
* Gets all the possible values of time for which the store has data
|
1386 |
* and intersects with an interval.
|
1387 |
* In raster this method has sense in a mosaic. Therefore this has to be implemented
|
1388 |
* by the provider.
|
1389 |
* @param interval
|
1390 |
* the interval of time
|
1391 |
* @return
|
1392 |
* a collection of {@link Time} objects.
|
1393 |
*/
|
1394 |
@SuppressWarnings("unchecked") |
1395 |
public Collection getTimes(Interval interval) { |
1396 |
return null; |
1397 |
} |
1398 |
|
1399 |
public void close() { |
1400 |
if(transparency != null) |
1401 |
transparency.dispose(); |
1402 |
try {
|
1403 |
finalize(); |
1404 |
} catch (Throwable e) { |
1405 |
} |
1406 |
} |
1407 |
|
1408 |
/*
|
1409 |
* (non-Javadoc)
|
1410 |
* @see java.lang.Object#finalize()
|
1411 |
*/
|
1412 |
protected void finalize() throws Throwable { |
1413 |
dataType = null;
|
1414 |
noData = null;
|
1415 |
wktProjection = null;
|
1416 |
stats = null;
|
1417 |
histogram = null;
|
1418 |
param = null;
|
1419 |
storeServices = null;
|
1420 |
rmfBlocksManager = null;
|
1421 |
colorTable = null;
|
1422 |
colorInterpretation = null;
|
1423 |
serialInfo = null;
|
1424 |
transparency = null;
|
1425 |
tileServer = null;
|
1426 |
fileUtil = null;
|
1427 |
rasterUtil = null;
|
1428 |
proj = null;
|
1429 |
uri = null;
|
1430 |
selectedSubdatasetID = null;
|
1431 |
ownTransformation = null;
|
1432 |
externalTransformation = null;
|
1433 |
} |
1434 |
} |