svn-gvsig-desktop / trunk / libraries / libCacheService / src / org / gvsig / cacheservice / CacheService.java @ 18218
History | View | Annotate | Download (6.19 KB)
1 | 14910 | rgaitan | package org.gvsig.cacheservice; |
---|---|---|---|
2 | 14896 | rgaitan | |
3 | import java.awt.Dimension; |
||
4 | import java.awt.Point; |
||
5 | import java.awt.geom.Rectangle2D; |
||
6 | import java.io.File; |
||
7 | /**
|
||
8 | 14926 | salva | *
|
9 | 14910 | rgaitan | * @author Rafael Gait�n <rgaitan@dsic.upv.es>, modified code from cq RasterCache of Luis W. Sevilla.
|
10 | 14896 | rgaitan | *
|
11 | */
|
||
12 | public abstract class CacheService { |
||
13 | 14926 | salva | |
14 | 14896 | rgaitan | /**
|
15 | * Tipo planetario. Las coordenadas son Lat/Lon
|
||
16 | */
|
||
17 | public static int SPHERIC = 0x10; |
||
18 | /**
|
||
19 | 14910 | rgaitan | * Tipo plano (UTM). Las coordenadas son m�tricas.
|
20 | 14896 | rgaitan | */
|
21 | public static int PLANE = 0x20; |
||
22 | /**
|
||
23 | 14910 | rgaitan | * el cach� se realiza en funci�n del tama�o del fichero,
|
24 | 14896 | rgaitan | * con los tiles relativos a su coordenada 0,0.
|
25 | */
|
||
26 | public static int LOCAL = 0x100; |
||
27 | /**
|
||
28 | 14910 | rgaitan | * el cach� se realiza con parametros globales, de manera que
|
29 | 14896 | rgaitan | * el tileado es con respecto a una rejilla de referencia, y no
|
30 | * calculado especialmente para ese raster.
|
||
31 | */
|
||
32 | public static int GLOBAL = 0x200; |
||
33 | 14926 | salva | |
34 | 14896 | rgaitan | public static final Rectangle2D sphericGlobalBounds = |
35 | new Rectangle2D.Double(-180,-90,360,180); |
||
36 | public static final Rectangle2D planeGlobalBounds = |
||
37 | 14926 | salva | new Rectangle2D.Double(-20000000,-10000000,40000000,20000000); |
38 | |||
39 | 14896 | rgaitan | public static int TILEID_TYPE_GOOGLE = 0x01; |
40 | public static int TILEID_TYPE_OSGPLANET = 0x02; |
||
41 | public static int TILEID_TYPE_VIRTUALEARTH = 0x03; |
||
42 | 14926 | salva | |
43 | 14896 | rgaitan | private String _name = ""; |
44 | private String _planet = ""; |
||
45 | |||
46 | private int _cacheType = GLOBAL | SPHERIC; |
||
47 | private int _tileIdType = TILEID_TYPE_OSGPLANET; |
||
48 | private String _cacheRootDir = "/data/cache"; |
||
49 | private String _cacheDir = null; |
||
50 | private int _tileSize = 256; |
||
51 | |||
52 | 14926 | salva | |
53 | 14896 | rgaitan | private boolean _withHashDirs = false; |
54 | private int _hashDirsNumber = 100; |
||
55 | 14926 | salva | |
56 | 14896 | rgaitan | private int _minLevel = 0; |
57 | private int _maxLevel = 20; |
||
58 | 14926 | salva | |
59 | 14896 | rgaitan | private Rectangle2D _bounds; |
60 | 14926 | salva | |
61 | 14896 | rgaitan | private Rectangle2D _fullExtent = sphericGlobalBounds; |
62 | 14926 | salva | |
63 | 14896 | rgaitan | /**
|
64 | * @param planet
|
||
65 | * @param name
|
||
66 | * @param server
|
||
67 | */
|
||
68 | public CacheService(String planet, String name) { |
||
69 | super();
|
||
70 | this._name = name;
|
||
71 | this._planet = planet;
|
||
72 | setBounds(sphericGlobalBounds); |
||
73 | } |
||
74 | |||
75 | 14926 | salva | |
76 | 14896 | rgaitan | /**
|
77 | 14910 | rgaitan | * Devuelve el tama�o de Tile como Dimension;
|
78 | 14896 | rgaitan | * @return
|
79 | 14926 | salva | */
|
80 | 14896 | rgaitan | public Dimension computeSz() { |
81 | return new Dimension(getTileSize(),getTileSize()); |
||
82 | } |
||
83 | |||
84 | public Dimension getFullSize(int level) { |
||
85 | int w = getTileSize() * (int)Math.pow(2,level); |
||
86 | return new Dimension(w, w/2); |
||
87 | } |
||
88 | 14926 | salva | |
89 | 14896 | rgaitan | /**
|
90 | * Devuelve el numero de Tiles (ancho y alto) para ese nivel.
|
||
91 | * @param level
|
||
92 | * @return
|
||
93 | */
|
||
94 | public Dimension getLevelSize(int level) { |
||
95 | int w = (int)Math.pow(2,level); |
||
96 | return new Dimension(w, w/2); |
||
97 | } |
||
98 | 14926 | salva | |
99 | 14896 | rgaitan | public boolean isFileInCache(String fName) { |
100 | File cacheFile = new File(fName); |
||
101 | return cacheFile.exists();
|
||
102 | } |
||
103 | 14926 | salva | |
104 | |||
105 | 14896 | rgaitan | public void setCacheDir(String dir) { |
106 | _cacheDir = dir; |
||
107 | } |
||
108 | public String getCacheDir() { |
||
109 | File file;
|
||
110 | if (_cacheDir == null) { |
||
111 | // Compruebo si existe el directorio del planeta
|
||
112 | _cacheDir = getCacheRootDir()+"/"+getPlanet()+"/"; |
||
113 | file = new File(_cacheDir); |
||
114 | if (!file.exists()) file.mkdir();
|
||
115 | // Compruebo si existe el directorio del servidor
|
||
116 | _cacheDir += getName()+"/";
|
||
117 | } |
||
118 | file = new File(_cacheDir); |
||
119 | if (!file.exists()) file.mkdirs();
|
||
120 | return _cacheDir;
|
||
121 | } |
||
122 | 14926 | salva | |
123 | 14896 | rgaitan | /**
|
124 | * @return Returns the cacheRootDir.
|
||
125 | */
|
||
126 | public String getCacheRootDir() { |
||
127 | return _cacheRootDir;
|
||
128 | } |
||
129 | /**
|
||
130 | * @param cacheRootDir The cacheRootDir to set.
|
||
131 | */
|
||
132 | public void setCacheRootDir(String cacheRootDir) { |
||
133 | _cacheRootDir = cacheRootDir; |
||
134 | } |
||
135 | |||
136 | /**
|
||
137 | * @return Returns the name.
|
||
138 | */
|
||
139 | public String getName() { |
||
140 | return _name;
|
||
141 | } |
||
142 | /**
|
||
143 | * @param name The name to set.
|
||
144 | */
|
||
145 | public void setName(String name) { |
||
146 | _name = name; |
||
147 | } |
||
148 | /**
|
||
149 | * @return Returns the planet.
|
||
150 | */
|
||
151 | public String getPlanet() { |
||
152 | return _planet;
|
||
153 | } |
||
154 | /**
|
||
155 | * @param planet The planet to set.
|
||
156 | */
|
||
157 | public void setPlanet(String planet) { |
||
158 | _planet = planet; |
||
159 | } |
||
160 | /**
|
||
161 | * @return Returns the tileSize.
|
||
162 | */
|
||
163 | public int getTileSize() { |
||
164 | return _tileSize;
|
||
165 | } |
||
166 | /**
|
||
167 | * @param tileSize The tileSize to set.
|
||
168 | */
|
||
169 | public void setTileSize(int tileSize) { |
||
170 | _tileSize = tileSize; |
||
171 | } |
||
172 | /**
|
||
173 | * @return Returns the tileIdType.
|
||
174 | */
|
||
175 | public int getTileIdType() { |
||
176 | return _tileIdType;
|
||
177 | } |
||
178 | /**
|
||
179 | * @param tileIdType The tileIdType to set.
|
||
180 | */
|
||
181 | public void setTileIdType(int tileIdType) { |
||
182 | _tileIdType = tileIdType; |
||
183 | } |
||
184 | /**
|
||
185 | * @return Returns the maxLevel.
|
||
186 | */
|
||
187 | public int getMaxLevel() { |
||
188 | return _maxLevel;
|
||
189 | } |
||
190 | /**
|
||
191 | * @param maxLevel The maxLevel to set.
|
||
192 | */
|
||
193 | public void setMaxLevel(int maxLevel) { |
||
194 | _maxLevel = maxLevel; |
||
195 | } |
||
196 | /**
|
||
197 | * @return Returns the minLevel.
|
||
198 | */
|
||
199 | public int getMinLevel() { |
||
200 | return _minLevel;
|
||
201 | } |
||
202 | /**
|
||
203 | * @param minLevel The minLevel to set.
|
||
204 | */
|
||
205 | public void setMinLevel(int minLevel) { |
||
206 | _minLevel = minLevel; |
||
207 | } |
||
208 | /**
|
||
209 | * @return Returns the bounds.
|
||
210 | */
|
||
211 | public Rectangle2D getBounds() { |
||
212 | return _bounds;
|
||
213 | } |
||
214 | |||
215 | public void setBounds(Rectangle2D r) { |
||
216 | _bounds = r; |
||
217 | } |
||
218 | /**
|
||
219 | * @return Returns the cacheType.
|
||
220 | */
|
||
221 | public int getCacheType() { |
||
222 | return _cacheType;
|
||
223 | } |
||
224 | /**
|
||
225 | * @param cacheType The cacheType to set.
|
||
226 | */
|
||
227 | public void setCacheType(int cacheType) { |
||
228 | _cacheType = cacheType; |
||
229 | if ((cacheType & GLOBAL) == GLOBAL)
|
||
230 | if ((cacheType & PLANE) == PLANE)
|
||
231 | setFullExtent(planeGlobalBounds); |
||
232 | else if ((cacheType & SPHERIC) == SPHERIC) |
||
233 | setFullExtent(sphericGlobalBounds); |
||
234 | } |
||
235 | /**
|
||
236 | * @return Returns the fullExtent.
|
||
237 | */
|
||
238 | public Rectangle2D getFullExtent() { |
||
239 | return _fullExtent;
|
||
240 | } |
||
241 | /**
|
||
242 | * @param fullExtent The fullExtent to set.
|
||
243 | */
|
||
244 | public void setFullExtent(Rectangle2D fullExtent) { |
||
245 | _fullExtent = fullExtent; |
||
246 | } |
||
247 | /**
|
||
248 | * Gets Number of Hash Directories. 100 by default.
|
||
249 | * @return Returns the hashDirsOrder.
|
||
250 | */
|
||
251 | public int getHashDirsNumber() { |
||
252 | return _hashDirsNumber;
|
||
253 | } |
||
254 | /**
|
||
255 | * Sets Number of Hash Directories.
|
||
256 | * @param hashDirsOrder The hashDirsOrder to set.
|
||
257 | */
|
||
258 | public void setHashDirsNumber(int hashDirsNumber) { |
||
259 | _hashDirsNumber = hashDirsNumber; |
||
260 | } |
||
261 | /**
|
||
262 | * returns if this cache has HashDirectories. False by difault.
|
||
263 | * @return Returns the withHashDirs.
|
||
264 | */
|
||
265 | public boolean isWithHashDirs() { |
||
266 | return _withHashDirs;
|
||
267 | } |
||
268 | /**
|
||
269 | * sets wheter this cache has HashDirectories or no.
|
||
270 | * @param withHashDirs The withHashDirs to set.
|
||
271 | */
|
||
272 | public void setWithHashDirs(boolean withHashDirs) { |
||
273 | _withHashDirs = withHashDirs; |
||
274 | } |
||
275 | /**
|
||
276 | * Compute HashDirNumbre from tileNumber.
|
||
277 | * @param num tileNumber (without level).
|
||
278 | * @return
|
||
279 | */
|
||
280 | public String getHashDir(Point num) { |
||
281 | String hd = null; |
||
282 | hd = ""+(num.x % _hashDirsNumber);
|
||
283 | return hd;
|
||
284 | } |
||
285 | } |