gvsig-raster / org.gvsig.raster.postgis / branches / org.gvsig.raster.postgis_dataaccess_refactoring / org.gvsig.raster.postgis.io / src / main / java / org / gvsig / raster / postgis / io / downloader / PostGISRasterTileServer.java @ 2289
History | View | Annotate | Download (4.7 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.postgis.io.downloader; |
23 |
|
24 |
import org.cresques.cts.IProjection; |
25 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
26 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
27 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
28 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
29 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
30 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
31 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
32 |
import org.gvsig.raster.cache.tile.provider.Downloader; |
33 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
34 |
import org.gvsig.raster.impl.provider.tile.TileDownloaderForFiles; |
35 |
import org.gvsig.raster.postgis.io.PostGISRasterProvider; |
36 |
|
37 |
/**
|
38 |
* Data server for the tile cache in a <code>PostGISRasterProvider</code>
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
40 |
*/
|
41 |
public class PostGISRasterTileServer implements TileServer { |
42 |
private CacheStruct struct = null; |
43 |
private Downloader downloader = null; |
44 |
private RasterDataStore store = null; |
45 |
private boolean externalStruct = false; |
46 |
|
47 |
public PostGISRasterTileServer(RasterDataStore store) {
|
48 |
this.store = store;
|
49 |
} |
50 |
|
51 |
public Downloader getDownloader() {
|
52 |
//The downloader is built the first time or if the structure is assigned from the client.
|
53 |
boolean firstLoad = (downloader == null); |
54 |
|
55 |
if(firstLoad || externalStruct) {
|
56 |
downloader = new TileDownloaderForFiles(store, getStruct(),
|
57 |
getStruct().getTileSizeByLevel(0)[0], |
58 |
getStruct().getTileSizeByLevel(0)[1], |
59 |
getFileSuffix()); |
60 |
externalStruct = false;
|
61 |
return downloader;
|
62 |
} |
63 |
|
64 |
//If the tile size has changed.
|
65 |
if(((TileDownloaderForFiles)downloader).getTileSize()[0] != TileCacheLibrary.DEFAULT_TILEWIDTH || |
66 |
((TileDownloaderForFiles)downloader).getTileSize()[1] != TileCacheLibrary.DEFAULT_TILEHEIGHT) {
|
67 |
downloader = new TileDownloaderForFiles(store, getStruct(),
|
68 |
TileCacheLibrary.DEFAULT_TILEWIDTH, |
69 |
TileCacheLibrary.DEFAULT_TILEHEIGHT, |
70 |
getFileSuffix()); |
71 |
} |
72 |
return downloader;
|
73 |
} |
74 |
|
75 |
public CacheStruct getStruct() {
|
76 |
if(struct == null) { |
77 |
TileCacheManager manager = TileCacheLocator.getManager(); |
78 |
|
79 |
int coordinates = CacheStruct.FLAT;
|
80 |
if(store.getProjection() != null) |
81 |
coordinates = (store.getProjection() != null && store.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
|
82 |
else {
|
83 |
Extent e = store.getExtent(); |
84 |
if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && |
85 |
e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) { |
86 |
coordinates = CacheStruct.GEOGRAFIC; |
87 |
} |
88 |
} |
89 |
|
90 |
String epsg = null; |
91 |
IProjection proj = store.getProjection(); |
92 |
if(proj != null) |
93 |
epsg = proj.getAbrev(); |
94 |
|
95 |
struct = manager.createCacheStructure(coordinates, |
96 |
TileCacheLibrary.DEFAULT_LEVELS, |
97 |
store.getExtent().toRectangle2D(), |
98 |
Double.POSITIVE_INFINITY,//provider.getCellSize(), |
99 |
TileCacheLibrary.DEFAULT_TILEWIDTH, |
100 |
TileCacheLibrary.DEFAULT_TILEWIDTH, |
101 |
((PostGISRasterProvider)store.getProvider()).getDataParameters().getURI(), |
102 |
((PostGISRasterProvider)store.getProvider()).getURIOfFirstProvider().replaceAll("\\.", "_"), |
103 |
TileCacheLibrary.DEFAULT_STRUCTURE, |
104 |
RasterLibrary.pathTileCache, |
105 |
getFileSuffix(), |
106 |
epsg, |
107 |
0);
|
108 |
} |
109 |
return struct;
|
110 |
} |
111 |
|
112 |
public void setStruct(CacheStruct struct) { |
113 |
if(struct != null) { |
114 |
this.struct = struct;
|
115 |
if(struct.getTileSizeByLevel(0) != null) { |
116 |
downloader = new TileDownloaderForFiles(store,
|
117 |
struct, |
118 |
struct.getTileSizeByLevel(0)[0], |
119 |
struct.getTileSizeByLevel(0)[1], |
120 |
getFileSuffix()); |
121 |
externalStruct = true;
|
122 |
} |
123 |
} |
124 |
} |
125 |
|
126 |
public String getFileSuffix() { |
127 |
return "tif"; |
128 |
} |
129 |
|
130 |
public void setFileSuffix(String extension) { |
131 |
} |
132 |
} |