gvsig-raster / org.gvsig.raster.mosaic / trunk / org.gvsig.raster.mosaic / org.gvsig.raster.mosaic.io / src / main / java / org / gvsig / raster / mosaic / io / downloader / MosaicTileServer.java @ 859
History | View | Annotate | Download (4.76 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.downloader; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
28 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
29 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
30 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
31 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
32 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
33 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
34 |
import org.gvsig.raster.cache.tile.provider.Downloader; |
35 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
36 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
37 |
import org.gvsig.raster.impl.provider.RasterProvider; |
38 |
import org.gvsig.raster.mosaic.io.MosaicDataParameters; |
39 |
|
40 |
/**
|
41 |
* Data server for the tile cache in a MosaicProvider
|
42 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
43 |
*/
|
44 |
public class MosaicTileServer implements TileServer { |
45 |
private CacheStruct struct = null; |
46 |
private Downloader downloader = null; |
47 |
private DefaultRasterProvider provider = null; |
48 |
private String suffix = "tif"; |
49 |
private String layerName = null; |
50 |
private ArrayList<RasterProvider> provList = null; |
51 |
private int overlapMethod = MosaicDataParameters.FIRST; |
52 |
private int colorCorrectionMethod = MosaicDataParameters.NONE; |
53 |
private NoData noData = null; |
54 |
|
55 |
public MosaicTileServer(DefaultRasterProvider prov,
|
56 |
ArrayList<RasterProvider> provList,
|
57 |
String layerName,
|
58 |
int overlapMethod,
|
59 |
int colorCorrectionMethod,
|
60 |
NoData noData) { |
61 |
this.provider = prov;
|
62 |
this.layerName = layerName;
|
63 |
this.provList = provList;
|
64 |
this.overlapMethod = overlapMethod;
|
65 |
this.colorCorrectionMethod = colorCorrectionMethod;
|
66 |
this.noData = noData;
|
67 |
} |
68 |
|
69 |
/*
|
70 |
* (non-Javadoc)
|
71 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#getDownloader()
|
72 |
*/
|
73 |
public Downloader getDownloader() {
|
74 |
if(downloader == null) |
75 |
downloader = new TileDownloaderForMosaics(provider,
|
76 |
provList, |
77 |
getStruct(), |
78 |
TileCacheLibrary.DEFAULT_TILESIZE, |
79 |
getFileSuffix(), |
80 |
overlapMethod, |
81 |
colorCorrectionMethod, |
82 |
noData); |
83 |
return downloader;
|
84 |
} |
85 |
|
86 |
public CacheStruct getStruct() {
|
87 |
if(struct == null) { |
88 |
TileCacheManager manager = TileCacheLocator.getManager(); |
89 |
|
90 |
int coordinates = CacheStruct.FLAT;
|
91 |
if(provider.getProjection() != null) |
92 |
coordinates = (provider.getProjection() != null && provider.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
|
93 |
else {
|
94 |
Extent e = provider.getExtent(); |
95 |
if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && |
96 |
e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) { |
97 |
coordinates = CacheStruct.GEOGRAFIC; |
98 |
} |
99 |
} |
100 |
|
101 |
String epsg = null; |
102 |
IProjection proj = provider.getProjection(); |
103 |
if(proj != null) |
104 |
epsg = proj.getAbrev(); |
105 |
|
106 |
struct = manager.createCacheStructure(coordinates, |
107 |
TileCacheLibrary.DEFAULT_LEVELS, |
108 |
provider.getExtent().toRectangle2D(), |
109 |
provider.getCellSize(), |
110 |
TileCacheLibrary.DEFAULT_TILESIZE, |
111 |
TileCacheLibrary.DEFAULT_TILESIZE, |
112 |
layerName, |
113 |
TileCacheLibrary.DEFAULT_STRUCTURE, |
114 |
RasterLibrary.pathTileCache, |
115 |
getFileSuffix(), |
116 |
epsg, |
117 |
provider.getFileSize()); |
118 |
} |
119 |
return struct;
|
120 |
} |
121 |
|
122 |
/*
|
123 |
* (non-Javadoc)
|
124 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#getFileExtension()
|
125 |
*/
|
126 |
public String getFileSuffix() { |
127 |
return suffix;
|
128 |
} |
129 |
|
130 |
/*
|
131 |
* (non-Javadoc)
|
132 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#setFileSuffix(java.lang.String)
|
133 |
*/
|
134 |
public void setFileSuffix(String extension) { |
135 |
this.suffix = extension;
|
136 |
} |
137 |
} |