Revision 10246
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.raster.cache</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>org.gvsig.raster.cache</name> |
|
8 |
<description>Cache management for raster files</description> |
|
9 |
<version>2.2.39</version> |
|
10 |
<scm> |
|
11 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39</connection> |
|
12 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39</developerConnection> |
|
13 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39</url> |
|
14 |
</scm> |
|
15 |
|
|
16 |
<repositories> |
|
17 |
<repository> |
|
18 |
<id>gvsig-public-http-repository</id> |
|
19 |
<name>gvSIG maven public HTTP repository</name> |
|
20 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
21 |
<releases> |
|
22 |
<enabled>true</enabled> |
|
23 |
<updatePolicy>daily</updatePolicy> |
|
24 |
<checksumPolicy>warn</checksumPolicy> |
|
25 |
</releases> |
|
26 |
<snapshots> |
|
27 |
<enabled>true</enabled> |
|
28 |
<updatePolicy>daily</updatePolicy> |
|
29 |
<checksumPolicy>warn</checksumPolicy> |
|
30 |
</snapshots> |
|
31 |
</repository> |
|
32 |
</repositories> |
|
33 |
|
|
34 |
<parent> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.desktop</artifactId> |
|
37 |
<version>2.0.256</version> |
|
38 |
</parent> |
|
39 |
|
|
40 |
<developers> |
|
41 |
<developer> |
|
42 |
<id>nbrodin</id> |
|
43 |
<name>Nacho Brodin</name> |
|
44 |
<email>nachobrodin@gmail.com</email> |
|
45 |
<roles> |
|
46 |
<role>Architect</role> |
|
47 |
<role>Developer</role> |
|
48 |
</roles> |
|
49 |
</developer> |
|
50 |
</developers> |
|
51 |
|
|
52 |
<dependencyManagement> |
|
53 |
<dependencies> |
|
54 |
|
|
55 |
|
|
56 |
<!-- |
|
57 |
Versions of child projects |
|
58 |
--> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.raster.cache.lib.api</artifactId> |
|
62 |
<version>2.2.39</version> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.raster.cache.lib.impl</artifactId> |
|
67 |
<version>2.2.39</version> |
|
68 |
</dependency> |
|
69 |
|
|
70 |
|
|
71 |
</dependencies> |
|
72 |
</dependencyManagement> |
|
73 |
|
|
74 |
|
|
75 |
<build> |
|
76 |
<plugins> |
|
77 |
<plugin> |
|
78 |
<groupId>org.apache.maven.plugins</groupId> |
|
79 |
<artifactId>maven-release-plugin</artifactId> |
|
80 |
<configuration> |
|
81 |
<tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/</tagBase> |
|
82 |
<goals>deploy</goals> |
|
83 |
</configuration> |
|
84 |
</plugin> |
|
85 |
<plugin> |
|
86 |
<groupId>org.apache.maven.plugins</groupId> |
|
87 |
<artifactId>maven-compiler-plugin</artifactId> |
|
88 |
<configuration> |
|
89 |
<source>1.5</source> |
|
90 |
<target>1.5</target> |
|
91 |
</configuration> |
|
92 |
</plugin> |
|
93 |
<plugin> |
|
94 |
<groupId>org.codehaus.mojo</groupId> |
|
95 |
<artifactId>animal-sniffer-maven-plugin</artifactId> |
|
96 |
<configuration> |
|
97 |
<skip>true</skip> |
|
98 |
</configuration> |
|
99 |
</plugin> |
|
100 |
</plugins> |
|
101 |
</build> |
|
102 |
<modules> |
|
103 |
<module>org.gvsig.raster.cache.lib.api</module> |
|
104 |
<module>org.gvsig.raster.cache.lib.impl</module> |
|
105 |
</modules> |
|
106 |
</project> |
|
0 | 107 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/DefaultTileCacheManager.java | ||
---|---|---|
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.cache.tile.impl; |
|
23 |
|
|
24 |
import java.awt.geom.Point2D; |
|
25 |
import java.awt.geom.Rectangle2D; |
|
26 |
|
|
27 |
import org.gvsig.raster.cache.tile.Tile; |
|
28 |
import org.gvsig.raster.cache.tile.TileCache; |
|
29 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
|
30 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
|
31 |
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy; |
|
32 |
import org.gvsig.raster.cache.tile.impl.disk.FlatXFileSystemStrategy; |
|
33 |
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl; |
|
34 |
import org.gvsig.raster.cache.tile.impl.provider.DefaultCacheStruct; |
|
35 |
import org.gvsig.raster.cache.tile.pool.ThreadPool; |
|
36 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
|
37 |
|
|
38 |
/** |
|
39 |
* Default {@link RasterManager} implementation. |
|
40 |
* |
|
41 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
42 |
* @version $Id$ |
|
43 |
*/ |
|
44 |
public class DefaultTileCacheManager implements TileCacheManager { |
|
45 |
private static DefaultTileCacheManager internalInstance = new DefaultTileCacheManager(); |
|
46 |
private TileCache tileCacheInstance = null; |
|
47 |
public static int TILE_TIME_OUT = 20000; |
|
48 |
|
|
49 |
/** |
|
50 |
* Gets an instance of this object for internal use. |
|
51 |
* @return DefaultRasterManager |
|
52 |
*/ |
|
53 |
public static DefaultTileCacheManager getInstance() { |
|
54 |
return internalInstance; |
|
55 |
} |
|
56 |
|
|
57 |
public TileCache getTileCache(String baseDir) { |
|
58 |
if(tileCacheInstance == null) |
|
59 |
tileCacheInstance = new TileCacheImpl(baseDir); |
|
60 |
return tileCacheInstance; |
|
61 |
} |
|
62 |
|
|
63 |
public Tile createTile(int level, int col, int row) { |
|
64 |
return new TileImpl(level, col, row); |
|
65 |
} |
|
66 |
|
|
67 |
public Tile createTile(int wPx, int hPx, int row, int col, Point2D ul, Point2D lr) { |
|
68 |
return new TileImpl(wPx, hPx, row, col, ul, lr); |
|
69 |
} |
|
70 |
|
|
71 |
public CacheStruct createCacheStructure(int typeOfCoords, |
|
72 |
int levels, |
|
73 |
Rectangle2D layerExtent, |
|
74 |
double pixelSize, |
|
75 |
int tilePxWidth, |
|
76 |
int tilePxHeight, |
|
77 |
String uri, |
|
78 |
String layerName, |
|
79 |
String strategy, |
|
80 |
String baseDir, |
|
81 |
String fileSuffix, |
|
82 |
String epsg, |
|
83 |
long size) { |
|
84 |
return new DefaultCacheStruct(typeOfCoords, |
|
85 |
levels, |
|
86 |
layerExtent, |
|
87 |
pixelSize, |
|
88 |
tilePxWidth, |
|
89 |
tilePxHeight, |
|
90 |
uri, |
|
91 |
layerName, |
|
92 |
createStrategy(strategy), |
|
93 |
baseDir, |
|
94 |
fileSuffix, |
|
95 |
epsg, |
|
96 |
size ); |
|
97 |
} |
|
98 |
|
|
99 |
public CacheStruct createCacheStructure(int typeOfCoords, |
|
100 |
int levels, |
|
101 |
Rectangle2D layerExtent, |
|
102 |
double pixelSize, |
|
103 |
int tilePxWidth, |
|
104 |
int tilePxHeight, |
|
105 |
String layerName, |
|
106 |
String strategy, |
|
107 |
String baseDir, |
|
108 |
String fileSuffix, |
|
109 |
String epsg, |
|
110 |
long size) { |
|
111 |
return new DefaultCacheStruct(typeOfCoords, |
|
112 |
levels, |
|
113 |
layerExtent, |
|
114 |
pixelSize, |
|
115 |
tilePxWidth, |
|
116 |
tilePxHeight, |
|
117 |
layerName, |
|
118 |
layerName, |
|
119 |
createStrategy(strategy), |
|
120 |
baseDir, |
|
121 |
fileSuffix, |
|
122 |
epsg, |
|
123 |
size ); |
|
124 |
} |
|
125 |
|
|
126 |
/** |
|
127 |
* Creates a strategy object |
|
128 |
* @param strategy |
|
129 |
* @return |
|
130 |
*/ |
|
131 |
public ITileFileSystemStrategy createStrategy(String strategy) { |
|
132 |
ITileFileSystemStrategy strat = null; |
|
133 |
if(strategy == null || strategy.compareTo(TileCacheLibrary.FLATX_STRUCT) == 0) |
|
134 |
strat = new FlatXFileSystemStrategy(); |
|
135 |
return strat; |
|
136 |
} |
|
137 |
|
|
138 |
public ThreadPool createThreadPool(boolean priorityActive) { |
|
139 |
return new ThreadPoolImpl(priorityActive); |
|
140 |
} |
|
141 |
|
|
142 |
public ThreadPool createThreadPool(boolean priorityActive, int nThreads) { |
|
143 |
return new ThreadPoolImpl(priorityActive, nThreads); |
|
144 |
} |
|
145 |
|
|
146 |
public void setTileTimeOut(int ms) { |
|
147 |
TILE_TIME_OUT = ms; |
|
148 |
} |
|
149 |
|
|
150 |
public int getTileTimeOut() { |
|
151 |
return TILE_TIME_OUT; |
|
152 |
} |
|
153 |
|
|
154 |
} |
|
0 | 155 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/TileCacheImpl.java | ||
---|---|---|
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.cache.tile.impl; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.IOException; |
|
26 |
import java.util.ArrayList; |
|
27 |
|
|
28 |
import org.gvsig.raster.cache.tile.TileCache; |
|
29 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
|
30 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
|
31 |
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy; |
|
32 |
import org.gvsig.raster.cache.tile.impl.layer.TiledLayerImpl; |
|
33 |
import org.gvsig.raster.cache.tile.layer.TiledLayer; |
|
34 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
35 |
|
|
36 |
/** |
|
37 |
* Main implementation for the tile cache |
|
38 |
* |
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
40 |
*/ |
|
41 |
public class TileCacheImpl implements TileCache { |
|
42 |
private ArrayList<TiledLayerImpl> layerList = null; |
|
43 |
//private MemoryManager memoryManager = null; |
|
44 |
private String baseDir = null; |
|
45 |
private double currentSize = 0; |
|
46 |
protected String preffixSizeFileName = "c_len"; |
|
47 |
protected String configDir = ".metadata"; |
|
48 |
|
|
49 |
public TileCacheImpl(String baseDir) { |
|
50 |
this.layerList = new ArrayList<TiledLayerImpl>(); |
|
51 |
//memoryManager = new MemoryManager(); |
|
52 |
this.baseDir = baseDir; |
|
53 |
loadSize(); |
|
54 |
} |
|
55 |
|
|
56 |
public void updateBaseDirectory(String dir) { |
|
57 |
this.baseDir = dir; |
|
58 |
for (int i = 0; i < layerList.size(); i++) { |
|
59 |
layerList.get(i).updateBaseDirectory(dir); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Updates the size of the tiles downloaded |
|
65 |
* @param sizeBytes |
|
66 |
*/ |
|
67 |
public synchronized void updateSize(long sizeBytes) { |
|
68 |
currentSize += ((double)sizeBytes); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Loads the size of the directory |
|
73 |
*/ |
|
74 |
private void loadSize() { |
|
75 |
File f = new File(baseDir + File.separator + configDir); |
|
76 |
if(!f.exists()) { |
|
77 |
f.mkdirs(); |
|
78 |
saveSize(); |
|
79 |
} |
|
80 |
String[] list = f.list(); |
|
81 |
for (int i = 0; i < list.length; i++) { |
|
82 |
if(list[i].startsWith(preffixSizeFileName)) { |
|
83 |
String s = list[i].substring(5, list[i].length()); |
|
84 |
try { |
|
85 |
currentSize = Double.valueOf(s); |
|
86 |
} catch (NumberFormatException e) { |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Saves a size file |
|
94 |
* @throws IOException |
|
95 |
*/ |
|
96 |
public synchronized void saveSize() { |
|
97 |
String dir = baseDir + File.separator + configDir; |
|
98 |
File f = new File(dir); |
|
99 |
if(!f.exists()) { |
|
100 |
f.mkdirs(); |
|
101 |
} |
|
102 |
String[] list = f.list(); |
|
103 |
if(list != null) { |
|
104 |
for (int i = 0; i < list.length; i++) { |
|
105 |
if(list[i].startsWith(preffixSizeFileName)) { |
|
106 |
new File(dir + File.separator + list[i]).delete(); |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
try { |
|
111 |
new File(dir + File.separator + preffixSizeFileName + (int)currentSize).createNewFile(); |
|
112 |
} catch (IOException e) { |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
public boolean isFullDiskCache() { |
|
117 |
return currentSize >= (TileCacheLibrary.MAX_CACHE_SIZE * 1048576); |
|
118 |
} |
|
119 |
|
|
120 |
public TiledLayer createLayer(TileServer provider, String strategyType) { |
|
121 |
ITileFileSystemStrategy strat = ((DefaultTileCacheManager)TileCacheLocator.getManager()).createStrategy(strategyType); |
|
122 |
TiledLayerImpl l = new TiledLayerImpl(this, provider, strat/*, memoryManager.createLRUTileCache()*/); |
|
123 |
layerList.add(l); |
|
124 |
return l; |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Gets the base directory |
|
129 |
* @return |
|
130 |
*/ |
|
131 |
public String getBaseDirectory() { |
|
132 |
return baseDir; |
|
133 |
} |
|
134 |
|
|
135 |
public String getConfigurationDirectory() { |
|
136 |
return configDir; |
|
137 |
} |
|
138 |
|
|
139 |
public void removeLayer(TiledLayer layer) { |
|
140 |
layerList.remove(layer); |
|
141 |
updateSize(-layer.delete()); |
|
142 |
saveSize(); |
|
143 |
} |
|
144 |
} |
|
0 | 145 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/memory/MemoryManager.java | ||
---|---|---|
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.cache.tile.impl.memory; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* Manager for the memory distribution among different layers when the LRUTileCache |
|
27 |
* is used |
|
28 |
* |
|
29 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
30 |
*/ |
|
31 |
public class MemoryManager { |
|
32 |
|
|
33 |
/** |
|
34 |
* Gets a new LRUTileCache object |
|
35 |
* @return |
|
36 |
*/ |
|
37 |
public LRUTileCache createLRUTileCache() { |
|
38 |
return null; |
|
39 |
} |
|
40 |
|
|
41 |
} |
|
0 | 42 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/memory/LRUTileCache.java | ||
---|---|---|
1 |
/* gvSIG Mini. A free mobile phone viewer of free maps. |
|
2 |
* |
|
3 |
* Copyright (C) 2009 Prodevelop. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Prodevelop, S.L. |
|
22 |
* Pza. Don Juan de Villarrasa, 14 - 5 |
|
23 |
* 46001 Valencia |
|
24 |
* Spain |
|
25 |
* |
|
26 |
* +34 963 510 612 |
|
27 |
* +34 963 510 968 |
|
28 |
* prode@prodevelop.es |
|
29 |
* http://www.prodevelop.es |
|
30 |
* |
|
31 |
* gvSIG Mini has been partially funded by IMPIVA (Instituto de la Peque�a y |
|
32 |
* Mediana Empresa de la Comunidad Valenciana) & |
|
33 |
* European Union FEDER funds. |
|
34 |
* |
|
35 |
* 2009. |
|
36 |
* author Rub�n Blanco rblanco@prodevelop.es |
|
37 |
* |
|
38 |
* |
|
39 |
* Original version of the code made by Nicolas Gramlich. |
|
40 |
* No header license code found on the original source file. |
|
41 |
* |
|
42 |
* Original source code downloaded from http://code.google.com/p/osmdroid/ |
|
43 |
* package org.andnav.osm.views.util; |
|
44 |
* |
|
45 |
* License stated in that website is |
|
46 |
* http://www.gnu.org/licenses/lgpl.html |
|
47 |
* As no specific LGPL version was specified, LGPL license version is LGPL v2.1 |
|
48 |
* is assumed. |
|
49 |
* |
|
50 |
* |
|
51 |
*/ |
|
52 |
package org.gvsig.raster.cache.tile.impl.memory; |
|
53 |
|
|
54 |
|
|
55 |
//import org.gvsig.raster.cache.buffer.Buffer; |
|
56 |
|
|
57 |
/** |
|
58 |
* A Last Recent Used cache of Bitmaps |
|
59 |
* @author aromeu |
|
60 |
* @author rblanco |
|
61 |
* |
|
62 |
*/ |
|
63 |
public class LRUTileCache { |
|
64 |
// extends HashMap<String, Buffer> { |
|
65 |
// private static final long serialVersionUID = 6215141; |
|
66 |
// private final int maxCacheSize; |
|
67 |
// private LinkedList<String> list = null; |
|
68 |
// private final static Logger log = Logger.getLogger("LRUTileCache"); |
|
69 |
// |
|
70 |
// /** |
|
71 |
// * The Constructor |
|
72 |
// * @param maxCacheSize The cache size in number of Bitmaps |
|
73 |
// */ |
|
74 |
// public LRUTileCache(final int maxCacheSize) { |
|
75 |
// super(maxCacheSize); |
|
76 |
// this.maxCacheSize = Math.max(0, maxCacheSize); |
|
77 |
// this.list = new LinkedList<String>(); |
|
78 |
// } |
|
79 |
// |
|
80 |
// /** |
|
81 |
// * Clears the cache |
|
82 |
// */ |
|
83 |
// public synchronized void clear() { |
|
84 |
// try { |
|
85 |
// /*for (final Buffer b : this.values()) { |
|
86 |
// if (b != null) { |
|
87 |
// b.recycle(); |
|
88 |
// } |
|
89 |
// }*/ |
|
90 |
// super.clear(); |
|
91 |
// list.clear(); |
|
92 |
// } catch (Exception e) { |
|
93 |
// log.log(Level.SEVERE, "clear cache: ", e); |
|
94 |
// } |
|
95 |
// } |
|
96 |
// |
|
97 |
// /** |
|
98 |
// * Adds a Bitmap to the cache. If the cache is full, removes the last |
|
99 |
// */ |
|
100 |
// public synchronized Buffer put(final String key, final Buffer value) { |
|
101 |
// try { |
|
102 |
// if (maxCacheSize == 0) { |
|
103 |
// return null; |
|
104 |
// } |
|
105 |
// |
|
106 |
// // if the key isn't in the cache and the cache is full... |
|
107 |
// if (!super.containsKey(key) && !list.isEmpty() |
|
108 |
// && list.size() + 1 > maxCacheSize) { |
|
109 |
// final Object deadKey = list.removeLast(); |
|
110 |
// super.remove(deadKey); |
|
111 |
// //if (bitmap != null) |
|
112 |
// //bitmap.recycle(); |
|
113 |
// } |
|
114 |
// |
|
115 |
// updateKey(key); |
|
116 |
// } catch (Exception e) { |
|
117 |
// log.log(Level.SEVERE, "put", e); |
|
118 |
// } |
|
119 |
// return super.put(key, value); |
|
120 |
// } |
|
121 |
// |
|
122 |
// /** |
|
123 |
// * Returns a cached Bitmap given a key |
|
124 |
// * @param key The key of the Bitmap stored on the HashMap |
|
125 |
// * @return The Bitmap or null if it is not stored in the cache |
|
126 |
// */ |
|
127 |
// public synchronized Buffer get(final String key) { |
|
128 |
// try { |
|
129 |
// final Buffer value = super.get(key); |
|
130 |
// if (value != null) { |
|
131 |
// updateKey(key); |
|
132 |
// } |
|
133 |
// return value; |
|
134 |
// } catch (Exception e) { |
|
135 |
// log.log(Level.SEVERE, "get", e); |
|
136 |
// return null; |
|
137 |
// } |
|
138 |
// } |
|
139 |
// |
|
140 |
// /** |
|
141 |
// * Removes a Bitmap from the cache |
|
142 |
// * @param key The key of the Bitmap to remove |
|
143 |
// */ |
|
144 |
// public synchronized void remove(final String key) { |
|
145 |
// try { |
|
146 |
// list.remove(key); |
|
147 |
// } catch (Exception e) { |
|
148 |
// log.log(Level.SEVERE, "remove", e); |
|
149 |
// } |
|
150 |
// super.remove(key); |
|
151 |
// //if (bitmap != null) |
|
152 |
// //bitmap.recycle(); |
|
153 |
// } |
|
154 |
// |
|
155 |
// /** |
|
156 |
// * The key is touched (recent used) and added to the top of the list |
|
157 |
// * @param key The key to be updated |
|
158 |
// */ |
|
159 |
// private void updateKey(final String key) { |
|
160 |
// try { |
|
161 |
// list.remove(key); |
|
162 |
// list.addFirst(key); |
|
163 |
// } catch (Exception e) { |
|
164 |
// log.log(Level.SEVERE, "updatekey", e); |
|
165 |
// } |
|
166 |
// } |
|
167 |
} |
|
0 | 168 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/pool/ThreadTask.java | ||
---|---|---|
1 |
package org.gvsig.raster.cache.tile.impl.pool; |
|
2 |
|
|
3 |
import org.gvsig.raster.cache.tile.pool.AtomicTask; |
|
4 |
|
|
5 |
/** |
|
6 |
* This represents one thread in the pool. This thread gets a new task in |
|
7 |
* the pool and executes it. |
|
8 |
* |
|
9 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
10 |
*/ |
|
11 |
class ThreadTask extends Thread { |
|
12 |
private ThreadPoolImpl pool = null; |
|
13 |
private boolean stop = false; |
|
14 |
private AtomicTask currentJob = null; |
|
15 |
private boolean getMoreTiles = true; |
|
16 |
|
|
17 |
public ThreadTask(ThreadPoolImpl thePool) { |
|
18 |
pool = thePool; |
|
19 |
} |
|
20 |
|
|
21 |
public void run() { |
|
22 |
while (!stop) { |
|
23 |
if(getMoreTiles) { |
|
24 |
currentJob = pool.getNext(); |
|
25 |
currentJob.run(); |
|
26 |
} else { |
|
27 |
try { |
|
28 |
Thread.sleep(500); |
|
29 |
} catch (InterruptedException e) { |
|
30 |
} |
|
31 |
} |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* Stops this thread |
|
37 |
*/ |
|
38 |
public Runnable stopThread() { |
|
39 |
stop = true; |
|
40 |
return currentJob; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Cancels the task in progress and avoids that next tiles are gotten |
|
45 |
*/ |
|
46 |
public void cancelTaskInProgress() { |
|
47 |
if(currentJob != null) |
|
48 |
currentJob.cancelTask(); |
|
49 |
getMoreTiles = false; |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Gets new tiles to processed of the input queue |
|
54 |
*/ |
|
55 |
public void resumeTasks() { |
|
56 |
getMoreTiles = true; |
|
57 |
} |
|
58 |
} |
|
0 | 59 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/pool/TilePipeImpl.java | ||
---|---|---|
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.cache.tile.impl.pool; |
|
23 |
|
|
24 |
import java.util.LinkedList; |
|
25 |
import java.util.Queue; |
|
26 |
|
|
27 |
import org.gvsig.raster.cache.tile.Tile; |
|
28 |
import org.gvsig.raster.cache.tile.pool.AtomicTask; |
|
29 |
import org.gvsig.raster.cache.tile.pool.TilePipe; |
|
30 |
|
|
31 |
/** |
|
32 |
* This class manages transactions between the producer and the consumer. The |
|
33 |
* producer download tiles from a server and the consumer is a tile provider |
|
34 |
* which will return downloaded tiles. |
|
35 |
* |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class TilePipeImpl implements TilePipe { |
|
39 |
private boolean isEmpty = true; |
|
40 |
private Queue<AtomicTask> buffer = new LinkedList<AtomicTask>(); |
|
41 |
private boolean debug = false; |
|
42 |
|
|
43 |
public TilePipeImpl() { |
|
44 |
this.debug = false; |
|
45 |
} |
|
46 |
|
|
47 |
public TilePipeImpl(boolean debug) { |
|
48 |
this.debug = debug; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Sets a tile in the pipe |
|
53 |
* @param tile |
|
54 |
*/ |
|
55 |
public synchronized void setAtomicTask(AtomicTask task) { |
|
56 |
if(task != null) |
|
57 |
buffer.add(task); |
|
58 |
isEmpty = false; |
|
59 |
|
|
60 |
if(debug) |
|
61 |
System.err.println("Setting tile " + ((Tile)task).getCol() + " " + ((Tile)task).getRow()); |
|
62 |
|
|
63 |
notify(); |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Gets a tile from the pipe |
|
68 |
* @return |
|
69 |
*/ |
|
70 |
public synchronized AtomicTask getAtomicTask() { |
|
71 |
if(debug) |
|
72 |
System.out.println("0-Getting tile "); |
|
73 |
while( isEmpty == true ) { |
|
74 |
try { |
|
75 |
wait(); |
|
76 |
} catch( InterruptedException e ) { |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
AtomicTask task = buffer.poll() ; |
|
81 |
|
|
82 |
if(debug) |
|
83 |
System.out.println("1-Getting tile " + ((Tile)task).getCol() + " " + ((Tile)task).getRow()); |
|
84 |
|
|
85 |
if( getSize() == 0 ) |
|
86 |
isEmpty = true; |
|
87 |
|
|
88 |
return task; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Returns the number of elements in the queue |
|
93 |
* @return |
|
94 |
*/ |
|
95 |
public synchronized int getSize() { |
|
96 |
return buffer.size(); |
|
97 |
} |
|
98 |
|
|
99 |
/* |
|
100 |
* (non-Javadoc) |
|
101 |
* @see org.gvsig.raster.cache.tile.pool.TilePipe#clear() |
|
102 |
*/ |
|
103 |
public void clear() { |
|
104 |
synchronized (buffer) { |
|
105 |
buffer.clear(); |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
0 | 109 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/pool/ThreadPoolImpl.java | ||
---|---|---|
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.cache.tile.impl.pool; |
|
23 |
|
|
24 |
import java.util.Collections; |
|
25 |
import java.util.LinkedList; |
|
26 |
|
|
27 |
import org.gvsig.raster.cache.tile.Tile; |
|
28 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
|
29 |
import org.gvsig.raster.cache.tile.pool.AtomicTask; |
|
30 |
import org.gvsig.raster.cache.tile.pool.ThreadPool; |
|
31 |
import org.gvsig.raster.cache.tile.pool.TilePipe; |
|
32 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
|
33 |
|
|
34 |
/** |
|
35 |
* Pool of threads. This class contains a list of tasks and a limited number |
|
36 |
* of threads to execute them. When a thread is free will execute the next task |
|
37 |
* in the list. |
|
38 |
* |
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
40 |
*/ |
|
41 |
public class ThreadPoolImpl implements ThreadPool { |
|
42 |
private int NTHREADS_POOL = 5; |
|
43 |
private ThreadTask[] threadList = null; |
|
44 |
private LinkedList<AtomicTask> tasks = new LinkedList<AtomicTask>(); |
|
45 |
private boolean priorityActive = false; |
|
46 |
private TilePipe tilePipe = null; |
|
47 |
|
|
48 |
/** |
|
49 |
* Constructor. Only for testing purposes. After this constructor the method init |
|
50 |
* has to be called |
|
51 |
*/ |
|
52 |
public ThreadPoolImpl() { |
|
53 |
this.priorityActive = true; |
|
54 |
threadList = new ThreadTask[NTHREADS_POOL]; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Constructor |
|
59 |
* @param priorityActive true if the pool runs using priorities and false if doesn't |
|
60 |
* @param nThreads Number of threads of this pool |
|
61 |
*/ |
|
62 |
public ThreadPoolImpl(boolean priorityActive, int nThreads) { |
|
63 |
this.priorityActive = true; |
|
64 |
NTHREADS_POOL = nThreads; |
|
65 |
init(); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Constructor |
|
70 |
* @param priorityActive true if the pool runs using priorities and false if doesn't |
|
71 |
*/ |
|
72 |
public ThreadPoolImpl(boolean priorityActive) { |
|
73 |
this.priorityActive = priorityActive; |
|
74 |
init(); |
|
75 |
} |
|
76 |
|
|
77 |
public void init() { |
|
78 |
if(threadList == null) |
|
79 |
threadList = new ThreadTask[NTHREADS_POOL]; |
|
80 |
for (int i = 0; i < NTHREADS_POOL; i++) { |
|
81 |
threadList[i] = new ThreadTask(this); |
|
82 |
threadList[i].start(); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Cancel the pool of threads and destroy the pool |
|
88 |
* @param listener |
|
89 |
*/ |
|
90 |
public void cancelPool(TileListener listener) { |
|
91 |
if(threadList != null) { |
|
92 |
for (int i = 0; i < NTHREADS_POOL; i++) { |
|
93 |
if(threadList[i] != null) { |
|
94 |
Runnable r = threadList[i].stopThread(); |
|
95 |
try { |
|
96 |
if(listener != null) |
|
97 |
listener.tileReady((Tile)r); |
|
98 |
} catch (TileGettingException e) { |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
for (int i = 0; i < tasks.size(); i++) { |
|
104 |
try { |
|
105 |
if(listener != null) |
|
106 |
listener.tileReady((Tile)tasks.get(i)); |
|
107 |
} catch (TileGettingException e) { |
|
108 |
} |
|
109 |
} |
|
110 |
synchronized (tasks) { |
|
111 |
tasks.notifyAll(); |
|
112 |
} |
|
113 |
destroyPool(); |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Cleans the input and output pool |
|
118 |
* @param listener |
|
119 |
*/ |
|
120 |
public void emptyPool() { |
|
121 |
//Don't get and set more tiles |
|
122 |
for (int i = 0; i < threadList.length; i++) { |
|
123 |
threadList[i].cancelTaskInProgress(); |
|
124 |
} |
|
125 |
|
|
126 |
//Cleans queues |
|
127 |
synchronized (tasks) { |
|
128 |
tasks.clear(); |
|
129 |
getTilePipe().clear(); |
|
130 |
tasks.notifyAll(); |
|
131 |
} |
|
132 |
|
|
133 |
//Gets tiles again |
|
134 |
for (int i = 0; i < threadList.length; i++) { |
|
135 |
threadList[i].resumeTasks(); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
public LinkedList<AtomicTask> getInputTaskList() { |
|
140 |
return tasks; |
|
141 |
} |
|
142 |
|
|
143 |
/* |
|
144 |
* (non-Javadoc) |
|
145 |
* @see org.gvsig.raster.cache.tile.pool.ThreadPool#getTilePipe() |
|
146 |
*/ |
|
147 |
public TilePipe getTilePipe() { |
|
148 |
if(tilePipe == null) |
|
149 |
tilePipe = new TilePipeImpl(); |
|
150 |
return tilePipe; |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* Stops all threads in the list and sets the list to null |
|
155 |
* @deprecated |
|
156 |
*/ |
|
157 |
public void destroyPool() { |
|
158 |
for (int i = 0; i < NTHREADS_POOL; i++) { |
|
159 |
threadList[i].stopThread(); |
|
160 |
threadList[i] = null; |
|
161 |
} |
|
162 |
threadList = null; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Returns true if the pool is valid |
|
167 |
* @return |
|
168 |
*/ |
|
169 |
public boolean isPoolValid() { |
|
170 |
return !(threadList == null); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Adds a new task to the list |
|
175 |
* @param task |
|
176 |
*/ |
|
177 |
public void addTask(AtomicTask task) { |
|
178 |
synchronized (tasks) { |
|
179 |
tasks.addLast(task); |
|
180 |
tasks.notify(); |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Gets the next task in the list |
|
186 |
* @return |
|
187 |
*/ |
|
188 |
public AtomicTask getNext() { |
|
189 |
AtomicTask returnVal = null; |
|
190 |
synchronized (tasks) { |
|
191 |
while (tasks.isEmpty()) { |
|
192 |
try { |
|
193 |
tasks.wait(); |
|
194 |
} catch (InterruptedException ex) { |
|
195 |
System.err.println("Interrupted"); |
|
196 |
} |
|
197 |
} |
|
198 |
if(priorityActive) |
|
199 |
sort(tasks); |
|
200 |
returnVal = tasks.removeFirst(); |
|
201 |
} |
|
202 |
return returnVal; |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* Sorts the array of tasks. Each atomic task have to implement AtomicTask interface |
|
207 |
* which is Runnable and Comparable. The last one allow to sort the array |
|
208 |
* by priorities. |
|
209 |
* @param tasks |
|
210 |
*/ |
|
211 |
private void sort(LinkedList<AtomicTask> tasks) { |
|
212 |
Collections.sort(tasks); |
|
213 |
} |
|
214 |
} |
|
0 | 215 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/disk/DefaultFileSystemStrategy.java | ||
---|---|---|
1 |
package org.gvsig.raster.cache.tile.impl.disk; |
|
2 |
|
|
3 |
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy; |
|
4 |
|
|
5 |
|
|
6 |
public abstract class DefaultFileSystemStrategy implements ITileFileSystemStrategy { |
|
7 |
|
|
8 |
private String tileNameSuffix; |
|
9 |
private final static String DEFAULT_TILE_SUFFIX = ".tile.gvsig"; |
|
10 |
|
|
11 |
public DefaultFileSystemStrategy() { |
|
12 |
|
|
13 |
} |
|
14 |
|
|
15 |
public DefaultFileSystemStrategy(String tileNameSuffix) { |
|
16 |
this.tileNameSuffix = tileNameSuffix; |
|
17 |
} |
|
18 |
|
|
19 |
public String getTileNameSuffix() { |
|
20 |
if (tileNameSuffix == null) |
|
21 |
return DEFAULT_TILE_SUFFIX; |
|
22 |
return this.tileNameSuffix; |
|
23 |
} |
|
24 |
|
|
25 |
public void setTileNameSuffix(String suffix) { |
|
26 |
this.tileNameSuffix = suffix; |
|
27 |
} |
|
28 |
} |
|
0 | 29 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/disk/FlatXFileSystemStrategy.java | ||
---|---|---|
1 |
/* TileRasterCache, a library to download tiles from several sources. |
|
2 |
* |
|
3 |
* Copyright (C) 2010 Prodevelop SL. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Prodevelop Integraci�n de Tecnolog�as SL |
|
22 |
* Plaza don Juan de Vilarrasa , 14-5 |
|
23 |
* 46000 Valencia |
|
24 |
* Spain |
|
25 |
* |
|
26 |
* +34 963 510 612 |
|
27 |
* +34 963 510 968 |
|
28 |
* gis@prodevelop.es |
|
29 |
* http://www.prodevelop.es |
|
30 |
* |
|
31 |
* author: Alberto Romeu Carrasco (aromeu@prodevelop.es) |
|
32 |
*/ |
|
33 |
|
|
34 |
package org.gvsig.raster.cache.tile.impl.disk; |
|
35 |
|
|
36 |
import java.io.File; |
|
37 |
|
|
38 |
|
|
39 |
/** |
|
40 |
* This IFileSystemStrategy creates a directory for each zoom level of a layer. |
|
41 |
* Inside the directory of a zoom level, creates a directory for each X row and |
|
42 |
* inside the directory of an X row stores a file with the Y row, so |
|
43 |
* OSM/0/0/0.tile represents the tile http://osm/0/0/0.png |
|
44 |
* |
|
45 |
* This strategy is the most spread for mobile map viewers (although is not the most efficient) |
|
46 |
* @author aromeu |
|
47 |
* |
|
48 |
*/ |
|
49 |
public class FlatXFileSystemStrategy extends DefaultFileSystemStrategy { |
|
50 |
|
|
51 |
public FlatXFileSystemStrategy() { |
|
52 |
super(); |
|
53 |
} |
|
54 |
|
|
55 |
public FlatXFileSystemStrategy(String tileNameSuffix) { |
|
56 |
super(tileNameSuffix); |
|
57 |
} |
|
58 |
|
|
59 |
public String getRelativeToLayerDirTilePath(int row, |
|
60 |
int col, |
|
61 |
int zoomLevel, |
|
62 |
String var, |
|
63 |
String z, |
|
64 |
String time) { |
|
65 |
if(zoomLevel < 0) { //Real zoom level |
|
66 |
return new StringBuffer() |
|
67 |
.append(var) |
|
68 |
.append(File.separator) |
|
69 |
.append(z) |
|
70 |
.append(File.separator) |
|
71 |
.append(time) |
|
72 |
.append(File.separator) |
|
73 |
.append("real") |
|
74 |
.append(File.separator) |
|
75 |
.append(col) |
|
76 |
.append(File.separator) |
|
77 |
.append(row).toString(); |
|
78 |
} else { |
|
79 |
return new StringBuffer() |
|
80 |
.append(var) |
|
81 |
.append(File.separator) |
|
82 |
.append(z) |
|
83 |
.append(File.separator) |
|
84 |
.append(time) |
|
85 |
.append(File.separator) |
|
86 |
.append(zoomLevel) |
|
87 |
.append(File.separator) |
|
88 |
.append(col) |
|
89 |
.append(File.separator) |
|
90 |
.append(row).toString(); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
public String getLayerNameSuffix() { |
|
95 |
return "_flatx"; |
|
96 |
} |
|
97 |
|
|
98 |
public String getName() { |
|
99 |
return FLATX; |
|
100 |
} |
|
101 |
} |
|
0 | 102 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/provider/TileMatrixLimits.java | ||
---|---|---|
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.cache.tile.impl.provider; |
|
23 |
|
|
24 |
import java.awt.geom.Point2D; |
|
25 |
|
|
26 |
/** |
|
27 |
* Limits of a tile matrix |
|
28 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
29 |
*/ |
|
30 |
public class TileMatrixLimits { |
|
31 |
private TileMatrix tileMatrix = null; |
|
32 |
private int minTileRow = 0; |
|
33 |
private int maxTileRow = 0; |
|
34 |
private int minTileCol = 0; |
|
35 |
private int maxTileCol = 0; |
|
36 |
|
|
37 |
public TileMatrix getTileMatrix() { |
|
38 |
if(tileMatrix == null) |
|
39 |
tileMatrix = new TileMatrix(); |
|
40 |
return tileMatrix; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Gets the upper left corner and the lower right corner of the |
|
45 |
* selected tile |
|
46 |
* @param x X tile position |
|
47 |
* @param y Y tile position |
|
48 |
* @return |
|
49 |
*/ |
|
50 |
public Point2D[] getTileExtent(int x, int y) { |
|
51 |
double sizeTile = getTileMatrix().getTileWidth() * getTileMatrix().getScaleDenominator(); |
|
52 |
double initX = getTileMatrix().getTopLeftCorner()[0] + (sizeTile * x); |
|
53 |
double initY = getTileMatrix().getTopLeftCorner()[1] - (sizeTile * y); |
|
54 |
Point2D[] p = new Point2D[2]; |
|
55 |
p[0] = new Point2D.Double(initX, initY); |
|
56 |
p[1] = new Point2D.Double(initX + sizeTile, initY - sizeTile); |
|
57 |
return p; |
|
58 |
} |
|
59 |
|
|
60 |
public int getMinTileRow() { |
|
61 |
return minTileRow; |
|
62 |
} |
|
63 |
|
|
64 |
public void setMinTileRow(int minTileRow) { |
|
65 |
this.minTileRow = minTileRow; |
|
66 |
} |
|
67 |
|
|
68 |
public int getMaxTileRow() { |
|
69 |
return maxTileRow; |
|
70 |
} |
|
71 |
|
|
72 |
public void setMaxTileRow(int maxTileRow) { |
|
73 |
this.maxTileRow = maxTileRow; |
|
74 |
} |
|
75 |
|
|
76 |
public int getMinTileCol() { |
|
77 |
return minTileCol; |
|
78 |
} |
|
79 |
|
|
80 |
public void setMinTileCol(int minTileCol) { |
|
81 |
this.minTileCol = minTileCol; |
|
82 |
} |
|
83 |
|
|
84 |
public int getMaxTileCol() { |
|
85 |
return maxTileCol; |
|
86 |
} |
|
87 |
|
|
88 |
public void setMaxTileCol(int maxTileCol) { |
|
89 |
this.maxTileCol = maxTileCol; |
|
90 |
} |
|
91 |
|
|
92 |
public void print() { |
|
93 |
System.out.println(" *****TileMatrixLimits******"); |
|
94 |
System.out.println(" MaxTileCol:" + getMaxTileCol()); |
|
95 |
System.out.println(" MaxTileRow:" + getMaxTileRow()); |
|
96 |
System.out.println(" MinTileCol:" + getMinTileCol()); |
|
97 |
System.out.println(" MinTileRow:" + getMinTileRow()); |
|
98 |
if(tileMatrix != null) |
|
99 |
tileMatrix.print(); |
|
100 |
} |
|
101 |
} |
|
0 | 102 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.39/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/provider/DefaultCacheStruct.java | ||
---|---|---|
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.cache.tile.impl.provider; |
|
23 |
|
|
24 |
import java.awt.geom.Point2D; |
|
25 |
import java.awt.geom.Rectangle2D; |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.raster.cache.tile.Tile; |
|
30 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
|
31 |
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy; |
|
32 |
import org.gvsig.raster.cache.tile.exception.TileBuildException; |
|
33 |
import org.gvsig.raster.cache.tile.impl.TileImpl; |
|
34 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
|
35 |
|
|
36 |
/** |
|
37 |
* Implementation for a structure of a cache |
|
38 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
39 |
*/ |
|
40 |
public class DefaultCacheStruct implements CacheStruct { |
|
41 |
private TileMatrixSet tileMatrixSet = null; |
|
42 |
private ArrayList<TileMatrixLimits> limits = null; |
|
43 |
private String layerName = null; |
|
44 |
private String uri = null; |
|
45 |
private Rectangle2D worldExtent = null; |
|
46 |
private String fileSuffix = null; |
|
47 |
private String epsg = null; |
|
48 |
private long fileSize = 0; |
|
49 |
private double realPixelSize = 0; |
|
50 |
private Rectangle2D layerExtent = null; |
|
51 |
|
|
52 |
public DefaultCacheStruct(int typeOfCoords, |
|
53 |
int levels, |
|
54 |
Rectangle2D layerExtent, |
|
55 |
double pixelSize, |
|
56 |
int tilePxWidth, |
|
57 |
int tilePxHeight, |
|
58 |
String uri, |
|
59 |
String layerName, |
|
60 |
ITileFileSystemStrategy strategy, |
|
61 |
String baseDir, |
|
62 |
String fileSuffix, |
|
63 |
String epsg, |
|
64 |
long size) { |
|
65 |
this.uri = uri; |
|
66 |
this.layerName = layerName; |
|
67 |
this.fileSuffix = fileSuffix; |
|
68 |
this.fileSize = size; |
|
69 |
this.realPixelSize = pixelSize; |
|
70 |
this.layerExtent = layerExtent; |
|
71 |
if(epsg != null && epsg.startsWith("EPSG:")) |
|
72 |
this.epsg = epsg; |
|
73 |
|
|
74 |
//Coordenadas del mundo en geogr�ficas y planas |
|
75 |
|
|
76 |
if(typeOfCoords == CacheStruct.GEOGRAFIC) { |
|
77 |
worldExtent = new Rectangle2D.Double(-180, -90, 360, 180); |
|
78 |
} |
|
79 |
if(typeOfCoords == CacheStruct.FLAT) { |
|
80 |
worldExtent = new Rectangle2D.Double(-20037508, -20037508, 40075016, 40075016); |
|
81 |
} |
|
82 |
|
|
83 |
double[] pixelSizeList = buildWorldMatrix(typeOfCoords, levels, tilePxWidth, tilePxHeight, worldExtent); |
|
84 |
buildLayerMatrix(levels, tilePxWidth, tilePxHeight, worldExtent, layerExtent, pixelSizeList, pixelSize); |
|
85 |
} |
|
86 |
|
|
87 |
private void buildLayerMatrix(int levels, |
|
88 |
int tilePxWidth, |
|
89 |
int tilePxHeight, |
|
90 |
Rectangle2D worldExtent, |
|
91 |
Rectangle2D layerExtent, |
|
92 |
double[] pixelSizeList, |
|
93 |
double maxPixelSize) { |
|
94 |
limits = new ArrayList<TileMatrixLimits>(); |
|
95 |
|
|
96 |
for (int i = 0; i < levels; i++) { |
|
97 |
//Calculo de tiles para ese nivel en la capa actual |
|
98 |
int minTileCol = (int)(Math.abs(layerExtent.getMinX() - worldExtent.getMinX()) / pixelSizeList[i]) / tilePxWidth; |
|
99 |
int minTileRow = (int)(Math.abs(layerExtent.getMaxY() - worldExtent.getMaxY()) / pixelSizeList[i]) / tilePxHeight; |
|
100 |
int maxTileCol = (int)(Math.abs(layerExtent.getMaxX() - worldExtent.getMinX()) / pixelSizeList[i]) / tilePxWidth; |
|
101 |
int maxTileRow = (int)(Math.abs(layerExtent.getMinY() - worldExtent.getMaxY()) / pixelSizeList[i]) / tilePxHeight; |
|
102 |
|
|
103 |
//int imageTileWidth = (int)Math.ceil((layerExtent.getWidth() / pixelSizeList[i]) / tilePxWidth); |
|
104 |
//int imageTileHeight = (int)Math.ceil((layerExtent.getHeight() / pixelSizeList[i]) / tilePxHeight); |
|
105 |
TileMatrixLimits limit = new TileMatrixLimits(); |
|
106 |
limit.setMinTileRow(minTileRow); |
|
107 |
limit.setMinTileCol(minTileCol); |
|
108 |
limit.setMaxTileRow(maxTileRow); |
|
109 |
limit.setMaxTileCol(maxTileCol); |
|
110 |
|
|
111 |
//Calcula las coordenadas de la esquina superior izquierda del TileMatrixLimits |
|
112 |
double ulx = worldExtent.getMinX() + (minTileCol * tilePxWidth * pixelSizeList[i]); |
|
113 |
double uly = worldExtent.getMaxY() - (minTileRow * tilePxHeight * pixelSizeList[i]); |
|
114 |
limit.getTileMatrix().setTopLeftCorner(new double[]{ulx, uly}); |
|
115 |
limit.getTileMatrix().setScaleDenominator(pixelSizeList[i]); |
|
116 |
limit.getTileMatrix().setTileWidth(tilePxWidth); |
|
117 |
limit.getTileMatrix().setTileHeight(tilePxHeight); |
|
118 |
|
|
119 |
limits.add(limit); |
|
120 |
if(i == (levels - 1) || (maxPixelSize != Double.POSITIVE_INFINITY && maxPixelSize != Double.NEGATIVE_INFINITY && pixelSizeList[i] < maxPixelSize)) { |
|
121 |
//System.out.println("Image res:" + maxPixelSize + " Real res:" + pixelSizeList[i]); |
|
122 |
break; |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
private double[] buildWorldMatrix(int typeOfCoords, |
|
128 |
int levels, |
|
129 |
int tilePxWidth, |
|
130 |
int tilePxHeight, |
|
131 |
Rectangle2D worldExtent) { |
|
132 |
double[] pixelSizeList = new double[levels]; |
|
133 |
|
|
134 |
limits = new ArrayList<TileMatrixLimits>(); |
|
135 |
tileMatrixSet = new TileMatrixSet(); |
|
136 |
tileMatrixSet.setBbox(worldExtent); |
|
137 |
|
|
138 |
int nTilesWidth = 0; |
|
139 |
int nTilesHeight = 0; |
|
140 |
|
|
141 |
for (int i = 0; i < levels; i++) { |
|
142 |
TileMatrix tm = new TileMatrix(); |
|
143 |
tm.setTileWidth(tilePxWidth); |
|
144 |
tm.setTileHeight(tilePxHeight); |
|
145 |
if(i == 0) { |
|
146 |
nTilesWidth = (typeOfCoords == CacheStruct.FLAT) ? 1 : 2; |
|
147 |
nTilesHeight = 1; |
|
148 |
} else { |
|
149 |
nTilesWidth *= 2; |
|
150 |
nTilesHeight *= 2; |
|
151 |
} |
Also available in: Unified diff