gvsig-raster / org.gvsig.raster.mosaic / trunk / org.gvsig.raster.mosaic / org.gvsig.raster.mosaic.io / src / main / java / org / gvsig / raster / mosaic / io / MosaicProvider.java @ 2193
History | View | Annotate | Download (31.1 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.mosaic.io; |
23 |
|
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.io.File; |
28 |
import java.io.IOException; |
29 |
import java.security.MessageDigest; |
30 |
import java.security.NoSuchAlgorithmException; |
31 |
import java.util.ArrayList; |
32 |
import java.util.Date; |
33 |
import java.util.HashMap; |
34 |
import java.util.List; |
35 |
|
36 |
import org.cresques.cts.IProjection; |
37 |
import org.gvsig.compat.net.ICancellable; |
38 |
import org.gvsig.fmap.dal.DALFileLocator; |
39 |
import org.gvsig.fmap.dal.DALLocator; |
40 |
import org.gvsig.fmap.dal.DataStore; |
41 |
import org.gvsig.fmap.dal.DataStoreParameters; |
42 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
43 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
44 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
45 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
46 |
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand; |
47 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
48 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
49 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
50 |
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException; |
51 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
52 |
import org.gvsig.fmap.dal.coverage.exception.FileNotSupportedException; |
53 |
import org.gvsig.fmap.dal.coverage.exception.HistogramException; |
54 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
55 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
56 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
57 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
58 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
59 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
60 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
61 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
62 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
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.util.MathUtils; |
66 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
67 |
import org.gvsig.fmap.dal.exception.InitializeException; |
68 |
import org.gvsig.fmap.dal.exception.OpenException; |
69 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
70 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
71 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
72 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
73 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
74 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
75 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
76 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
77 |
import org.gvsig.metadata.MetadataLocator; |
78 |
import org.gvsig.raster.cache.tile.Tile; |
79 |
import org.gvsig.raster.cache.tile.TileCache; |
80 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
81 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
82 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
83 |
import org.gvsig.raster.cache.tile.exception.TileBuildException; |
84 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
85 |
import org.gvsig.raster.cache.tile.layer.TiledLayer; |
86 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
87 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
88 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
89 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
90 |
import org.gvsig.raster.impl.datastruct.DatasetBandImpl; |
91 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
92 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
93 |
import org.gvsig.raster.impl.provider.MemoryMatrixBuffer; |
94 |
import org.gvsig.raster.impl.provider.RasterProvider; |
95 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
96 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
97 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
98 |
import org.gvsig.raster.impl.store.properties.SimpleProviderHistogramComputer; |
99 |
import org.gvsig.raster.impl.store.properties.SimpleProviderStatistics; |
100 |
import org.gvsig.raster.mosaic.io.downloader.MosaicTileServer; |
101 |
import org.gvsig.timesupport.RelativeInstant; |
102 |
import org.gvsig.timesupport.Time; |
103 |
import org.gvsig.timesupport.TimeSupportLocator; |
104 |
import org.gvsig.tools.ToolsLocator; |
105 |
import org.gvsig.tools.task.TaskStatus; |
106 |
import org.slf4j.Logger; |
107 |
import org.slf4j.LoggerFactory; |
108 |
/**
|
109 |
* Data provider for raster mosaics
|
110 |
*
|
111 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
112 |
*/
|
113 |
@SuppressWarnings("deprecation") |
114 |
public class MosaicProvider extends DefaultRasterProvider { |
115 |
public static String NAME = "Mosaic Raster"; |
116 |
public static String DESCRIPTION = "Mosaic Raster Support"; |
117 |
public final String METADATA_DEFINITION_NAME = NAME; |
118 |
private static final Logger logger = LoggerFactory.getLogger(MosaicProvider.class); |
119 |
private boolean open = false; |
120 |
private RasterUtils util = RasterLocator.getManager().getRasterUtils();
|
121 |
private MathUtils math = RasterLocator.getManager().getMathUtils();
|
122 |
protected static String[] formatList = null; |
123 |
//private MosaicRasterFormat mosaicRasterFormat = null;
|
124 |
private List<RasterProvider> providerList = null; |
125 |
private double pixelSize = 0D; |
126 |
private Extent extent = null; |
127 |
private double width = 0; |
128 |
private double height = 0; |
129 |
private Extent viewRequest = null; |
130 |
private TiledLayer tiledLayer = null; |
131 |
//This provider needs a MosaicTileServer by set of layers
|
132 |
private HashMap<String, MosaicTileServer> |
133 |
tileServerMap = new HashMap<String, MosaicTileServer>(); |
134 |
private ArrayList<RasterProvider> selectedProviders = new ArrayList<RasterProvider>(); |
135 |
|
136 |
public static void register() { |
137 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
138 |
registerFormats(); |
139 |
|
140 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
141 |
dataman.registerStoreProvider(NAME, |
142 |
MosaicProvider.class, MosaicDataParametersImpl.class); |
143 |
} |
144 |
|
145 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
146 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
147 |
NAME, DESCRIPTION, |
148 |
MosaicServerExplorer.class); |
149 |
|
150 |
if (!dataman.getExplorerProviders().contains(NAME)) {
|
151 |
dataman.registerExplorerProvider(NAME, MosaicServerExplorer.class, MosaicServerExplorerParameters.class); |
152 |
} |
153 |
|
154 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
155 |
} |
156 |
|
157 |
private static void registerFormats() { |
158 |
formatList = new String[] {"mrf"}; |
159 |
for (int i = 0; i < formatList.length; i++) |
160 |
RasterLocator.getManager().addFormat(formatList[i], MosaicProvider.class); |
161 |
} |
162 |
|
163 |
public String[] getFormatList() { |
164 |
return formatList;
|
165 |
} |
166 |
|
167 |
/**
|
168 |
* Returns true if the extension is supported and false if doesn't
|
169 |
* @param ext
|
170 |
* @return
|
171 |
*/
|
172 |
public boolean isExtensionSupported(String ext) { |
173 |
if(ext.indexOf(".") != -1) |
174 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
175 |
for (int i = 0; i < formatList.length; i++) { |
176 |
if(formatList[i].compareTo(ext) == 0) |
177 |
return true; |
178 |
} |
179 |
return false; |
180 |
} |
181 |
|
182 |
public MosaicProvider() {
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Opens the dataset.
|
187 |
* @param proj Projection
|
188 |
* @param fName File name
|
189 |
* @throws NotSupportedExtensionException
|
190 |
*/
|
191 |
public MosaicProvider(String params) throws NotSupportedExtensionException, OpenException { |
192 |
super(params);
|
193 |
if(params instanceof String) { |
194 |
MosaicDataParametersImpl p = new MosaicDataParametersImpl();
|
195 |
p.setURI((String)params);
|
196 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
197 |
.createDynObject( |
198 |
MetadataLocator.getMetadataManager().getDefinition( |
199 |
DataStore.METADATA_DEFINITION_NAME))); |
200 |
init(p, null);
|
201 |
} |
202 |
} |
203 |
|
204 |
public MosaicProvider (MosaicDataParametersImpl params,
|
205 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
|
206 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
207 |
.createDynObject( |
208 |
MetadataLocator.getMetadataManager().getDefinition( |
209 |
DataStore.METADATA_DEFINITION_NAME))); |
210 |
init(params, storeServices); |
211 |
} |
212 |
|
213 |
/**
|
214 |
* Build file references
|
215 |
* @param proj Projection
|
216 |
* @param param Load parameters
|
217 |
* @throws NotSupportedExtensionException
|
218 |
*/
|
219 |
public void init (AbstractRasterDataParameters params, |
220 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
|
221 |
setParam(storeServices, params); |
222 |
|
223 |
openFromMrf(); |
224 |
|
225 |
calcMetadataFromParams(); |
226 |
|
227 |
super.init();
|
228 |
|
229 |
try {
|
230 |
loadFromRmf(getRmfBlocksManager()); |
231 |
} catch (ParsingException e) {
|
232 |
//No lee desde rmf
|
233 |
} |
234 |
|
235 |
open = true;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Calculates metadata using the parameters
|
240 |
*/
|
241 |
private void calcMetadataFromParams() { |
242 |
uri = getParameters().getURI(); |
243 |
providerList = getParameters().getProviders(); |
244 |
pixelSize = getParameters().getPixelSize(); |
245 |
setColorInterpretation(providerList.get(0).getColorInterpretation().cloneColorInterpretation());
|
246 |
|
247 |
//Se le pone banda de transparencia siempre
|
248 |
if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) { |
249 |
transparency = new DataStoreTransparency();
|
250 |
transparency.setTransparencyBand(getBandCount() - 1);
|
251 |
} else
|
252 |
transparency = providerList.get(0).getTransparency();
|
253 |
|
254 |
extent = null;
|
255 |
for (int i = 0; i < providerList.size(); i++) { |
256 |
if(extent == null) |
257 |
extent = providerList.get(i).getExtent(); |
258 |
else
|
259 |
extent = extent.encloseBoundinBoxes(providerList.get(i).getExtent()); |
260 |
|
261 |
//Usa el primer NoData de la primera imagen que tenga un valor asignado
|
262 |
if(noData == null && providerList.get(i).getNoDataValue().isDefined()) |
263 |
noData = providerList.get(i).getNoDataValue(); |
264 |
} |
265 |
width = extent.width() / pixelSize; |
266 |
height = extent.height() / pixelSize; |
267 |
|
268 |
ownTransformation = new AffineTransform(pixelSize, 0, |
269 |
0, -pixelSize,
|
270 |
extent.getULX(), extent.getULY()); |
271 |
externalTransformation = (AffineTransform) ownTransformation.clone();
|
272 |
|
273 |
((MosaicDataParametersImpl)getParameters()).resetParamsChanged(); |
274 |
} |
275 |
|
276 |
/**
|
277 |
* Loads the specific provider
|
278 |
* @param file
|
279 |
* @return
|
280 |
* @throws NotSupportedExtensionException
|
281 |
* @throws FileNotSupportedException
|
282 |
*/
|
283 |
@SuppressWarnings("unchecked") |
284 |
private RasterProvider loadProvider(String file, DataStoreProviderServices storeServices) throws ProviderNotRegisteredException, InitializeException { |
285 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
286 |
DataStoreProvider prov = null;
|
287 |
|
288 |
if(file != null) { |
289 |
//We have to locate a provider's name which manages the selected file
|
290 |
//A FilesystemServerExplorer will give a getProviderNames service
|
291 |
FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
292 |
FilesystemServerExplorer serverExplorer = null;
|
293 |
try {
|
294 |
paramsExplorer.setRoot(File.separator);
|
295 |
serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer); |
296 |
} catch (ValidateDataParametersException e) {
|
297 |
throw new InitializeException(e); |
298 |
} |
299 |
File f = new File(file); |
300 |
//Gets the list of provider's name to manage the file
|
301 |
List<String> provName = serverExplorer.getProviderNameList(f); |
302 |
if(provName.size() > 0) { |
303 |
for (int i = 0; i < provName.size(); i++) { |
304 |
//Gets the first provider what is not a TileProvider
|
305 |
if(provName.get(i).compareTo("Tile Store") != 0) { |
306 |
DataStoreParameters newparams = dataManager.createStoreParameters(provName.get(i)); |
307 |
((FilesystemStoreParameters)newparams).setFile(f); |
308 |
prov = dataManager.createProvider(storeServices, newparams); |
309 |
} |
310 |
} |
311 |
} |
312 |
} |
313 |
|
314 |
if(prov != null && prov instanceof RasterProvider) { |
315 |
if(((RasterProvider)prov).isRotated())
|
316 |
throw new InitializeException("Rotation not supported tiling files", new Throwable()); |
317 |
|
318 |
return (RasterProvider)prov;
|
319 |
} |
320 |
|
321 |
return null; |
322 |
} |
323 |
|
324 |
/**
|
325 |
* Open from a .mrf file.
|
326 |
* This method loads all providers and adds these to the parameters
|
327 |
* @throws OpenException
|
328 |
*/
|
329 |
private void openFromMrf() throws OpenException { |
330 |
if(getParameters().getURI() != null && new File(getParameters().getURI()).exists()) { |
331 |
try {
|
332 |
if(getParameters().getProviders() != null) |
333 |
getParameters().getProviders().clear(); |
334 |
MosaicRasterFormat multiFileFormat = new MosaicRasterFormat();
|
335 |
multiFileFormat = MosaicRasterFormatSerializer.read(multiFileFormat, getParameters().getURI()); |
336 |
for (int i = 0; i < multiFileFormat.getNumberOfFiles(); i++) { |
337 |
try {
|
338 |
File file = new File(multiFileFormat.getPathToFile(i)); |
339 |
if(file.exists()) {
|
340 |
RasterProvider prov = loadProvider(multiFileFormat.getPathToFile(i), storeServices); |
341 |
if(i == 0) |
342 |
getParameters().setPixelSize(prov.getCellSize()); |
343 |
getParameters().addProvider(prov); |
344 |
} |
345 |
} catch (ProviderNotRegisteredException e) {
|
346 |
throw new OpenException("A provider can't be loaded", e); |
347 |
} catch (InitializeException e) {
|
348 |
throw new OpenException("A provider can't be initialized", e); |
349 |
} |
350 |
} |
351 |
} catch (IOException e1) { |
352 |
throw new OpenException("File .mrf can't be read", e1); |
353 |
} catch (ParsingException e1) {
|
354 |
throw new OpenException("File .mrf can't be parsed", e1); |
355 |
} |
356 |
} |
357 |
} |
358 |
|
359 |
public RasterProvider load() {
|
360 |
return this; |
361 |
} |
362 |
|
363 |
/**
|
364 |
* Gets the MosaicDataParameters
|
365 |
* @return
|
366 |
*/
|
367 |
public MosaicDataParameters getParameters() {
|
368 |
try {
|
369 |
return (MosaicDataParameters)parameters;
|
370 |
} catch (ClassCastException e) { |
371 |
return null; |
372 |
} |
373 |
} |
374 |
|
375 |
public boolean isOpen() { |
376 |
return open;
|
377 |
} |
378 |
|
379 |
public void close() { |
380 |
for (int i = 0; i < providerList.size(); i++) { |
381 |
providerList.get(i).close(); |
382 |
} |
383 |
} |
384 |
|
385 |
/**
|
386 |
* @return Returns the dataType.
|
387 |
*/
|
388 |
public int[] getDataType() { |
389 |
if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) { |
390 |
int[] dt = new int[getBandCount()]; |
391 |
for (int i = 0; i < providerList.get(0).getDataType().length; i++) { |
392 |
dt[i] = providerList.get(0).getDataType()[i];
|
393 |
} |
394 |
dt[getBandCount() - 1] = Buffer.TYPE_BYTE; |
395 |
return dt;
|
396 |
} |
397 |
return providerList.get(0).getDataType(); |
398 |
} |
399 |
|
400 |
/**
|
401 |
* Gets the number of bands
|
402 |
* @return
|
403 |
*/
|
404 |
public int getBandCount() { |
405 |
if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) |
406 |
return providerList.get(0).getBandCount() + 1; |
407 |
return providerList.get(0).getBandCount(); |
408 |
} |
409 |
|
410 |
public String[] getURIByProvider() { |
411 |
providerList = getParameters().getProviders(); |
412 |
String[] uris = new String[providerList.size()]; |
413 |
for (int i = 0; i < uris.length; i++) { |
414 |
uris[i] = providerList.get(i).getURI(); |
415 |
} |
416 |
return uris;
|
417 |
} |
418 |
|
419 |
public String getURIByBand(int band) { |
420 |
//No matter which band be selected. In providers with one file is always the first URI
|
421 |
return getURI();
|
422 |
} |
423 |
|
424 |
public double getPixelSizeX() { |
425 |
if(getParameters().hasParamsChanged())
|
426 |
calcMetadataFromParams(); |
427 |
return pixelSize;
|
428 |
} |
429 |
|
430 |
public double getPixelSizeY() { |
431 |
if(getParameters().hasParamsChanged())
|
432 |
calcMetadataFromParams(); |
433 |
return pixelSize;
|
434 |
} |
435 |
|
436 |
public NoData getNoDataValue() {
|
437 |
if(getParameters().hasParamsChanged())
|
438 |
calcMetadataFromParams(); |
439 |
return noData;
|
440 |
} |
441 |
|
442 |
public Extent getExtent() {
|
443 |
if(getParameters().hasParamsChanged())
|
444 |
calcMetadataFromParams(); |
445 |
return extent;
|
446 |
} |
447 |
|
448 |
public double getCellSize() { |
449 |
return pixelSize;
|
450 |
} |
451 |
|
452 |
public Statistics getStatistics() {
|
453 |
if(stats == null || getParameters().hasParamsChanged()) { |
454 |
//First of all read the statistics in the rmf. If these have not been calculated then
|
455 |
//we'll read the statistics from simple files
|
456 |
stats = super.getStatistics();
|
457 |
try {
|
458 |
loadObjectFromRmf(SimpleProviderStatistics.class, stats); |
459 |
} catch (RmfSerializerException e) {
|
460 |
// Si no se puede cargar del RMF, recalcularemos las estadisticas.
|
461 |
} |
462 |
if(!stats.isCalculated()) {
|
463 |
calcMetadataFromParams(); |
464 |
providerList = getParameters().getProviders(); |
465 |
stats = SimpleProviderStatistics.union(this, providerList);
|
466 |
} |
467 |
} |
468 |
return stats;
|
469 |
} |
470 |
|
471 |
public HistogramComputer getHistogramComputer() {
|
472 |
if(histogram == null || getParameters().hasParamsChanged()) { |
473 |
calcMetadataFromParams(); |
474 |
providerList = getParameters().getProviders(); |
475 |
try {
|
476 |
histogram = SimpleProviderHistogramComputer.union(this, providerList);
|
477 |
} catch (HistogramException e) {
|
478 |
return null; |
479 |
} catch (InterruptedException e) { |
480 |
return null; |
481 |
} |
482 |
} |
483 |
return histogram;
|
484 |
} |
485 |
|
486 |
public String getURIOfFirstProvider() { |
487 |
return providerList.get(0).getURIOfFirstProvider(); |
488 |
} |
489 |
|
490 |
public long getFileSize() { |
491 |
if(getParameters().hasParamsChanged())
|
492 |
calcMetadataFromParams(); |
493 |
long sizeMosaic = 0; |
494 |
for (int i = 0; i < providerList.size(); i++) { |
495 |
long[] fs = providerList.get(i).getFileSizeByProvider(); |
496 |
for (int j = 0; j < fs.length; j++) { |
497 |
sizeMosaic += fs[j]; |
498 |
} |
499 |
} |
500 |
return sizeMosaic;
|
501 |
} |
502 |
|
503 |
public IProjection getProjection() {
|
504 |
return proj;
|
505 |
} |
506 |
|
507 |
public void setProjection(IProjection p) { |
508 |
} |
509 |
|
510 |
public String getInfoByPoint(double x, double y, ICancellable cancellable) { |
511 |
return null; |
512 |
} |
513 |
|
514 |
public int[] getTileSize(int level) { |
515 |
return null; |
516 |
} |
517 |
|
518 |
public int getSourceType() { |
519 |
return RasterDataStore.MOSAIC;
|
520 |
} |
521 |
|
522 |
public String translateFileName(String fileName) { |
523 |
return fileName;
|
524 |
} |
525 |
|
526 |
public void setView(Extent e) { |
527 |
viewRequest = new ExtentImpl(e);
|
528 |
} |
529 |
|
530 |
public Extent getView() {
|
531 |
return viewRequest;
|
532 |
} |
533 |
|
534 |
public double getWidth() { |
535 |
if(getParameters().hasParamsChanged())
|
536 |
calcMetadataFromParams(); |
537 |
return width;
|
538 |
} |
539 |
|
540 |
public double getHeight() { |
541 |
if(getParameters().hasParamsChanged())
|
542 |
calcMetadataFromParams(); |
543 |
return height;
|
544 |
} |
545 |
|
546 |
public Object readBlock(int pos, int blockHeight, double scale) |
547 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
|
548 |
if(getParameters().hasParamsChanged())
|
549 |
calcMetadataFromParams(); |
550 |
blockHeight = pos + blockHeight > getHeight() ? (int)(getHeight() - pos) : blockHeight;
|
551 |
Buffer buf = RasterLocator.getManager().createBuffer(getDataType()[0], (int)getWidth(), blockHeight, getBandCount(), true); |
552 |
BandList bandList = new BandListImpl();
|
553 |
bandList.clear(); |
554 |
int[] drawableBands = new int[getBandCount()]; |
555 |
for(int i = 0; i < getBandCount(); i++) { |
556 |
try {
|
557 |
int dataType = getDataType()[i];
|
558 |
DatasetBand band = new DatasetBandImpl(getURIByBand(i),
|
559 |
getBandPositionByProvider(i), |
560 |
dataType, |
561 |
getBandCount()); |
562 |
bandList.addBand(band, i); |
563 |
drawableBands[i] = i; |
564 |
} catch(BandNotFoundInListException ex) {
|
565 |
//No a๏ฟฝadimos la banda
|
566 |
} |
567 |
} |
568 |
bandList.setDrawableBands(drawableBands); |
569 |
return getWindow(0, pos, bandList, buf); |
570 |
} |
571 |
|
572 |
public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
573 |
if(getParameters().hasParamsChanged())
|
574 |
calcMetadataFromParams(); |
575 |
return null; |
576 |
} |
577 |
|
578 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
579 |
BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
|
580 |
if(getParameters().hasParamsChanged())
|
581 |
calcMetadataFromParams(); |
582 |
setView(extent); |
583 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection());
|
584 |
List<Tile> tileList = null; |
585 |
try {
|
586 |
tileList = getTileList(extent, bandList, bufWidth, bufHeight, layerName); |
587 |
tiledLayer.getTiles(tileList, listener, status); |
588 |
} catch (TileGettingException e) {
|
589 |
throw new RasterDriverException("Error getting the tile list", e); |
590 |
} catch (TileBuildException e) {
|
591 |
throw new RasterDriverException("Error building the tile list", e); |
592 |
} |
593 |
} |
594 |
|
595 |
public Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status) |
596 |
throws ProcessInterruptedException, RasterDriverException {
|
597 |
if(getParameters().hasParamsChanged())
|
598 |
calcMetadataFromParams(); |
599 |
setView(extent); |
600 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection());
|
601 |
List<Tile> tileList = null; |
602 |
try {
|
603 |
tileList = getTileList(extent, bandList, rasterBuf.getWidth(), rasterBuf.getHeight(), layerName); |
604 |
for (int i = 0; i < tileList.size(); i++) { |
605 |
tiledLayer.getTile(tileList.get(i)); |
606 |
} |
607 |
} catch (TileGettingException e) {
|
608 |
throw new RasterDriverException("Error getting the tile list", e); |
609 |
} catch (TileBuildException e) {
|
610 |
throw new RasterDriverException("Error building the tile list", e); |
611 |
} |
612 |
MemoryMatrixBuffer matrixBuffer = new MemoryMatrixBuffer(tileList);
|
613 |
|
614 |
if( tileList.get(0).getData().length > 1 && |
615 |
getDataType()[0] == Buffer.TYPE_BYTE && |
616 |
rasterBuf.getBandCount() == 1 &&
|
617 |
bandList.getDrawableBands()[0] == getBandCount())
|
618 |
return matrixBuffer.getWindow(extent, rasterBuf, true); |
619 |
else
|
620 |
return matrixBuffer.getWindow(extent, rasterBuf, false); |
621 |
} |
622 |
|
623 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
624 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
625 |
//cut image
|
626 |
if(getParameters().hasParamsChanged())
|
627 |
calcMetadataFromParams(); |
628 |
Extent ext = getExtent(); |
629 |
Point2D pInit = rasterToWorld(new Point2D.Double(0, 0)); |
630 |
Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight())); |
631 |
double wRaster = Math.abs(pEnd.getX() - pInit.getX()); |
632 |
double hRaster = Math.abs(pEnd.getY() - pInit.getY()); |
633 |
double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w);
|
634 |
double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h);
|
635 |
|
636 |
Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry);
|
637 |
setView(selectedExtent); |
638 |
return getWindow(selectedExtent,
|
639 |
rasterBuf.getWidth(), rasterBuf.getHeight(), bandList, rasterBuf, false, status);
|
640 |
} |
641 |
|
642 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
643 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
644 |
//draw method
|
645 |
if(getParameters().hasParamsChanged())
|
646 |
calcMetadataFromParams(); |
647 |
setView(extent); |
648 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection());
|
649 |
List<Tile> tileList = null; |
650 |
try {
|
651 |
tileList = getTileList(extent, bandList, bufWidth, bufHeight, layerName); |
652 |
for (int i = 0; i < tileList.size(); i++) { |
653 |
tiledLayer.getTile(tileList.get(i)); |
654 |
} |
655 |
} catch (TileGettingException e) {
|
656 |
throw new RasterDriverException("Error getting the tile list", e); |
657 |
} catch (TileBuildException e) {
|
658 |
throw new RasterDriverException("Error building the tile list", e); |
659 |
} |
660 |
MemoryMatrixBuffer matrixBuffer = new MemoryMatrixBuffer(tileList);
|
661 |
|
662 |
if( tileList.get(0).getData().length > 1 && |
663 |
getDataType()[0] == Buffer.TYPE_BYTE && |
664 |
rasterBuf.getBandCount() == 1 &&
|
665 |
bandList.getDrawableBands()[0] == getBandCount())
|
666 |
return matrixBuffer.getWindow(extent, rasterBuf, true); |
667 |
else
|
668 |
return matrixBuffer.getWindow(extent, rasterBuf, false); |
669 |
} |
670 |
|
671 |
public Buffer getWindow(int x, int y, |
672 |
BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
673 |
//Layer with real resolution
|
674 |
if(getParameters().hasParamsChanged())
|
675 |
calcMetadataFromParams(); |
676 |
int w = rasterBuf.getWidth();
|
677 |
int h = rasterBuf.getHeight();
|
678 |
Rectangle2D r = new Rectangle2D.Double(x, y, w, h); |
679 |
setView( |
680 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
|
681 |
getWidth(), |
682 |
getHeight(), |
683 |
r)) |
684 |
); |
685 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection());
|
686 |
|
687 |
CacheStruct struct = getTileServer(layerName).getStruct(); |
688 |
|
689 |
createTiledLayer(layerName); //Creates a new layer when the file type changes
|
690 |
|
691 |
List<Tile> tileList = struct.getTileList(r);
|
692 |
|
693 |
for (int i = 0; i < tileList.size(); i++) { |
694 |
tileList.get(i).setDownloaderParams("BandList", bandList.clone());
|
695 |
} |
696 |
|
697 |
try {
|
698 |
for (int i = 0; i < tileList.size(); i++) { |
699 |
tiledLayer.getTile(tileList.get(i)); |
700 |
} |
701 |
} catch (TileGettingException e) {
|
702 |
throw new RasterDriverException("Error getting the tile list", e); |
703 |
} |
704 |
|
705 |
MemoryMatrixBuffer matrixBuffer = new MemoryMatrixBuffer(tileList);
|
706 |
return matrixBuffer.getWindow(r, rasterBuf);
|
707 |
} |
708 |
|
709 |
public Buffer getWindow(int x, int y, int w, int h, |
710 |
BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
711 |
if(rasterBuf.getWidth() == w && rasterBuf.getHeight() == h)
|
712 |
return getWindow(x, y, bandList, rasterBuf);
|
713 |
|
714 |
if(getParameters().hasParamsChanged())
|
715 |
calcMetadataFromParams(); |
716 |
setView( |
717 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
|
718 |
getWidth(), |
719 |
getHeight(), |
720 |
new Rectangle2D.Double(x, y, w, h))) |
721 |
); |
722 |
return null; |
723 |
} |
724 |
|
725 |
public int getBlockSize() { |
726 |
return 0; |
727 |
} |
728 |
|
729 |
public boolean isTiled() { |
730 |
return false; |
731 |
} |
732 |
|
733 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
734 |
return 0; |
735 |
} |
736 |
|
737 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
738 |
return 0; |
739 |
} |
740 |
|
741 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
742 |
return 0; |
743 |
} |
744 |
|
745 |
public boolean isOverviewsSupported() { |
746 |
return false; |
747 |
} |
748 |
|
749 |
public boolean isReproyectable() { |
750 |
return false; |
751 |
} |
752 |
|
753 |
public String getName() { |
754 |
return NAME;
|
755 |
} |
756 |
|
757 |
public void setStatus(RasterProvider provider) { |
758 |
if(provider instanceof MosaicProvider) { |
759 |
} |
760 |
} |
761 |
|
762 |
public boolean isTimeSupported() { |
763 |
return true; |
764 |
} |
765 |
|
766 |
public boolean isMosaic() { |
767 |
return true; |
768 |
} |
769 |
|
770 |
public void deleteLayerFromCache() { |
771 |
String layerName = getLayerNameFromSelection(null); |
772 |
TileCacheManager manager = TileCacheLocator.getManager(); |
773 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
774 |
TiledLayer newLayer = tileCache.createLayer(getTileServer(layerName), TileCacheLibrary.DEFAULT_STRUCTURE); |
775 |
tileCache.removeLayer(newLayer); |
776 |
} |
777 |
|
778 |
/**
|
779 |
* Gets the layer name using the time selection and visibility
|
780 |
* @param t
|
781 |
* @return
|
782 |
*/
|
783 |
private String getLayerNameFromSelection(Time t) { |
784 |
String name = ""; |
785 |
|
786 |
MessageDigest md = null; |
787 |
try {
|
788 |
md = java.security.MessageDigest.getInstance("MD5");
|
789 |
} catch (NoSuchAlgorithmException e) { |
790 |
} |
791 |
|
792 |
//Without time selected
|
793 |
if(t == null || selectedProviders.size() != providerList.size()) { |
794 |
selectedProviders.clear(); |
795 |
for (int i = 0; i < providerList.size(); i++) { |
796 |
RasterProvider prov = providerList.get(i); |
797 |
selectedProviders.add(prov); |
798 |
if(!((RasterDataParameters)prov.getDataParameters()).isVisible())
|
799 |
name += prov.getURI().substring(prov.getURI().lastIndexOf(File.separator) + 1, prov.getURI().length()); |
800 |
} |
801 |
} else {
|
802 |
selectedProviders.clear(); |
803 |
for (int i = 0; i < providerList.size(); i++) { |
804 |
try {
|
805 |
TimeSeries tSeries = providerList.get(i).getTimeSerials(); |
806 |
ArrayList<?> tList = tSeries.getTimeList();
|
807 |
for (int j = 0; j < tList.size(); j++) { |
808 |
Object obj = tList.get(i);
|
809 |
RelativeInstant instant = null;
|
810 |
if(obj instanceof Date) { |
811 |
Date s = (Date)obj; |
812 |
instant = TimeSupportLocator.getManager().createRelativeInstant(s); |
813 |
} |
814 |
if(obj instanceof Double) { |
815 |
long s = ((Double)obj).longValue(); |
816 |
instant = TimeSupportLocator.getManager().createRelativeInstant(s); |
817 |
} |
818 |
if( instant != null && |
819 |
t.intersects(instant) && |
820 |
!selectedProviders.contains(providerList.get(i))) { |
821 |
RasterProvider prov = providerList.get(i); |
822 |
selectedProviders.add(prov); |
823 |
if(!((RasterDataParameters)prov.getDataParameters()).isVisible())
|
824 |
name += prov.getURI().substring(prov.getURI().lastIndexOf(File.separator) + 1, prov.getURI().length()); |
825 |
} |
826 |
} |
827 |
} catch (RmfSerializerException e) {
|
828 |
logger.debug("Error reading rmf time serials", e);
|
829 |
} |
830 |
} |
831 |
} |
832 |
|
833 |
if(md != null) { |
834 |
md.update(name.getBytes()); |
835 |
return math.convertToHex(md.digest());
|
836 |
} else {
|
837 |
return name;
|
838 |
} |
839 |
} |
840 |
|
841 |
/**
|
842 |
* Creates a new tiled layer if this hasn't been created yet or the ID has changed.
|
843 |
* An ID could changed because the file type has changed when the user uses WMTS properties.
|
844 |
*/
|
845 |
private TileCache createTiledLayer(String layerName) { |
846 |
TileCacheManager manager = TileCacheLocator.getManager(); |
847 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
848 |
TiledLayer newLayer = tileCache.createLayer(getTileServer(layerName), TileCacheLibrary.DEFAULT_STRUCTURE); |
849 |
if(tiledLayer == null || newLayer.getID().compareTo(tiledLayer.getID()) != 0) |
850 |
tiledLayer = newLayer; |
851 |
return tileCache;
|
852 |
} |
853 |
|
854 |
/**
|
855 |
* Gets the tile list in a selected extent
|
856 |
* @param ex
|
857 |
* @param bandList
|
858 |
* @param bufWidth
|
859 |
* @param bufHeight
|
860 |
* @return
|
861 |
* @throws TileBuildException
|
862 |
*/
|
863 |
private List<Tile> getTileList(Extent ex, BandList bandList, int bufWidth, int bufHeight, String layerName) throws TileBuildException { |
864 |
CacheStruct struct = getTileServer(layerName).getStruct(); |
865 |
|
866 |
createTiledLayer(layerName); //Creates a new layer when the file type changes
|
867 |
|
868 |
Extent adjustedExtent = util.intersection(getExtent(), ex); |
869 |
double newBufWidth = (adjustedExtent.width() * bufWidth) / ex.width();
|
870 |
double pixelSizeRequest = adjustedExtent.width() / newBufWidth;
|
871 |
|
872 |
List<Tile> tileList = struct.getTileList(new Point2D.Double(adjustedExtent.getULX(), adjustedExtent.getULY()), |
873 |
new Point2D.Double(adjustedExtent.getLRX(), adjustedExtent.getLRY()), |
874 |
pixelSizeRequest); |
875 |
|
876 |
for (int i = 0; i < tileList.size(); i++) { |
877 |
tileList.get(i).setDownloaderParams("BandList", bandList.clone());
|
878 |
} |
879 |
return tileList;
|
880 |
} |
881 |
|
882 |
public TileServer getTileServer() {
|
883 |
return null; |
884 |
} |
885 |
|
886 |
/**
|
887 |
* Gets the tile server from the Hashmap
|
888 |
* @param layerName
|
889 |
* @return
|
890 |
*/
|
891 |
public TileServer getTileServer(String layerName) { |
892 |
MosaicTileServer tileServer = tileServerMap.get(layerName); |
893 |
if(tileServer == null) { |
894 |
tileServer = new MosaicTileServer(this, |
895 |
providerList, |
896 |
layerName, |
897 |
getParameters().getOverlapMethod(), |
898 |
getParameters().getColorCorrectionMethod(), |
899 |
getNoDataValue()); |
900 |
tileServerMap.put(layerName, tileServer); |
901 |
} |
902 |
return tileServer;
|
903 |
} |
904 |
} |