gvsig-raster / org.gvsig.raster.tilecache / trunk / org.gvsig.raster.tilecache / org.gvsig.raster.tilecache.io / src / main / java / org / gvsig / raster / tilecache / io / TileProvider.java @ 966
History | View | Annotate | Download (37.5 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.tilecache.io; |
23 |
|
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.NoninvertibleTransformException; |
26 |
import java.awt.geom.Point2D; |
27 |
import java.io.File; |
28 |
import java.io.FileNotFoundException; |
29 |
import java.io.IOException; |
30 |
import java.lang.reflect.Constructor; |
31 |
import java.lang.reflect.InvocationTargetException; |
32 |
import java.util.ArrayList; |
33 |
|
34 |
import org.gvsig.compat.net.ICancellable; |
35 |
import org.gvsig.fmap.dal.DALFileLocator; |
36 |
import org.gvsig.fmap.dal.DALLocator; |
37 |
import org.gvsig.fmap.dal.DataStore; |
38 |
import org.gvsig.fmap.dal.DataStoreParameters; |
39 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
40 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
41 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
42 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
43 |
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand; |
44 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
45 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException; |
47 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
48 |
import org.gvsig.fmap.dal.coverage.exception.FileNotSupportedException; |
49 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
50 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
51 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
52 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
53 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
54 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
55 |
import org.gvsig.fmap.dal.coverage.store.parameter.MultiDimensionalStoreParameters; |
56 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
57 |
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
58 |
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
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.Transparency; |
62 |
import org.gvsig.fmap.dal.coverage.util.MathUtils; |
63 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
64 |
import org.gvsig.fmap.dal.exception.InitializeException; |
65 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
66 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
67 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
68 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
69 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
70 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
71 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
72 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
73 |
import org.gvsig.metadata.MetadataLocator; |
74 |
import org.gvsig.raster.cache.tile.Tile; |
75 |
import org.gvsig.raster.cache.tile.TileCache; |
76 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
77 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
78 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
79 |
import org.gvsig.raster.cache.tile.exception.TileBuildException; |
80 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
81 |
import org.gvsig.raster.cache.tile.layer.TiledLayer; |
82 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
83 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
84 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
85 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
86 |
import org.gvsig.raster.impl.datastruct.DatasetBandImpl; |
87 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
88 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
89 |
import org.gvsig.raster.impl.provider.MemoryMatrixBuffer; |
90 |
import org.gvsig.raster.impl.provider.RasterProvider; |
91 |
import org.gvsig.raster.impl.provider.RemoteRasterProvider; |
92 |
import org.gvsig.raster.impl.provider.TiledRasterProvider; |
93 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
94 |
import org.gvsig.raster.impl.store.properties.RemoteDataStoreStatistics; |
95 |
import org.gvsig.tools.ToolsLocator; |
96 |
import org.gvsig.tools.locator.LocatorException; |
97 |
import org.slf4j.Logger; |
98 |
import org.slf4j.LoggerFactory; |
99 |
|
100 |
/**
|
101 |
* Provider for WMTS service
|
102 |
*
|
103 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
104 |
*/
|
105 |
public class TileProvider extends DefaultRasterProvider implements TiledRasterProvider { |
106 |
public static String NAME = "Tile Store"; |
107 |
public static String DESCRIPTION = "Raster Tiled Source"; |
108 |
public static final String METADATA_DEFINITION_NAME = "TileStore"; |
109 |
private static final Logger logger = LoggerFactory.getLogger(TileProvider.class); |
110 |
private RasterProvider provider = null; |
111 |
private boolean open = false; |
112 |
private Extent viewRequest = null; |
113 |
private TiledLayer tiledLayer = null; |
114 |
private RasterUtils util = RasterLocator.getManager().getRasterUtils();
|
115 |
private MathUtils math = RasterLocator.getManager().getMathUtils();
|
116 |
private TileServer secondLevelTileServer = null; |
117 |
|
118 |
public static void register() { |
119 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
120 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
121 |
dataman.registerStoreProvider(NAME, |
122 |
TileProvider.class, TileDataParametersImpl.class); |
123 |
} |
124 |
|
125 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
126 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
127 |
NAME, DESCRIPTION, |
128 |
TileServerExplorer.class); |
129 |
|
130 |
if (!dataman.getExplorerProviders().contains(TileServerExplorer.NAME)) {
|
131 |
dataman.registerExplorerProvider(TileServerExplorer.NAME, TileServerExplorer.class, TileServerExplorerParameters.class); |
132 |
} |
133 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Loads the specific provider to download data
|
138 |
* @param file
|
139 |
* @return
|
140 |
* @throws NotSupportedExtensionException
|
141 |
* @throws FileNotSupportedException
|
142 |
*/
|
143 |
private RasterProvider loadProvider(TileDataParametersImpl params, DataStoreProviderServices storeServices) throws ProviderNotRegisteredException, InitializeException { |
144 |
Object obj = params.getDataParameters();
|
145 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
146 |
DataStoreProvider prov = null;
|
147 |
|
148 |
if(obj != null && obj instanceof DataStoreParameters) //Remote |
149 |
prov = dataManager.createProvider(storeServices, (DataStoreParameters)obj); |
150 |
else { //File |
151 |
if(params.getFile() != null) { |
152 |
//We have to locate a provider's name which manages the selected file
|
153 |
//A FilesystemServerExplorer will give a getProviderNames service
|
154 |
FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
155 |
FilesystemServerExplorer serverExplorer = null;
|
156 |
try {
|
157 |
paramsExplorer.setRoot(File.separator);
|
158 |
serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer); |
159 |
} catch (ValidateDataParametersException e) {
|
160 |
throw new InitializeException(e); |
161 |
} |
162 |
|
163 |
//Gets the list of provider's name to manage the file
|
164 |
ArrayList<String> provName = serverExplorer.getProviderNameList(params.getFile()); |
165 |
if(provName.size() > 0) { |
166 |
for (int i = 0; i < provName.size(); i++) { |
167 |
//Gets the first provider what is not a TileProvider
|
168 |
if(provName.get(i).compareTo(NAME) != 0) { |
169 |
DataStoreParameters newparams = dataManager.createStoreParameters(provName.get(i)); |
170 |
((FilesystemStoreParameters)newparams).setFile(params.getFile()); |
171 |
prov = dataManager.createProvider(storeServices, newparams); |
172 |
} |
173 |
} |
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
if(prov != null && prov instanceof RasterProvider) { |
179 |
if(((RasterProvider)prov).isRotated())
|
180 |
throw new InitializeException("Rotation not supported tiling files", new Throwable()); |
181 |
|
182 |
return (RasterProvider)prov;
|
183 |
} |
184 |
|
185 |
return null; |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Gets the internal provider used to feed the TileProvider
|
190 |
* @return
|
191 |
*/
|
192 |
public RasterProvider getInternalProvider() {
|
193 |
return provider;
|
194 |
} |
195 |
|
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getFileSuffix()
|
199 |
*/
|
200 |
public String getFileSuffix() { |
201 |
try {
|
202 |
return provider instanceof RemoteRasterProvider ? provider.getFileSuffix() : "tif"; |
203 |
} catch(Throwable e) { |
204 |
//if wmts doesn't exists in the classpath
|
205 |
return "tif"; |
206 |
} |
207 |
} |
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getRMFFile()
|
212 |
*/
|
213 |
public String getRMFFile() { |
214 |
TileCacheManager manager = TileCacheLocator.getManager(); |
215 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
216 |
|
217 |
String path = tiledLayer.getBaseLayerDirectory().substring(0, tiledLayer.getBaseLayerDirectory().lastIndexOf(File.separator) + 1) + |
218 |
tileCache.getConfigurationDirectory() + File.separator +
|
219 |
tiledLayer.getID() + ".rmf";
|
220 |
|
221 |
try {
|
222 |
if(!new File(path).exists() && |
223 |
provider != null &&
|
224 |
provider.getRMFFile() != null &&
|
225 |
new File(provider.getRMFFile()).exists()) |
226 |
RasterLocator.getManager().getFileUtils().copyFile(provider.getRMFFile(), path); |
227 |
|
228 |
if(provider != null && provider.getColorTable() != null) { |
229 |
ColorTable colorTable = provider.getColorTable(); |
230 |
RasterLocator.getManager().getProviderServices().saveObjectToRmfFile(path, ColorTable.class, colorTable); |
231 |
} |
232 |
} catch (LocatorException e) {
|
233 |
logger.info("No se ha podido copiar el fichero RMF a la capa tileada", e);
|
234 |
} catch (FileNotFoundException e) { |
235 |
logger.info("No se ha podido copiar el fichero RMF a la capa tileada", e);
|
236 |
} catch (IOException e) { |
237 |
logger.info("No se ha podido copiar el fichero RMF a la capa tileada", e);
|
238 |
} catch (RmfSerializerException e) {
|
239 |
logger.info("No se ha podido copiar la tabla de color a la capa tileada", e);
|
240 |
} |
241 |
return path;
|
242 |
} |
243 |
|
244 |
public TileProvider() throws NotSupportedExtensionException { |
245 |
super();
|
246 |
} |
247 |
|
248 |
/*
|
249 |
* (non-Javadoc)
|
250 |
* @see org.gvsig.raster.impl.provider.RasterProvider#registerTileProviderFormats(java.lang.Class)
|
251 |
*/
|
252 |
public void registerTileProviderFormats(Class<RasterProvider> c) { |
253 |
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* Assigns the provider associated to this tile server
|
258 |
* @param prov
|
259 |
* @throws NotSupportedExtensionException
|
260 |
*/
|
261 |
public void setProvider(RasterProvider prov) throws NotSupportedExtensionException { |
262 |
this.provider = prov;
|
263 |
init(getDataStoreParameters(), getStoreServices()); |
264 |
} |
265 |
|
266 |
public TileProvider(TileDataParametersImpl params,
|
267 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, FileNotSupportedException {
|
268 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
269 |
.createDynObject( |
270 |
MetadataLocator.getMetadataManager().getDefinition( |
271 |
DataStore.METADATA_DEFINITION_NAME))); |
272 |
if(!params.isSecondLevelCache()) {
|
273 |
try {
|
274 |
provider = loadProvider(params, storeServices); |
275 |
} catch (ProviderNotRegisteredException e) {
|
276 |
throw new FileNotSupportedException("Provider not registered", e); |
277 |
} catch (InitializeException e) {
|
278 |
throw new FileNotSupportedException("Initialize exception", e); |
279 |
} |
280 |
init(params, storeServices); |
281 |
} |
282 |
} |
283 |
|
284 |
/**
|
285 |
* Creates the second level cache if the client has set a <code>TileServer</code> and the
|
286 |
* <code>CacheStruct</code> is different that the old one.
|
287 |
* <UL>
|
288 |
* <LI>First level cache without TileServer from the client: do nothing</LI>
|
289 |
* <LI>First level cache with TileServer from the client and the structure is
|
290 |
* different to the old one: Builds a second level TileProvider</LI>
|
291 |
* <LI>First level cache with TileServer from the client and the structure is
|
292 |
* equal to the old one: do nothing</LI>
|
293 |
* <LI>Second level cache: sets the TileServer</LI>
|
294 |
* </UL>
|
295 |
* @param params
|
296 |
* @param storeServices
|
297 |
* @throws NotSupportedExtensionException
|
298 |
*/
|
299 |
/*private void createsSecondLevelCache(TileDataParametersImpl params) throws NotSupportedExtensionException {
|
300 |
//Se obtiene el TileServer que haya pasado el cliente en los par?metros si ha pasado alguno.
|
301 |
TileServer tileServer = params.getTileServer();
|
302 |
//Se obtiene el CacheStruct y se compara con el del provider
|
303 |
CacheStruct cacheStruct = null;
|
304 |
if(tileServer != null)
|
305 |
cacheStruct = tileServer.getStruct();
|
306 |
|
307 |
if(params.isSecondLevelCache()) { //Cache de segundo nivel
|
308 |
this.secondLevelTileServer = tileServer;
|
309 |
} else if(cacheStruct != null && !provider.getTileServer().getStruct().compare(cacheStruct)) { //Cache de primer nivel
|
310 |
//Si son distintos habr? que crear una cach? de segundo nivel por lo que creamos un nuevo TileProvider
|
311 |
//que tenga como par?metro el provider viejo
|
312 |
TileDataParametersImpl par = new TileDataParametersImpl();
|
313 |
par.setDataParameters(provider.getDataParameters());
|
314 |
par.setTileServer(tileServer);
|
315 |
par.setSecondLevelCache(true);
|
316 |
TileProvider newProvider = new TileProvider(par, null);
|
317 |
newProvider.setProvider(this.provider);
|
318 |
//Al TileProvider actual se le asigna como provider el TileProvider creado
|
319 |
this.provider = newProvider;
|
320 |
}
|
321 |
}*/
|
322 |
|
323 |
/**
|
324 |
* Crea las referencias al fichero y carga
|
325 |
* las estructuras con la informaci?n y los metadatos.
|
326 |
* @param proj Proyecci?n
|
327 |
* @param param Parametros de carga
|
328 |
* @throws NotSupportedExtensionException
|
329 |
*/
|
330 |
public void init (DataStoreParameters params, |
331 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
332 |
setParam(storeServices, params); |
333 |
open = true;
|
334 |
setDataType(provider.getDataType()); |
335 |
bandCount = provider.getBandCount(); |
336 |
//if(getColorInterpretation() == null)
|
337 |
setColorInterpretation(provider.getColorInterpretation()); |
338 |
/*else
|
339 |
getColorInterpretation().addColorInterpretation(provider.getColorInterpretation());*/
|
340 |
setColorTable(provider.getColorTable()); |
341 |
noData = provider.getNoDataValue(); |
342 |
setFName(provider.getURIOfFirstProvider()); |
343 |
try {
|
344 |
wktProjection = provider.getWktProjection(); |
345 |
} catch (RasterDriverException e) {
|
346 |
} |
347 |
ownTransformation = provider.getAffineTransform(); |
348 |
externalTransformation = (AffineTransform)ownTransformation.clone();
|
349 |
|
350 |
createTiledLayer(); |
351 |
|
352 |
//Force to deletes the layer if the flag is to true
|
353 |
if(tiledLayer != null) { |
354 |
if(param instanceof TileDataParameters) { |
355 |
if(((TileDataParameters)param).isDeletingCache()) {
|
356 |
TileCacheManager manager = TileCacheLocator.getManager(); |
357 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
358 |
tileCache.removeLayer(tiledLayer); |
359 |
((TileDataParameters)param).deleteCache(false);
|
360 |
} |
361 |
} |
362 |
} |
363 |
|
364 |
if(provider instanceof RemoteRasterProvider) |
365 |
stats = new RemoteDataStoreStatistics(provider);
|
366 |
} |
367 |
|
368 |
/**
|
369 |
* Creates a new tiled layer if this hasn't been created yet or the ID has changed.
|
370 |
* An ID could changed because the file type has changed when the user uses WMTS properties.
|
371 |
*/
|
372 |
private void createTiledLayer() { |
373 |
TileCacheManager manager = TileCacheLocator.getManager(); |
374 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
375 |
TiledLayer newLayer = tileCache.createLayer(provider.getTileServer(), TileCacheLibrary.DEFAULT_STRUCTURE); |
376 |
if(tiledLayer == null || newLayer.getID().compareTo(tiledLayer.getID()) != 0) |
377 |
tiledLayer = newLayer; |
378 |
} |
379 |
|
380 |
/*
|
381 |
* (non-Javadoc)
|
382 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getZoomLevels()
|
383 |
*/
|
384 |
public int getZoomLevels() { |
385 |
if(provider.getTileServer() != null) |
386 |
return provider.getTileServer().getStruct().getNumberOfLevels();
|
387 |
return 0; |
388 |
} |
389 |
|
390 |
/*
|
391 |
* (non-Javadoc)
|
392 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getNearestLevel(double)
|
393 |
*/
|
394 |
public int getNearestLevel(double pixelSize) { |
395 |
double[] pixelSizes = getPixelSizeByLevel(); |
396 |
for (int i = 0; i < pixelSizes.length - 1; i++) { |
397 |
if(pixelSize <= pixelSizes[i] && pixelSize > pixelSizes[i + 1]) { |
398 |
return i;
|
399 |
} |
400 |
} |
401 |
if(pixelSize < pixelSizes[getZoomLevels() - 1]) |
402 |
return getZoomLevels() - 1; |
403 |
return 0; |
404 |
} |
405 |
|
406 |
/**
|
407 |
* Returns a list of pixel sizes by level
|
408 |
* @return
|
409 |
*/
|
410 |
public double[] getPixelSizeByLevel() { |
411 |
double[] list = new double[getZoomLevels()]; |
412 |
CacheStruct struct = provider.getTileServer().getStruct(); |
413 |
for (int i = 0; i < struct.getNumberOfLevels(); i++) { |
414 |
list[i] = math.adjustDouble(struct.getPixelSizeByLevel(i)); |
415 |
} |
416 |
return list;
|
417 |
} |
418 |
|
419 |
/*
|
420 |
* (non-Javadoc)
|
421 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getCoordsInTheNearestLevel(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int)
|
422 |
*/
|
423 |
public Extent getCoordsInTheNearestLevel(Extent extent, int w, int h) { |
424 |
double[] pixelSizes = getPixelSizeByLevel(); |
425 |
double currentPixelSize = extent.width() / (double)w; |
426 |
|
427 |
int level = 0; |
428 |
for (int i = 0; i < (pixelSizes.length - 1); i++) { |
429 |
if(currentPixelSize < pixelSizes[i] && currentPixelSize >= pixelSizes[i + 1]) { |
430 |
level = i + 1;
|
431 |
break;
|
432 |
} |
433 |
} |
434 |
|
435 |
return getZoomLevelCoordinates(level, extent, w, h);
|
436 |
} |
437 |
|
438 |
/*
|
439 |
* (non-Javadoc)
|
440 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getCoordsInLevel(java.awt.geom.Point2D, int, int, int)
|
441 |
*/
|
442 |
public Extent getCoordsInLevel(Point2D viewCenter, int level, int w, int h) { |
443 |
level = adjustLevel(level); |
444 |
double pixelSize = provider.getTileServer().getStruct().getPixelSizeByLevel(level);
|
445 |
|
446 |
double ulx = viewCenter.getX() - ((w / 2) * pixelSize); |
447 |
double uly = viewCenter.getY() - ((h / 2) * pixelSize); |
448 |
double lrx = ulx + (w * pixelSize);
|
449 |
double lry = uly + (h * pixelSize);
|
450 |
return new ExtentImpl(ulx, uly, lrx, lry); |
451 |
} |
452 |
|
453 |
/**
|
454 |
* Adjust de level to the range
|
455 |
* @param level
|
456 |
* @return
|
457 |
*/
|
458 |
private int adjustLevel(int level) { |
459 |
if(level < 0) |
460 |
level = 0;
|
461 |
if(level > getZoomLevels())
|
462 |
level = getZoomLevels(); |
463 |
return level;
|
464 |
} |
465 |
|
466 |
/*
|
467 |
* (non-Javadoc)
|
468 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform()
|
469 |
*/
|
470 |
public AffineTransform getAffineTransform() { |
471 |
return provider.getAffineTransform();
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* Obtiene el objeto que contiene el estado de la transparencia
|
476 |
*/
|
477 |
public Transparency getTransparency() { |
478 |
return provider.getTransparency();
|
479 |
} |
480 |
|
481 |
/**
|
482 |
* Gets the bounding box in world coordinates. If the layer has grid subsets (TileMatrixLimits) then
|
483 |
* this will have a only extent but if the layer doesn't have grid subsets then this will have a different
|
484 |
* extent in each level resolution. In this case we need to know the extent for each level.
|
485 |
* @return Extent
|
486 |
*/
|
487 |
public Extent getExtent() {
|
488 |
return provider.getExtent();
|
489 |
} |
490 |
|
491 |
/*
|
492 |
* (non-Javadoc)
|
493 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load()
|
494 |
*/
|
495 |
public RasterProvider load() {
|
496 |
return this; |
497 |
} |
498 |
|
499 |
/*
|
500 |
* (non-Javadoc)
|
501 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
|
502 |
*/
|
503 |
public boolean isOpen() { |
504 |
return open;
|
505 |
} |
506 |
|
507 |
/*
|
508 |
* (non-Javadoc)
|
509 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isTiled()
|
510 |
*/
|
511 |
public boolean isTiled() { |
512 |
return true; |
513 |
} |
514 |
|
515 |
/*
|
516 |
* (non-Javadoc)
|
517 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
|
518 |
*/
|
519 |
public void close() { |
520 |
open = false;
|
521 |
} |
522 |
|
523 |
/*
|
524 |
* (non-Javadoc)
|
525 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String)
|
526 |
*/
|
527 |
public String translateFileName(String fileName) { |
528 |
return fileName;
|
529 |
} |
530 |
|
531 |
/*
|
532 |
* (non-Javadoc)
|
533 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setView(org.gvsig.fmap.dal.coverage.datastruct.Extent)
|
534 |
*/
|
535 |
public void setView(Extent e) { |
536 |
viewRequest = e; |
537 |
} |
538 |
|
539 |
/*
|
540 |
* (non-Javadoc)
|
541 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
|
542 |
*/
|
543 |
public Extent getView() {
|
544 |
return viewRequest;
|
545 |
} |
546 |
|
547 |
/*
|
548 |
* (non-Javadoc)
|
549 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
|
550 |
*/
|
551 |
public double getWidth() { |
552 |
return provider.getWidth();
|
553 |
} |
554 |
|
555 |
/*
|
556 |
* (non-Javadoc)
|
557 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
|
558 |
*/
|
559 |
public double getHeight() { |
560 |
return provider.getHeight();
|
561 |
} |
562 |
|
563 |
/*
|
564 |
* (non-Javadoc)
|
565 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#readCompleteLine(int, int)
|
566 |
*/
|
567 |
public Object readCompleteLine(int line, int band) |
568 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
|
569 |
return null; |
570 |
} |
571 |
|
572 |
/**
|
573 |
* When the remote layer has fixed size this method downloads the file and return its reference.
|
574 |
* File layer has in the long side FIXED_SIZE pixels and the bounding box is complete. This file could be
|
575 |
* useful to build an histogram or calculate statistics. This represents a sample of data.
|
576 |
* @return
|
577 |
* @throws RasterDriverException
|
578 |
*/
|
579 |
public File getFileLayer() throws RasterDriverException { |
580 |
return null; |
581 |
} |
582 |
|
583 |
/**
|
584 |
* Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
|
585 |
* to read a file very fast without setting a view. In a Web Map Service when the size is fixed then it will read the
|
586 |
* entire image but when the source hasn't pixel size it will read a sample of data. This set of data will have
|
587 |
* the size defined in FIXED_SIZE.
|
588 |
*
|
589 |
* @param pos Posici?n donde se empieza a leer
|
590 |
* @param blockHeight Altura m?xima del bloque leido
|
591 |
* @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
|
592 |
* @throws InvalidSetViewException
|
593 |
* @throws FileNotOpenException
|
594 |
* @throws RasterDriverException
|
595 |
*/
|
596 |
public Object readBlock(int pos, int blockHeight, double scale) |
597 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
|
598 |
return provider.readBlock(pos, blockHeight, scale);
|
599 |
} |
600 |
|
601 |
/*
|
602 |
* (non-Javadoc)
|
603 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
|
604 |
*/
|
605 |
public Object getData(int x, int y, int band) |
606 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
|
607 |
return provider.getData(x, y, band);
|
608 |
} |
609 |
|
610 |
/**
|
611 |
* Assigns the list of bands RGB and read a window of data
|
612 |
* @param rasterBuf
|
613 |
* @param bandList
|
614 |
* @param lastFile
|
615 |
* @param ulx
|
616 |
* @param uly
|
617 |
* @param lrx
|
618 |
* @param lry
|
619 |
* @return
|
620 |
* @throws RasterDriverException
|
621 |
* @throws ProcessInterruptedException
|
622 |
*/
|
623 |
public Buffer getBuffer(Buffer rasterBuf, BandList bandList, File lastFile, |
624 |
double ulx, double uly, double lrx, double lry) throws RasterDriverException, ProcessInterruptedException { |
625 |
return null; |
626 |
} |
627 |
|
628 |
/**
|
629 |
* Calculates the extent of a zoom level using other extent as a reference. The new extent is
|
630 |
* calculated with the same coordinate at the center.
|
631 |
* @param level
|
632 |
* @param extent
|
633 |
* @param w
|
634 |
* @param h
|
635 |
* @return
|
636 |
*/
|
637 |
public Extent getZoomLevelCoordinates(int level, Extent extent, int w, int h) { |
638 |
double centerX = extent.getCenterX();
|
639 |
double centerY = extent.getCenterY();
|
640 |
return getCoordsInLevel(new Point2D.Double(centerX, centerY), level, w, h); |
641 |
} |
642 |
|
643 |
/**
|
644 |
* Gets the tile list in a selected extent
|
645 |
* @param ex
|
646 |
* @param bandList
|
647 |
* @param bufWidth
|
648 |
* @param bufHeight
|
649 |
* @return
|
650 |
* @throws TileBuildException
|
651 |
*/
|
652 |
private ArrayList<Tile> getTileList(Extent ex, BandList bandList, int bufWidth, int bufHeight) throws TileBuildException { |
653 |
TileServer tileServer = provider.getTileServer(); |
654 |
CacheStruct struct = tileServer.getStruct(); |
655 |
tileServer.setFileSuffix(getFileSuffix()); |
656 |
|
657 |
createTiledLayer(); //Creates a new layer when the file type changes
|
658 |
|
659 |
Extent adjustedExtent = util.intersection(provider.getExtent(), ex); |
660 |
double newBufWidth = (adjustedExtent.width() * bufWidth) / ex.width();
|
661 |
double pixelSizeRequest = adjustedExtent.width() / newBufWidth;
|
662 |
|
663 |
ArrayList<Tile> tileList = struct.getTileList(new Point2D.Double(adjustedExtent.getULX(), adjustedExtent.getULY()), |
664 |
new Point2D.Double(adjustedExtent.getLRX(), adjustedExtent.getLRY()), |
665 |
pixelSizeRequest); |
666 |
|
667 |
for (int i = 0; i < tileList.size(); i++) { |
668 |
loadTileTimeParameters(tileList.get(i)); |
669 |
} |
670 |
|
671 |
for (int i = 0; i < tileList.size(); i++) { |
672 |
tileList.get(i).setDownloaderParams("BandList", bandList.clone());
|
673 |
} |
674 |
return tileList;
|
675 |
} |
676 |
|
677 |
/**
|
678 |
* Loads the multidimensional parameters in a tile
|
679 |
* @param tile
|
680 |
*/
|
681 |
private void loadTileTimeParameters(Tile tile) { |
682 |
if(provider.getDataParameters() instanceof MultiDimensionalStoreParameters) { |
683 |
MultiDimensionalStoreParameters par = (MultiDimensionalStoreParameters)provider.getDataParameters(); |
684 |
tile.setVariable(par.getStringVariable()); |
685 |
tile.setZ(par.getStringLevel()); |
686 |
tile.setTimeInstant(par.getStringTime()); |
687 |
} |
688 |
} |
689 |
|
690 |
/*
|
691 |
* (non-Javadoc)
|
692 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#needEnhanced()
|
693 |
*/
|
694 |
public boolean needEnhanced() { |
695 |
return provider.needEnhanced();
|
696 |
} |
697 |
|
698 |
/*
|
699 |
* (non-Javadoc)
|
700 |
* @see org.gvsig.raster.impl.provider.TiledRasterProvider#getTile(int, int, int, org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.raster.cache.tile.provider.CacheStruct)
|
701 |
*/
|
702 |
public Tile getTile(int level, int tileCol, int tileRow, Extent ex, CacheStruct cacheStruct) throws TileGettingException { |
703 |
if(cacheStruct == null) |
704 |
cacheStruct = provider.getTileServer().getStruct(); |
705 |
else
|
706 |
provider.getTileServer().setStruct(cacheStruct); |
707 |
|
708 |
Tile tile = null;
|
709 |
try {
|
710 |
tile = cacheStruct.getTileStructure(level, tileCol, tileRow, |
711 |
new Point2D.Double(ex.getULX(), ex.getULY()), new Point2D.Double(ex.getLRX(), ex.getLRY())); |
712 |
} catch (TileBuildException e1) {
|
713 |
throw new TileGettingException(e1); |
714 |
} |
715 |
|
716 |
loadTileTimeParameters(tile); |
717 |
|
718 |
//Creamos un BandList con todas las bandas del fichero
|
719 |
BandList bandList = new BandListImpl();
|
720 |
for(int i = 0; i < provider.getBandCount(); i++) { |
721 |
try {
|
722 |
DatasetBand band = new DatasetBandImpl(provider.getURIOfFirstProvider(), i, provider.getDataType()[i], provider.getBandCount());
|
723 |
bandList.addBand(band, i); |
724 |
} catch(BandNotFoundInListException e) {
|
725 |
//No a?adimos la banda
|
726 |
} |
727 |
} |
728 |
bandList.setDrawableBands(new int[]{0, 1, 2}); |
729 |
|
730 |
tile.setDownloaderParams("BandList", bandList);
|
731 |
createTiledLayer(); |
732 |
return tiledLayer.getTile(tile);
|
733 |
} |
734 |
|
735 |
/*
|
736 |
* (non-Javadoc)
|
737 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
|
738 |
*/
|
739 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
740 |
BandList bandList, TileListener listener) throws ProcessInterruptedException, RasterDriverException {
|
741 |
try {
|
742 |
ArrayList<Tile> tileList = getTileList(ex, bandList, bufWidth, bufHeight);
|
743 |
tiledLayer.getTiles(tileList, listener); |
744 |
} catch (TileGettingException e) {
|
745 |
throw new RasterDriverException("Error getting the tile list", e); |
746 |
} catch (TileBuildException e) {
|
747 |
throw new RasterDriverException("Error building the tile list", e); |
748 |
} |
749 |
} |
750 |
|
751 |
/*
|
752 |
* (non-Javadoc)
|
753 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
754 |
*/
|
755 |
public Buffer getWindow(Extent extent, |
756 |
int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
757 |
//draw method
|
758 |
ArrayList<Tile> tileList = null; |
759 |
try {
|
760 |
tileList = getTileList(extent, bandList, bufWidth, bufHeight); |
761 |
for (int i = 0; i < tileList.size(); i++) { |
762 |
tiledLayer.getTile(tileList.get(i)); |
763 |
} |
764 |
} catch (TileGettingException e) {
|
765 |
throw new RasterDriverException("Error getting the tile list", e); |
766 |
} catch (TileBuildException e) {
|
767 |
throw new RasterDriverException("Error building the tile list", e); |
768 |
} |
769 |
MemoryMatrixBuffer matrixBuffer = new MemoryMatrixBuffer(tileList);
|
770 |
return matrixBuffer.getWindow(extent, rasterBuf);
|
771 |
} |
772 |
|
773 |
/*
|
774 |
* (non-Javadoc)
|
775 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
776 |
*/
|
777 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf) |
778 |
throws ProcessInterruptedException, RasterDriverException {
|
779 |
//return ((DefaultRasterProvider)provider).getWindow(ex, bandList, rasterBuf);
|
780 |
return null; |
781 |
} |
782 |
|
783 |
/*
|
784 |
* (non-Javadoc)
|
785 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
786 |
*/
|
787 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
788 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
789 |
Extent extent = new ExtentImpl(ulx, uly, ulx + w, uly - h);
|
790 |
ArrayList<Tile> tileList = null; |
791 |
try {
|
792 |
tileList = getTileList(extent, bandList, rasterBuf.getWidth(), rasterBuf.getHeight()); |
793 |
for (int i = 0; i < tileList.size(); i++) { |
794 |
tiledLayer.getTile(tileList.get(i)); |
795 |
} |
796 |
} catch (TileGettingException e) {
|
797 |
throw new RasterDriverException("Error getting the tile list", e); |
798 |
} catch (TileBuildException e) {
|
799 |
throw new RasterDriverException("Error building the tile list", e); |
800 |
} |
801 |
MemoryMatrixBuffer matrixBuffer = new MemoryMatrixBuffer(tileList);
|
802 |
return matrixBuffer.getWindow(extent, rasterBuf);
|
803 |
} |
804 |
|
805 |
/*
|
806 |
* (non-Javadoc)
|
807 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
808 |
*/
|
809 |
public Buffer getWindow(int x, int y, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
810 |
Buffer b = ((DefaultRasterProvider)provider).getWindow(x, y, bandList, rasterBuf); //Para proveedores de fichero esto va |
811 |
if(b != null) |
812 |
return b;
|
813 |
else {
|
814 |
//TODO
|
815 |
} |
816 |
return null; |
817 |
} |
818 |
|
819 |
/*
|
820 |
* (non-Javadoc)
|
821 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
822 |
*/
|
823 |
public Buffer getWindow(int x, int y, int w, int h, int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
824 |
Buffer b = ((DefaultRasterProvider)provider).getWindow(x, y, w, h, bufWidth, bufHeight, bandList, rasterBuf); //Para proveedores de fichero esto va |
825 |
if(b != null) |
826 |
return b;
|
827 |
else {
|
828 |
//TODO
|
829 |
} |
830 |
return null; |
831 |
} |
832 |
|
833 |
/*
|
834 |
* (non-Javadoc)
|
835 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
|
836 |
*/
|
837 |
public int getBlockSize() { |
838 |
return 0; |
839 |
} |
840 |
|
841 |
/*
|
842 |
* (non-Javadoc)
|
843 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
|
844 |
*/
|
845 |
public void setAffineTransform(AffineTransform t){ |
846 |
|
847 |
} |
848 |
|
849 |
/*
|
850 |
* (non-Javadoc)
|
851 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
|
852 |
*/
|
853 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
854 |
return getZoomLevels();
|
855 |
} |
856 |
|
857 |
/*
|
858 |
* (non-Javadoc)
|
859 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewWidth(int, int)
|
860 |
*/
|
861 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
862 |
return 0; |
863 |
} |
864 |
|
865 |
/*
|
866 |
* (non-Javadoc)
|
867 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewHeight(int, int)
|
868 |
*/
|
869 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
870 |
return 0; |
871 |
} |
872 |
|
873 |
/*
|
874 |
* (non-Javadoc)
|
875 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isOverviewsSupported()
|
876 |
*/
|
877 |
public boolean isOverviewsSupported() { |
878 |
return false; |
879 |
} |
880 |
|
881 |
/*
|
882 |
* (non-Javadoc)
|
883 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isReproyectable()
|
884 |
*/
|
885 |
public boolean isReproyectable() { |
886 |
return false; |
887 |
} |
888 |
|
889 |
/*
|
890 |
* (non-Javadoc)
|
891 |
* @see org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider#getName()
|
892 |
*/
|
893 |
public String getName() { |
894 |
return NAME;
|
895 |
} |
896 |
|
897 |
/**
|
898 |
* Convierte un punto desde coordenadas pixel a coordenadas del mundo.
|
899 |
* @param pt Punto a transformar
|
900 |
* @return punto transformado en coordenadas del mundo
|
901 |
*/
|
902 |
public Point2D rasterToWorld(Point2D pt) { |
903 |
Point2D p = new Point2D.Double(); |
904 |
getAffineTransform().transform(pt, p); |
905 |
return p;
|
906 |
} |
907 |
|
908 |
/**
|
909 |
* Convierte un punto desde del mundo a coordenadas pixel.
|
910 |
* @param pt Punto a transformar
|
911 |
* @return punto transformado en coordenadas pixel
|
912 |
*/
|
913 |
public Point2D worldToRaster(Point2D pt) { |
914 |
Point2D p = new Point2D.Double(); |
915 |
try {
|
916 |
getAffineTransform().inverseTransform(pt, p); |
917 |
} catch (NoninvertibleTransformException e) { |
918 |
return pt;
|
919 |
} |
920 |
return p;
|
921 |
} |
922 |
|
923 |
/*
|
924 |
* (non-Javadoc)
|
925 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setStatus(org.gvsig.raster.impl.provider.RasterProvider)
|
926 |
*/
|
927 |
public void setStatus(RasterProvider provider) { |
928 |
if(provider instanceof TileProvider) { |
929 |
} |
930 |
} |
931 |
|
932 |
/**
|
933 |
* ASigna el par?metro de inicializaci?n del driver.
|
934 |
*/
|
935 |
@Override
|
936 |
public void setParam(DataStoreProviderServices storeServices, DataStoreParameters param) { |
937 |
if(param instanceof RemoteStoreParameters) |
938 |
this.uri = ((RasterDataParameters)param).getURI();
|
939 |
this.param = param;
|
940 |
this.storeServices = storeServices;
|
941 |
} |
942 |
|
943 |
/*
|
944 |
* (non-Javadoc)
|
945 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getInfoByPoint(double, double)
|
946 |
*/
|
947 |
public String getInfoByPoint(double x, double y, ICancellable cancellable) throws RemoteServiceException { |
948 |
return null; |
949 |
} |
950 |
|
951 |
/**
|
952 |
* A tiled provider can't return a color table because each tile could have a different table.
|
953 |
* Besides, the table is not available when le provider is loaded. There could be to load
|
954 |
* the table from one tile because this is a property of a tile. The color table is sent to
|
955 |
* the render with the data in a tile.
|
956 |
*/
|
957 |
/*public ColorTable getColorTable() {
|
958 |
return null;
|
959 |
}*/
|
960 |
|
961 |
/*
|
962 |
* (non-Javadoc)
|
963 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#getColorInterpretation()
|
964 |
*/
|
965 |
public ColorInterpretation getColorInterpretation() {
|
966 |
return provider.getColorInterpretation();
|
967 |
} |
968 |
|
969 |
/**
|
970 |
* Asigna el objeto que contiene que contiene la interpretaci?n de
|
971 |
* color por banda
|
972 |
* @param DataStoreColorInterpretation
|
973 |
*/
|
974 |
public void setColorInterpretation(ColorInterpretation colorInterpretation) { |
975 |
provider.setColorInterpretation(colorInterpretation); |
976 |
} |
977 |
|
978 |
/*
|
979 |
* (non-Javadoc)
|
980 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTileSize(int)
|
981 |
*/
|
982 |
public int[] getTileSize(int level) { |
983 |
return provider.getTileServer().getStruct().getTileSizeByLevel(level);
|
984 |
} |
985 |
|
986 |
/*
|
987 |
* (non-Javadoc)
|
988 |
* @see org.gvsig.raster.impl.provider.RasterProvider#deleteLayerFromCache()
|
989 |
*/
|
990 |
public void deleteLayerFromCache() { |
991 |
TileCacheManager manager = TileCacheLocator.getManager(); |
992 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
993 |
if(tiledLayer != null) |
994 |
tileCache.removeLayer(tiledLayer); |
995 |
} |
996 |
|
997 |
/*
|
998 |
* (non-Javadoc)
|
999 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getTileServer()
|
1000 |
*/
|
1001 |
public TileServer getTileServer() {
|
1002 |
return secondLevelTileServer;
|
1003 |
} |
1004 |
|
1005 |
public void setSecondLevelTileServer(TileServer tileServer) { |
1006 |
this.secondLevelTileServer = tileServer;
|
1007 |
} |
1008 |
|
1009 |
/*
|
1010 |
* (non-Javadoc)
|
1011 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setTileServer(java.lang.Class)
|
1012 |
*/
|
1013 |
public void setTileServer(Class<?> tileServer) { |
1014 |
//TODO:Manejar excepciones
|
1015 |
//Crear par?metros
|
1016 |
TileDataParametersImpl par = new TileDataParametersImpl();
|
1017 |
par.setDataParameters(getDataParameters()); |
1018 |
par.setSecondLevelCache(true); //No crea un nuevo provider |
1019 |
|
1020 |
//Crea el proveedor de tiles de segundo nivel
|
1021 |
TileProvider newProvider = null;
|
1022 |
try {
|
1023 |
newProvider = new TileProvider(par, null); |
1024 |
newProvider.setProvider(this.provider);
|
1025 |
} catch (NotSupportedExtensionException e1) {
|
1026 |
e1.printStackTrace(); |
1027 |
} catch (FileNotSupportedException e) {
|
1028 |
//No se puede dar. Si el padre es soportado este tambi?n
|
1029 |
e.printStackTrace(); |
1030 |
} |
1031 |
|
1032 |
//Instancia el TileServer pasado por el cliente con el TileProvider de segundo nivel
|
1033 |
Constructor<?> constructor;
|
1034 |
TileServer tServer = null;
|
1035 |
try {
|
1036 |
constructor = tileServer.getConstructor(new Class<?>[]{DefaultRasterProvider.class}); |
1037 |
Object [] args2 = {newProvider}; |
1038 |
tServer = (TileServer)constructor.newInstance(args2); |
1039 |
} catch (SecurityException e) { |
1040 |
e.printStackTrace(); |
1041 |
} catch (NoSuchMethodException e) { |
1042 |
e.printStackTrace(); |
1043 |
} catch (IllegalArgumentException e) { |
1044 |
e.printStackTrace(); |
1045 |
} catch (InstantiationException e) { |
1046 |
e.printStackTrace(); |
1047 |
} catch (IllegalAccessException e) { |
1048 |
e.printStackTrace(); |
1049 |
} catch (InvocationTargetException e) { |
1050 |
e.printStackTrace(); |
1051 |
} |
1052 |
|
1053 |
//Asigna el TileServer al nuevo provider de segundo nivel
|
1054 |
newProvider.setSecondLevelTileServer(tServer); |
1055 |
|
1056 |
//Asigna al provider de tiles de primer nivel el de segundo.
|
1057 |
//Solo si las estructuras de cach? son diferentes
|
1058 |
try {
|
1059 |
if(!provider.getTileServer().getStruct().compare(tServer.getStruct())) {
|
1060 |
this.setProvider(newProvider);
|
1061 |
tiledLayer = null;
|
1062 |
} |
1063 |
} catch (NotSupportedExtensionException e) {
|
1064 |
e.printStackTrace(); |
1065 |
} |
1066 |
} |
1067 |
|
1068 |
} |