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