Revision 85
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.gvsig.raster.osm</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
</buildSpec> |
|
9 |
<natures> |
|
10 |
</natures> |
|
11 |
</projectDescription> |
|
0 | 12 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.raster.osm.io.DefaultOSMIOLibrary |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/downloader/TileDownloaderForOSM.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.downloader; |
|
23 |
|
|
24 |
import java.io.BufferedOutputStream; |
|
25 |
import java.io.DataInputStream; |
|
26 |
import java.io.DataOutputStream; |
|
27 |
import java.io.File; |
|
28 |
import java.io.FileOutputStream; |
|
29 |
import java.net.HttpURLConnection; |
|
30 |
import java.net.MalformedURLException; |
|
31 |
import java.net.URI; |
|
32 |
import java.net.URISyntaxException; |
|
33 |
import java.net.URL; |
|
34 |
|
|
35 |
import org.gvsig.compat.net.ICancellable; |
|
36 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
37 |
import org.gvsig.raster.cache.tile.Tile; |
|
38 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
|
39 |
import org.gvsig.raster.impl.provider.tile.BaseTileDownloader; |
|
40 |
import org.gvsig.raster.osm.io.OSMDataParameters; |
|
41 |
|
|
42 |
/** |
|
43 |
* Tile getter for Open Street Map |
|
44 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
45 |
*/ |
|
46 |
public class TileDownloaderForOSM extends BaseTileDownloader { |
|
47 |
private String server = null; |
|
48 |
private String suffix = null; |
|
49 |
private String slash = "/"; |
|
50 |
|
|
51 |
public TileDownloaderForOSM(RasterDataStore store, |
|
52 |
int tileSize) { |
|
53 |
super(store, tileSize, tileSize); |
|
54 |
server = ((OSMDataParameters)store.getParameters()).getURI(); |
|
55 |
suffix = ((OSMDataParameters)store.getParameters()).getTileSuffix(); |
|
56 |
} |
|
57 |
|
|
58 |
public synchronized Tile downloadTile(Tile tile) throws TileGettingException { |
|
59 |
int level = tile.getLevel(); |
|
60 |
int y = tile.getRow(); |
|
61 |
int x = tile.getCol(); |
|
62 |
try { |
|
63 |
URI uri = new URI( |
|
64 |
server + |
|
65 |
(server.endsWith(slash) ? "" : slash) + |
|
66 |
level + slash + |
|
67 |
x + slash + |
|
68 |
y + "." + suffix); |
|
69 |
|
|
70 |
downloadFile(uri.toURL(), tile.getFile(), tile.getCancelled()); |
|
71 |
} catch (MalformedURLException e) { |
|
72 |
throw new TileGettingException(e); |
|
73 |
} catch (URISyntaxException e) { |
|
74 |
throw new TileGettingException(e); |
|
75 |
} |
|
76 |
readTileFromDisk(tile); |
|
77 |
return tile; |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
public synchronized void downloadFile(URL url, File file, ICancellable cancel) throws TileGettingException { |
|
82 |
int IO_BUFFER_SIZE = 8 * 1024; |
|
83 |
int timeout = 30000; |
|
84 |
|
|
85 |
DataOutputStream dos; |
|
86 |
try { |
|
87 |
DataInputStream is; |
|
88 |
HttpURLConnection connection = null; |
|
89 |
|
|
90 |
connection = (HttpURLConnection)url.openConnection(); |
|
91 |
connection.setConnectTimeout(timeout); |
|
92 |
|
|
93 |
is = new DataInputStream(url.openStream()); |
|
94 |
|
|
95 |
dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(file))); |
|
96 |
byte[] buffer = new byte[IO_BUFFER_SIZE]; |
|
97 |
|
|
98 |
int read; |
|
99 |
while ((read = is.read(buffer)) != -1) { |
|
100 |
dos.write(buffer, 0, read); |
|
101 |
if(cancel != null && cancel.isCanceled()) |
|
102 |
return; |
|
103 |
} |
|
104 |
|
|
105 |
dos.close(); |
|
106 |
is.close(); |
|
107 |
is = null; |
|
108 |
dos = null; |
|
109 |
} catch (Exception e) { |
|
110 |
throw new TileGettingException(e); |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
} |
|
0 | 115 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/downloader/OSMTileServer.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.downloader; |
|
23 |
|
|
24 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
25 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
26 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
|
27 |
import org.gvsig.raster.cache.tile.provider.Downloader; |
|
28 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
29 |
import org.gvsig.raster.osm.cachestruct.OSMCacheStruct; |
|
30 |
import org.gvsig.raster.osm.io.OSMDataParameters; |
|
31 |
|
|
32 |
/** |
|
33 |
* Data server for the tile cache in a OSMProvider |
|
34 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
35 |
*/ |
|
36 |
public class OSMTileServer implements TileServer { |
|
37 |
private CacheStruct struct = null; |
|
38 |
private Downloader downloader = null; |
|
39 |
private RasterDataStore store = null; |
|
40 |
private String suffix = null; |
|
41 |
private int tileSize = 256; |
|
42 |
private int levels = 0; |
|
43 |
|
|
44 |
/** |
|
45 |
* Creates a OSMTileServer |
|
46 |
* @param prov |
|
47 |
* @param suffix |
|
48 |
* it depends on the layer |
|
49 |
* @param levels |
|
50 |
* it depends on the layer |
|
51 |
*/ |
|
52 |
public OSMTileServer(RasterDataStore store, String suffix, int levels) { |
|
53 |
this.store = store; |
|
54 |
this.suffix = suffix; |
|
55 |
this.levels = levels; |
|
56 |
} |
|
57 |
|
|
58 |
public Downloader getDownloader() { |
|
59 |
if(downloader == null) { |
|
60 |
downloader = new TileDownloaderForOSM(store, getStruct().getTileSizeByLevel(0)[0]); |
|
61 |
} |
|
62 |
return downloader; |
|
63 |
} |
|
64 |
|
|
65 |
public CacheStruct getStruct() { |
|
66 |
if(struct == null) { |
|
67 |
struct = new OSMCacheStruct(levels, |
|
68 |
tileSize, |
|
69 |
tileSize, |
|
70 |
((OSMDataParameters)store.getParameters()).getOSMLayerName(), |
|
71 |
RasterLibrary.pathTileCache, |
|
72 |
suffix, |
|
73 |
0); |
|
74 |
} |
|
75 |
return struct; |
|
76 |
} |
|
77 |
|
|
78 |
public void setStruct(CacheStruct struct) { |
|
79 |
//La structura de cache es proporcionada por el servidor |
|
80 |
} |
|
81 |
|
|
82 |
public String getFileSuffix() { |
|
83 |
return suffix; |
|
84 |
} |
|
85 |
|
|
86 |
public void setFileSuffix(String extension) { |
|
87 |
this.suffix = extension; |
|
88 |
} |
|
89 |
} |
|
0 | 90 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/io/OSMServerExplorer.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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 |
|
|
23 |
package org.gvsig.raster.osm.io; |
|
24 |
|
|
25 |
import java.util.List; |
|
26 |
|
|
27 |
import org.gvsig.compat.net.ICancellable; |
|
28 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
29 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
30 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
31 |
import org.gvsig.fmap.dal.coverage.exception.ConnectException; |
|
32 |
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
|
35 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
public class OSMServerExplorer { |
|
40 |
public static final String NAME = OSMProvider.NAME; |
|
41 |
|
|
42 |
public String getProviderName() { |
|
43 |
return OSMProvider.NAME; |
|
44 |
} |
|
45 |
|
|
46 |
public boolean canAdd() { |
|
47 |
return false; |
|
48 |
} |
|
49 |
|
|
50 |
public boolean canAdd(String storeName) throws DataException { |
|
51 |
return false; |
|
52 |
} |
|
53 |
|
|
54 |
public List<?> list() throws DataException { |
|
55 |
return null; |
|
56 |
} |
|
57 |
|
|
58 |
public List<?> list(int mode) throws DataException { |
|
59 |
return null; |
|
60 |
} |
|
61 |
|
|
62 |
public boolean add(String provider, NewDataStoreParameters parameters, |
|
63 |
boolean overwrite) throws DataException { |
|
64 |
return false; |
|
65 |
} |
|
66 |
|
|
67 |
public void remove(DataStoreParameters parameters) throws DataException { |
|
68 |
|
|
69 |
} |
|
70 |
|
|
71 |
public NewDataStoreParameters getAddParameters(String storeName) |
|
72 |
throws DataException { |
|
73 |
return null; |
|
74 |
} |
|
75 |
|
|
76 |
public DataServerExplorerParameters getParameters() { |
|
77 |
return null; |
|
78 |
} |
|
79 |
|
|
80 |
public List<?> getDataStoreProviderNames() { |
|
81 |
return null; |
|
82 |
} |
|
83 |
|
|
84 |
public void dispose() { |
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() { |
|
89 |
return null; |
|
90 |
} |
|
91 |
|
|
92 |
public DataStoreParameters getStoredParameters() { |
|
93 |
return null; |
|
94 |
} |
|
95 |
|
|
96 |
public void connect(ICancellable cancellable) throws ConnectException { |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
public boolean isHostReachable(int timeout) { |
|
101 |
return false; |
|
102 |
} |
|
103 |
|
|
104 |
public boolean isHostReachable() { |
|
105 |
return isHostReachable(RasterDataServerExplorer.TIME); |
|
106 |
} |
|
107 |
|
|
108 |
} |
|
0 | 109 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/io/OSMProvider.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.io; |
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
|
|
26 |
import org.cresques.cts.IProjection; |
|
27 |
import org.gvsig.fmap.crs.CRSFactory; |
|
28 |
import org.gvsig.fmap.dal.DALLocator; |
|
29 |
import org.gvsig.fmap.dal.DataStore; |
|
30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
32 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
33 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
34 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
35 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
36 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
37 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
38 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
39 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
40 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
41 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
42 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
43 |
import org.gvsig.metadata.MetadataLocator; |
|
44 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
45 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
|
46 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
47 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
|
48 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
49 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
50 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
|
51 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
|
52 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
|
53 |
import org.gvsig.raster.osm.cachestruct.OSMCacheStruct; |
|
54 |
import org.gvsig.raster.osm.downloader.OSMTileServer; |
|
55 |
import org.gvsig.tools.ToolsLocator; |
|
56 |
import org.slf4j.Logger; |
|
57 |
import org.slf4j.LoggerFactory; |
|
58 |
/** |
|
59 |
* Data provider for OSM servers |
|
60 |
* |
|
61 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
62 |
*/ |
|
63 |
public class OSMProvider extends AbstractRasterProvider { |
|
64 |
public static String NAME = "OSM Raster"; |
|
65 |
public static String DESCRIPTION = "OSM Raster Server"; |
|
66 |
public final String METADATA_DEFINITION_NAME = NAME; |
|
67 |
private Extent viewRequest = null; |
|
68 |
private TileServer tileServer = null; |
|
69 |
private boolean open = false; |
|
70 |
private DataStoreTransparency fileTransparency = null; |
|
71 |
private static final Logger logger = LoggerFactory.getLogger(OSMProvider.class); |
|
72 |
|
|
73 |
public static void register() { |
|
74 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
75 |
|
|
76 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
77 |
dataman.registerStoreProvider(NAME, |
|
78 |
OSMProvider.class, OSMDataParametersImpl.class); |
|
79 |
} |
|
80 |
|
|
81 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
82 |
} |
|
83 |
|
|
84 |
public OSMProvider() { |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Opens the dataset. |
|
89 |
* @param proj Projection |
|
90 |
* @param fName File name |
|
91 |
* @throws NotSupportedExtensionException |
|
92 |
*/ |
|
93 |
public OSMProvider(String params) throws NotSupportedExtensionException, OpenException { |
|
94 |
super(params); |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
public OSMProvider (OSMDataParametersImpl params, |
|
99 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
100 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
101 |
.createDynObject( |
|
102 |
MetadataLocator.getMetadataManager().getDefinition( |
|
103 |
DataStore.METADATA_DEFINITION_NAME))); |
|
104 |
init(params, storeServices); |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* Build file references |
|
109 |
* @param proj Projection |
|
110 |
* @param param Load parameters |
|
111 |
* @throws NotSupportedExtensionException |
|
112 |
*/ |
|
113 |
public void init (OSMDataParametersImpl params, |
|
114 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
115 |
setParam(storeServices, params); |
|
116 |
setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE}); |
|
117 |
bandCount = 4; |
|
118 |
super.init(); |
|
119 |
fileSize = (long)(getWidth() * getHeight() * 3); |
|
120 |
|
|
121 |
Extent ext = getExtent(); |
|
122 |
ownTransformation = new AffineTransform( |
|
123 |
ext.width() / getWidth(), 0, |
|
124 |
0, -(ext.height() / getHeight()), |
|
125 |
getExtent().getMin().getX(), |
|
126 |
getExtent().getMax().getY()); |
|
127 |
externalTransformation = (AffineTransform)ownTransformation.clone(); |
|
128 |
open = true; |
|
129 |
} |
|
130 |
|
|
131 |
public IProjection getProjection() { |
|
132 |
if(proj == null) { |
|
133 |
try { |
|
134 |
proj = CRSFactory.getCRS("EPSG:3785"); |
|
135 |
} catch(Exception e) { |
|
136 |
logger.info("Projection not loaded", e); |
|
137 |
} |
|
138 |
} |
|
139 |
return proj; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* Gets the bounding box in world coordinates. |
|
144 |
* @return Extent |
|
145 |
*/ |
|
146 |
public Extent getExtent() { |
|
147 |
return ((OSMCacheStruct)getTileServer().getStruct()).getWorldExtent(); |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* Reloads metadata using the selected grid |
|
152 |
*/ |
|
153 |
@SuppressWarnings("unused") |
|
154 |
private void reloadMetadataFromGrid() { |
|
155 |
//wktProjection = null; |
|
156 |
//CrsWkt crs = new CrsWkt(wktProjection); |
|
157 |
//IProjection proj = CRSFactory.getCRS("EPSG:23030"); |
|
158 |
|
|
159 |
/*ownTransformation = new AffineTransform( |
|
160 |
scaleX, 0, |
|
161 |
0, -scaleY, |
|
162 |
pRect.getMinX(), |
|
163 |
pRect.getMaxY());*/ |
|
164 |
externalTransformation = (AffineTransform)ownTransformation.clone(); |
|
165 |
bandCount = 3; |
|
166 |
setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE}); |
|
167 |
} |
|
168 |
|
|
169 |
public RasterProvider load() { |
|
170 |
return this; |
|
171 |
} |
|
172 |
|
|
173 |
public boolean isOpen() { |
|
174 |
return open; |
|
175 |
} |
|
176 |
|
|
177 |
public void close() { |
|
178 |
} |
|
179 |
|
|
180 |
public String translateFileName(String fileName) { |
|
181 |
return fileName; |
|
182 |
} |
|
183 |
|
|
184 |
public NoData getNoDataValue() { |
|
185 |
NoData nodata = super.getNoDataValue(); |
|
186 |
if(nodata != null) |
|
187 |
nodata.setNoDataTransparent(false); |
|
188 |
return noData; |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci�n |
|
193 |
* de la vista asignada ya que la petici�n viene en coordenadas del fichero .rmf y la vista (v) |
|
194 |
* ha de estar en coordenadas del fichero. |
|
195 |
*/ |
|
196 |
public void setView(Extent e) { |
|
197 |
viewRequest = new ExtentImpl(e); |
|
198 |
} |
|
199 |
|
|
200 |
public Extent getView() { |
|
201 |
return viewRequest; |
|
202 |
} |
|
203 |
|
|
204 |
public double getWidth() { |
|
205 |
int n = getTileServer().getStruct().getNumberOfLevels() - 1; |
|
206 |
return getExtent().width() / getTileServer().getStruct().getPixelSizeByLevel(n); |
|
207 |
} |
|
208 |
|
|
209 |
public double getHeight() { |
|
210 |
int n = getTileServer().getStruct().getNumberOfLevels() - 1; |
|
211 |
return getExtent().width() / getTileServer().getStruct().getPixelSizeByLevel(n); |
|
212 |
} |
|
213 |
|
|
214 |
public Object readBlock(int pos, int blockHeight, double scale) |
|
215 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
|
216 |
return null; |
|
217 |
} |
|
218 |
|
|
219 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
220 |
return null; |
|
221 |
} |
|
222 |
|
|
223 |
public int getBlockSize(){ |
|
224 |
return 0; |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* Informa de si el driver ha supersampleado en el �ltimo dibujado. Es el driver el que colocar� |
|
229 |
* el valor de esta variable cada vez que dibuja. |
|
230 |
* @return true si se ha supersampleado y false si no se ha hecho. |
|
231 |
*/ |
|
232 |
public boolean isSupersampling() { |
|
233 |
return false; |
|
234 |
} |
|
235 |
|
|
236 |
public void setAffineTransform(AffineTransform t){ |
|
237 |
super.setAffineTransform(t); |
|
238 |
} |
|
239 |
|
|
240 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
|
241 |
if(band >= getBandCount()) |
|
242 |
throw new BandAccessException("Wrong band"); |
|
243 |
return 0; |
|
244 |
} |
|
245 |
|
|
246 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
|
247 |
if (band >= getBandCount()) |
|
248 |
throw new BandAccessException("Wrong band"); |
|
249 |
return 0; |
|
250 |
} |
|
251 |
|
|
252 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
|
253 |
if (band >= getBandCount()) |
|
254 |
throw new BandAccessException("Wrong band"); |
|
255 |
return 0; |
|
256 |
} |
|
257 |
|
|
258 |
public boolean isOverviewsSupported() { |
|
259 |
return true; |
|
260 |
} |
|
261 |
|
|
262 |
public boolean isReproyectable() { |
|
263 |
return true; |
|
264 |
} |
|
265 |
|
|
266 |
public String getName() { |
|
267 |
return NAME; |
|
268 |
} |
|
269 |
|
|
270 |
public DataStoreTransparency getTransparency() { |
|
271 |
if(fileTransparency == null) |
|
272 |
fileTransparency = new DataStoreTransparency(getColorInterpretation()); |
|
273 |
return fileTransparency; |
|
274 |
} |
|
275 |
|
|
276 |
public ColorInterpretation getColorInterpretation() { |
|
277 |
if(super.getColorInterpretation() == null) { |
|
278 |
super.setColorInterpretation(DataStoreColorInterpretation.createRGBInterpretation()); |
|
279 |
} |
|
280 |
return super.getColorInterpretation(); |
|
281 |
} |
|
282 |
|
|
283 |
public void setStatus(RasterProvider provider) { |
|
284 |
if(provider instanceof OSMProvider) { |
|
285 |
//Not implemented yet |
|
286 |
} |
|
287 |
} |
|
288 |
|
|
289 |
public boolean isTimeSupported() { |
|
290 |
return true; |
|
291 |
} |
|
292 |
|
|
293 |
public boolean isTiled() { |
|
294 |
return true; |
|
295 |
} |
|
296 |
|
|
297 |
public TileServer getTileServer() { |
|
298 |
if(tileServer == null) { |
|
299 |
DefaultRasterStore store = new DefaultRasterStore(); |
|
300 |
store.setProvider(this); |
|
301 |
tileServer = new OSMTileServer(store, |
|
302 |
((OSMDataParameters)param).getTileSuffix(), |
|
303 |
((OSMDataParameters)param).getNumberOfLevels()); |
|
304 |
} |
|
305 |
return tileServer; |
|
306 |
} |
|
307 |
|
|
308 |
@Override |
|
309 |
public void loadBuffer(SpiRasterQuery query) |
|
310 |
throws ProcessInterruptedException, RasterDriverException { |
|
311 |
|
|
312 |
} |
|
313 |
} |
|
0 | 314 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/io/OSMDataParameters.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.io; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* Parameters for the WMS provider |
|
27 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
28 |
*/ |
|
29 |
public interface OSMDataParameters { |
|
30 |
public void setURI(String string); |
|
31 |
|
|
32 |
public String getURI(); |
|
33 |
|
|
34 |
public int getWidth(); |
|
35 |
|
|
36 |
public int getHeight(); |
|
37 |
|
|
38 |
public void setWidth(int w); |
|
39 |
|
|
40 |
public void setHeight(int h); |
|
41 |
|
|
42 |
public String getOSMLayerName(); |
|
43 |
|
|
44 |
public void setOSMLayerName(String name); |
|
45 |
|
|
46 |
public int getNumberOfLevels(); |
|
47 |
|
|
48 |
public void setNumberOfLevels(int levels); |
|
49 |
|
|
50 |
public String getTileSuffix(); |
|
51 |
|
|
52 |
public void setTileSuffix(String suffix); |
|
53 |
} |
|
0 | 54 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/io/OSMException.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.io; |
|
23 |
|
|
24 |
import java.util.Hashtable; |
|
25 |
import java.util.Map; |
|
26 |
|
|
27 |
/** |
|
28 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
29 |
*/ |
|
30 |
public class OSMException extends Exception { |
|
31 |
private static final long serialVersionUID = 1476084093500156070L; |
|
32 |
private String wmtsCode = null; |
|
33 |
protected String formatString = null; |
|
34 |
protected String messageKey = null; |
|
35 |
protected long code = 0; |
|
36 |
|
|
37 |
public OSMException() { |
|
38 |
init(); |
|
39 |
} |
|
40 |
|
|
41 |
public OSMException(Throwable cause) { |
|
42 |
super(cause); |
|
43 |
init(); |
|
44 |
initCause(cause); |
|
45 |
} |
|
46 |
|
|
47 |
public OSMException(String msg, Throwable cause) { |
|
48 |
super(msg, cause); |
|
49 |
init(); |
|
50 |
this.formatString = msg; |
|
51 |
} |
|
52 |
|
|
53 |
public OSMException(String wfsCode,String message) { |
|
54 |
init(); |
|
55 |
formatString = message; |
|
56 |
this.wmtsCode = wfsCode; |
|
57 |
} |
|
58 |
|
|
59 |
public OSMException(String message) { |
|
60 |
init(); |
|
61 |
formatString = message; |
|
62 |
} |
|
63 |
|
|
64 |
@SuppressWarnings("unchecked") |
|
65 |
protected Map values() { |
|
66 |
Hashtable params; |
|
67 |
params = new Hashtable(); |
|
68 |
return params; |
|
69 |
} |
|
70 |
|
|
71 |
public void init() { |
|
72 |
messageKey = "wmts_exception"; |
|
73 |
formatString = "WMTS Exception"; |
|
74 |
code = serialVersionUID; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* @return Returns the wfsCode. |
|
79 |
*/ |
|
80 |
public String getWfsCode() { |
|
81 |
return wmtsCode; |
|
82 |
} |
|
83 |
} |
|
0 | 84 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/io/OSMDataParametersImpl.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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 |
|
|
23 |
package org.gvsig.raster.osm.io; |
|
24 |
|
|
25 |
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer; |
|
26 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
27 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
30 |
import org.gvsig.tools.dynobject.DynStruct; |
|
31 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
32 |
|
|
33 |
/** |
|
34 |
* Parameters for OSM provider |
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
36 |
*/ |
|
37 |
public class OSMDataParametersImpl extends AbstractRasterDataParameters implements OSMDataParameters { |
|
38 |
private DelegatedDynObject delegatedDynObject = null; |
|
39 |
private static final String FIELD_WIDTH = "width"; |
|
40 |
private static final String FIELD_HEIGHT = "height"; |
|
41 |
private static final String FIELD_MAX_RES_LEVEL = "maxResolutionLevel"; |
|
42 |
private static final String FIELD_NAME = "name"; |
|
43 |
private static final String FIELD_SUFFIX = "suffix"; |
|
44 |
|
|
45 |
public OSMDataParametersImpl() { |
|
46 |
super(); |
|
47 |
initialize(); |
|
48 |
} |
|
49 |
|
|
50 |
protected void initialize() { |
|
51 |
this.delegatedDynObject = (DelegatedDynObject) ToolsLocator |
|
52 |
.getDynObjectManager().createDynObject(registerDynClass()); |
|
53 |
} |
|
54 |
|
|
55 |
public static DynStruct registerDynClass() { |
|
56 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
57 |
DynStruct definition = manager.getDefinition("OSMDataParameters_Persistent"); |
|
58 |
if( definition == null ) { |
|
59 |
definition = manager.addDefinition( |
|
60 |
OSMDataParametersImpl.class, |
|
61 |
"OSMDataParameters_Persistent", |
|
62 |
"OSM DataParameters Persistency", |
|
63 |
null, |
|
64 |
null |
|
65 |
); |
|
66 |
} |
|
67 |
|
|
68 |
AbstractRasterDataParameters.registerDynClass(definition); |
|
69 |
|
|
70 |
definition.addDynFieldInt(FIELD_MAX_RES_LEVEL) |
|
71 |
.setDescription("Maximun levels of resolution") |
|
72 |
.setMandatory(false); |
|
73 |
|
|
74 |
definition.addDynFieldInt(FIELD_WIDTH) |
|
75 |
.setDescription("Width") |
|
76 |
.setMandatory(false); |
|
77 |
|
|
78 |
definition.addDynFieldInt(FIELD_HEIGHT) |
|
79 |
.setDescription("Height") |
|
80 |
.setMandatory(false); |
|
81 |
|
|
82 |
definition.addDynFieldString(FIELD_NAME) |
|
83 |
.setDescription("Layer name") |
|
84 |
.setMandatory(false); |
|
85 |
|
|
86 |
definition.addDynFieldString(FIELD_SUFFIX) |
|
87 |
.setDescription("Field suffix") |
|
88 |
.setMandatory(false); |
|
89 |
|
|
90 |
return definition; |
|
91 |
} |
|
92 |
|
|
93 |
public void assignFields(RasterDataParameters par, RasterDataServerExplorer explorer) { |
|
94 |
super.assignFields(par, explorer); |
|
95 |
|
|
96 |
OSMDataParameters p = null; |
|
97 |
if(par instanceof OSMDataParameters) |
|
98 |
p = (OSMDataParameters)par; |
|
99 |
else |
|
100 |
return; |
|
101 |
|
|
102 |
setTileSuffix(p.getTileSuffix()); |
|
103 |
setOSMLayerName(p.getOSMLayerName()); |
|
104 |
setWidth(p.getWidth()); |
|
105 |
setHeight(p.getHeight()); |
|
106 |
setNumberOfLevels(p.getNumberOfLevels()); |
|
107 |
} |
|
108 |
|
|
109 |
public String getDataStoreName() { |
|
110 |
return OSMProvider.NAME; |
|
111 |
} |
|
112 |
|
|
113 |
public String getDescription() { |
|
114 |
return OSMProvider.DESCRIPTION; |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
119 |
return delegatedDynObject; |
|
120 |
} |
|
121 |
|
|
122 |
public boolean isOverridingHost() { |
|
123 |
return false; |
|
124 |
} |
|
125 |
|
|
126 |
public void setOverrideHost(boolean over) { |
|
127 |
|
|
128 |
} |
|
129 |
|
|
130 |
public void setWidth(int w) { |
|
131 |
this.setDynValue(FIELD_WIDTH, new Integer(w)); |
|
132 |
} |
|
133 |
|
|
134 |
public void setHeight(int h) { |
|
135 |
this.setDynValue(FIELD_HEIGHT, new Integer(h)); |
|
136 |
} |
|
137 |
|
|
138 |
public int getWidth() { |
|
139 |
Integer b = (Integer)getDynValue(FIELD_WIDTH); |
|
140 |
if(b != null) |
|
141 |
return ((Integer)b).intValue(); |
|
142 |
return 0; |
|
143 |
} |
|
144 |
|
|
145 |
public int getHeight() { |
|
146 |
Integer b = (Integer)getDynValue(FIELD_HEIGHT); |
|
147 |
if(b != null) |
|
148 |
return ((Integer)b).intValue(); |
|
149 |
return 0; |
|
150 |
} |
|
151 |
|
|
152 |
public String getOSMLayerName() { |
|
153 |
String b = (String)getDynValue(FIELD_NAME); |
|
154 |
if(b != null) |
|
155 |
return b; |
|
156 |
return null; |
|
157 |
} |
|
158 |
|
|
159 |
public void setOSMLayerName(String name) { |
|
160 |
this.setDynValue(FIELD_NAME, name); |
|
161 |
} |
|
162 |
|
|
163 |
public int getNumberOfLevels() { |
|
164 |
Integer b = (Integer)getDynValue(FIELD_MAX_RES_LEVEL); |
|
165 |
if(b != null) |
|
166 |
return ((Integer)b).intValue(); |
|
167 |
return 0; |
|
168 |
} |
|
169 |
|
|
170 |
public void setNumberOfLevels(int levels) { |
|
171 |
this.setDynValue(FIELD_MAX_RES_LEVEL, new Integer(levels)); |
|
172 |
} |
|
173 |
|
|
174 |
public String getTileSuffix() { |
|
175 |
String b = (String)getDynValue(FIELD_SUFFIX); |
|
176 |
if(b != null) |
|
177 |
return b; |
|
178 |
return null; |
|
179 |
} |
|
180 |
|
|
181 |
public void setTileSuffix(String suffix) { |
|
182 |
this.setDynValue(FIELD_SUFFIX, suffix); |
|
183 |
} |
|
184 |
} |
|
0 | 185 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/io/DefaultOSMIOLibrary.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.io; |
|
23 |
|
|
24 |
import org.gvsig.tools.library.AbstractLibrary; |
|
25 |
import org.gvsig.tools.library.LibraryException; |
|
26 |
/** |
|
27 |
* |
|
28 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
29 |
*/ |
|
30 |
public class DefaultOSMIOLibrary extends AbstractLibrary { |
|
31 |
|
|
32 |
@Override |
|
33 |
protected void doInitialize() throws LibraryException { |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
protected void doPostInitialize() throws LibraryException { |
|
38 |
OSMProvider.register(); |
|
39 |
OSMDataParametersImpl.registerDynClass(); |
|
40 |
} |
|
41 |
} |
|
0 | 42 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/cachestruct/TileMatrix.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.cachestruct; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* Description of a tile matrix |
|
27 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
28 |
*/ |
|
29 |
public class TileMatrix { |
|
30 |
private double scaleXDenominator = 0; |
|
31 |
private double scaleYDenominator = 0; |
|
32 |
private double[] topLeftCorner = null; |
|
33 |
private int tileWidth = 0; |
|
34 |
private int tileHeight = 0; |
|
35 |
private long matrixWidth = 0; |
|
36 |
private long matrixHeight = 0; |
|
37 |
private static final double MTS_X_GRADO = 111319.490793274; |
|
38 |
|
|
39 |
public double getScaleXDenominator() { |
|
40 |
return scaleXDenominator; |
|
41 |
} |
|
42 |
|
|
43 |
public void setScaleXDenominator(double scaleXDenominator) { |
|
44 |
this.scaleXDenominator = scaleXDenominator; |
|
45 |
} |
|
46 |
|
|
47 |
public double getScaleYDenominator() { |
|
48 |
return scaleYDenominator; |
|
49 |
} |
|
50 |
|
|
51 |
public void setScaleYDenominator(double scaleYDenominator) { |
|
52 |
this.scaleYDenominator = scaleYDenominator; |
|
53 |
} |
|
54 |
|
|
55 |
public int getTileWidth() { |
|
56 |
return tileWidth; |
|
57 |
} |
|
58 |
|
|
59 |
public void setTileWidth(int tileWidth) { |
|
60 |
this.tileWidth = tileWidth; |
|
61 |
} |
|
62 |
|
|
63 |
public int getTileHeight() { |
|
64 |
return tileHeight; |
|
65 |
} |
|
66 |
|
|
67 |
public void setTileHeight(int tileHeight) { |
|
68 |
this.tileHeight = tileHeight; |
|
69 |
} |
|
70 |
|
|
71 |
public long getMatrixWidth() { |
|
72 |
return matrixWidth; |
|
73 |
} |
|
74 |
|
|
75 |
public void setMatrixWidth(long matrixWidth) { |
|
76 |
this.matrixWidth = matrixWidth; |
|
77 |
} |
|
78 |
|
|
79 |
public long getMatrixHeight() { |
|
80 |
return matrixHeight; |
|
81 |
} |
|
82 |
|
|
83 |
public void setMatrixHeight(long matrixHeight) { |
|
84 |
this.matrixHeight = matrixHeight; |
|
85 |
} |
|
86 |
|
|
87 |
public double[] getTopLeftCorner() { |
|
88 |
return topLeftCorner; |
|
89 |
} |
|
90 |
|
|
91 |
public void setTopLeftCorner(double[] topLeftCorner) { |
|
92 |
this.topLeftCorner = topLeftCorner; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Gets the width in meters of a tile |
|
97 |
* @param projected |
|
98 |
* @return |
|
99 |
*/ |
|
100 |
public double getWidthMtsTile(boolean projected) { |
|
101 |
if(!projected) { |
|
102 |
return (scaleXDenominator * tileWidth * 0.28) / (MTS_X_GRADO * 1000); |
|
103 |
} else { |
|
104 |
return (scaleXDenominator * tileWidth * 0.28) / 1000; |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Gets the height in meters of a tile |
|
110 |
* @param projected |
|
111 |
* @return |
|
112 |
*/ |
|
113 |
public double getHeightMtsTile(boolean projected) { |
|
114 |
if(!projected) { |
|
115 |
return (scaleYDenominator * tileHeight * 0.28) / (MTS_X_GRADO * 1000); |
|
116 |
} else { |
|
117 |
return (scaleYDenominator * tileHeight * 0.28) / 1000; |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
public void print() { |
|
122 |
System.out.println(" *****TileMatrix******"); |
|
123 |
System.out.println(" scaleXDenominator:" + getScaleXDenominator()); |
|
124 |
System.out.println(" scaleYDenominator:" + getScaleYDenominator()); |
|
125 |
if(topLeftCorner != null) |
|
126 |
System.out.println(" topLeftCorner:" + topLeftCorner[0] + ", " + topLeftCorner[1]); |
|
127 |
System.out.println(" tileWidth:" + getTileWidth()); |
|
128 |
System.out.println(" tileHeight:" + getTileHeight()); |
|
129 |
System.out.println(" matrixWidth:" + getMatrixWidth()); |
|
130 |
System.out.println(" matrixHeight:" + getMatrixHeight()); |
|
131 |
} |
|
132 |
} |
|
0 | 133 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/cachestruct/TileMatrixLimits.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.cachestruct; |
|
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 sizeXTile = getTileMatrix().getTileWidth() * getTileMatrix().getScaleXDenominator(); |
|
52 |
double sizeYTile = getTileMatrix().getTileWidth() * getTileMatrix().getScaleYDenominator(); |
|
53 |
double initX = getTileMatrix().getTopLeftCorner()[0] + (sizeXTile * x); |
|
54 |
double initY = getTileMatrix().getTopLeftCorner()[1] - (sizeYTile * y); |
|
55 |
Point2D[] p = new Point2D[2]; |
|
56 |
p[0] = new Point2D.Double(initX, initY); |
|
57 |
p[1] = new Point2D.Double(initX + sizeXTile, initY - sizeYTile); |
|
58 |
return p; |
|
59 |
} |
|
60 |
|
|
61 |
public int getMinTileRow() { |
|
62 |
return minTileRow; |
|
63 |
} |
|
64 |
|
|
65 |
public void setMinTileRow(int minTileRow) { |
|
66 |
this.minTileRow = minTileRow; |
|
67 |
} |
|
68 |
|
|
69 |
public int getMaxTileRow() { |
|
70 |
return maxTileRow; |
|
71 |
} |
|
72 |
|
|
73 |
public void setMaxTileRow(int maxTileRow) { |
|
74 |
this.maxTileRow = maxTileRow; |
|
75 |
} |
|
76 |
|
|
77 |
public int getMinTileCol() { |
|
78 |
return minTileCol; |
|
79 |
} |
|
80 |
|
|
81 |
public void setMinTileCol(int minTileCol) { |
|
82 |
this.minTileCol = minTileCol; |
|
83 |
} |
|
84 |
|
|
85 |
public int getMaxTileCol() { |
|
86 |
return maxTileCol; |
|
87 |
} |
|
88 |
|
|
89 |
public void setMaxTileCol(int maxTileCol) { |
|
90 |
this.maxTileCol = maxTileCol; |
|
91 |
} |
|
92 |
|
|
93 |
public void print() { |
|
94 |
System.out.println(" *****TileMatrixLimits******"); |
|
95 |
System.out.println(" MaxTileCol:" + getMaxTileCol()); |
|
96 |
System.out.println(" MaxTileRow:" + getMaxTileRow()); |
|
97 |
System.out.println(" MinTileCol:" + getMinTileCol()); |
|
98 |
System.out.println(" MinTileRow:" + getMinTileRow()); |
|
99 |
if(tileMatrix != null) |
|
100 |
tileMatrix.print(); |
|
101 |
} |
|
102 |
} |
|
0 | 103 |
org.gvsig.raster.osm/trunk/org.gvsig.raster.osm/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/cachestruct/OSMCacheStruct.java | ||
---|---|---|
1 |
/* OSM layers for gvSIG. |
|
2 |
* Geographic Information System of the Valencian Government |
|
3 |
* |
|
4 |
* Copyright (C) 2012 Nacho Brodin |
|
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.osm.cachestruct; |
|
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.fmap.dal.coverage.RasterLocator; |
|
30 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
31 |
import org.gvsig.raster.cache.tile.Tile; |
|
32 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
|
33 |
import org.gvsig.raster.cache.tile.exception.TileBuildException; |
|
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 OSMCacheStruct implements CacheStruct { |
|
41 |
private TileMatrixSet tileMatrixSet = null; |
|
42 |
private ArrayList<TileMatrixLimits> limits = null; |
|
43 |
private String layerName = null; |
|
44 |
private Rectangle2D worldExtent = null; |
|
45 |
private String fileSuffix = null; |
|
46 |
private String epsg = null; |
|
47 |
private long fileSize = 0; |
|
48 |
private double realPixelSize = 0; |
|
49 |
|
|
50 |
public OSMCacheStruct(int levels, |
|
51 |
int tilePxWidth, |
|
52 |
int tilePxHeight, |
|
53 |
String layerName, |
|
54 |
String baseDir, |
|
55 |
String fileSuffix, |
|
56 |
long size) { |
|
57 |
this.layerName = layerName; |
|
58 |
this.fileSuffix = fileSuffix; |
|
59 |
this.fileSize = size; |
|
60 |
this.epsg = "EPSG:3857"; //WGS87 Pseudomercator |
|
61 |
|
|
62 |
//Coordenadas del mundo en geogr?ficas y planas |
|
63 |
|
|
64 |
//worldExtent = new Rectangle2D.Double(-180, -85.0511, 360, 170.1022); // arctan(sin(PI)) = 85.0511 |
|
65 |
//worldExtent = new Rectangle2D.Double(-180, -180, 360, 360); |
|
66 |
worldExtent = new Rectangle2D.Double(-20037508, -20037508, 40075016, 40075016); |
|
67 |
double[][] pixelSizeList = buildWorldMatrix(levels, tilePxWidth, tilePxHeight, worldExtent); |
|
68 |
buildLayerMatrix(levels, tilePxWidth, tilePxHeight, worldExtent, pixelSizeList); |
|
69 |
|
|
70 |
} |
|
71 |
|
|
72 |
private void buildLayerMatrix(int levels, |
|
73 |
int tilePxWidth, |
|
74 |
int tilePxHeight, |
|
75 |
Rectangle2D worldExtent, |
|
76 |
double[][] pixelSizeList) { |
|
77 |
limits = new ArrayList<TileMatrixLimits>(); |
|
78 |
|
|
79 |
for (int i = 0; i < levels; i++) { |
|
80 |
//Calculo de tiles para ese nivel en la capa actual |
|
81 |
int minTileCol = 0; |
|
82 |
int minTileRow = 0; |
|
83 |
int maxTileCol = (i == 0) ? 0 : (int)Math.pow(2, i) - 1; |
|
84 |
int maxTileRow = (i == 0) ? 0 : (int)Math.pow(2, i) - 1; |
|
85 |
|
|
86 |
TileMatrixLimits limit = new TileMatrixLimits(); |
|
87 |
limit.setMinTileRow(minTileRow); |
|
88 |
limit.setMinTileCol(minTileCol); |
|
89 |
limit.setMaxTileRow(maxTileRow); |
|
90 |
limit.setMaxTileCol(maxTileCol); |
|
91 |
|
|
92 |
//Calcula las coordenadas de la esquina superior izquierda del TileMatrixLimits |
|
93 |
double ulx = worldExtent.getMinX() + (minTileCol * tilePxWidth * pixelSizeList[0][i]); |
|
94 |
double uly = worldExtent.getMaxY() - (minTileRow * tilePxHeight * pixelSizeList[1][i]); |
|
95 |
limit.getTileMatrix().setTopLeftCorner(new double[]{ulx, uly}); |
|
96 |
limit.getTileMatrix().setScaleXDenominator(pixelSizeList[0][i]); |
|
97 |
limit.getTileMatrix().setScaleYDenominator(pixelSizeList[1][i]); |
|
98 |
limit.getTileMatrix().setTileWidth(tilePxWidth); |
|
99 |
limit.getTileMatrix().setTileHeight(tilePxHeight); |
|
100 |
|
|
101 |
limits.add(limit); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
private double[][] buildWorldMatrix(int levels, |
|
106 |
int tilePxWidth, |
|
107 |
int tilePxHeight, |
|
108 |
Rectangle2D worldExtent) { |
|
109 |
double[] pixelSizeXList = new double[levels]; |
|
110 |
double[] pixelSizeYList = new double[levels]; |
|
111 |
|
|
112 |
limits = new ArrayList<TileMatrixLimits>(); |
|
113 |
tileMatrixSet = new TileMatrixSet(); |
|
114 |
tileMatrixSet.setBbox(worldExtent); |
|
115 |
|
|
116 |
int nTilesWidth = 0; |
|
117 |
int nTilesHeight = 0; |
|
118 |
|
|
119 |
for (int i = 0; i < levels; i++) { |
|
120 |
TileMatrix tm = new TileMatrix(); |
|
121 |
tm.setTileWidth(tilePxWidth); |
|
122 |
tm.setTileHeight(tilePxHeight); |
|
123 |
|
|
124 |
nTilesWidth = (i == 0) ? 1 : nTilesWidth * 2; |
|
125 |
nTilesHeight = (i == 0) ? 1 : nTilesHeight * 2; |
|
126 |
|
|
127 |
tm.setMatrixWidth(nTilesWidth); |
|
128 |
tm.setMatrixHeight(nTilesHeight); |
|
129 |
if((tilePxWidth * nTilesWidth) != 0) |
|
130 |
pixelSizeXList[i] = worldExtent.getWidth() / ((long)tilePxWidth * (long)nTilesWidth); |
|
131 |
else |
|
132 |
pixelSizeXList[i] = 0; |
|
133 |
|
|
134 |
if((tilePxHeight * nTilesHeight) != 0) |
|
135 |
pixelSizeYList[i] = worldExtent.getHeight() / ((long)tilePxHeight * (long)nTilesHeight); |
|
136 |
else |
|
137 |
pixelSizeYList[i] = 0; |
Also available in: Unified diff