Revision 715

View differences:

org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

  
38
import org.gvsig.compat.net.ICancellable;
39
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
40
import org.gvsig.raster.cache.tile.Tile;
41
import org.gvsig.raster.cache.tile.exception.TileGettingException;
42
import org.gvsig.raster.impl.provider.tile.BaseTileDownloader;
43
import org.gvsig.raster.osm.io.OSMDataParameters;
44

  
45
/**
46
 * Tile getter for Open Street Map
47
 * @author Nacho Brodin (nachobrodin@gmail.com)
48
 */
49
public class TileDownloaderForOSM extends BaseTileDownloader {
50
	private String server   = null;
51
	private String suffix   = null;
52
	private String slash    = "/";
53

  
54
	private static Logger logger = LoggerFactory.getLogger(TileDownloaderForOSM.class);
55

  
56

  
57
	public TileDownloaderForOSM(RasterDataStore store,
58
			int tileSize) {
59
		super(store, tileSize, tileSize);
60
		server = ((OSMDataParameters)store.getParameters()).getURI().toString();
61
		suffix = ((OSMDataParameters)store.getParameters()).getTileSuffix();
62
	}
63

  
64
	public synchronized Tile downloadTile(Tile tile) throws TileGettingException {
65
		int level = tile.getLevel();
66
		int y = tile.getRow();
67
		int x = tile.getCol();
68
		try {
69
			String stringUri = server +
70
            (server.endsWith(slash) ? "" : slash) +
71
            level + slash +
72
            x + slash +
73
            y + "." + suffix;
74
			//logger.info("OSM URI = "+stringUri);
75
            URI uri = new URI(stringUri);
76

  
77
			URL url = uri.toURL();
78
            downloadFile(url, tile.getFile(), tile.getCancelled());
79
		} catch (MalformedURLException e) {
80
			throw new TileGettingException(e);
81
		} catch (URISyntaxException e) {
82
			throw new TileGettingException(e);
83
		}
84
		readTileFromDisk(tile);
85
		return tile;
86

  
87
	}
88

  
89
	 public synchronized void downloadFile(URL url, File file, ICancellable cancel) throws TileGettingException {
90
	    	int IO_BUFFER_SIZE = 8 * 1024;
91
			int timeout =  30000;
92

  
93
			DataOutputStream dos;
94
			try {
95
				DataInputStream is;
96
				HttpURLConnection connection = null;
97

  
98
				connection = (HttpURLConnection)url.openConnection();
99
				connection.setConnectTimeout(timeout);
100

  
101
				is = new DataInputStream(url.openStream());
102

  
103
				dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(file)));
104
				byte[] buffer = new byte[IO_BUFFER_SIZE];
105

  
106
				int read;
107
				while ((read = is.read(buffer)) != -1) {
108
					dos.write(buffer, 0, read);
109
					if(cancel != null && cancel.isCanceled())
110
						return;
111
				}
112

  
113
				dos.close();
114
				is.close();
115
				is = null;
116
				dos = null;
117
			} catch (Exception e) {
118
				throw new TileGettingException(e);
119
			}
120
	    }
121

  
122
}
0 123

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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
import java.io.File;
26
import java.net.URI;
27

  
28
import org.cresques.cts.IProjection;
29

  
30
import org.gvsig.fmap.crs.CRSFactory;
31
import org.gvsig.fmap.dal.DALLocator;
32
import org.gvsig.fmap.dal.DataStore;
33
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
34
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
35
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
36
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
37
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
38
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
39
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
40
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
41
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
42
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
43
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
44
import org.gvsig.fmap.dal.exception.OpenException;
45
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
46
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
47
import org.gvsig.metadata.MetadataLocator;
48
import org.gvsig.raster.cache.tile.provider.TileServer;
49
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
50
import org.gvsig.raster.impl.datastruct.ExtentImpl;
51
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
52
import org.gvsig.raster.impl.provider.RasterProvider;
53
import org.gvsig.raster.impl.store.DefaultRasterStore;
54
import org.gvsig.raster.impl.store.DefaultStoreFactory;
55
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
56
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
57
import org.gvsig.raster.osm.cachestruct.OSMCacheStruct;
58
import org.gvsig.raster.osm.downloader.OSMTileServer;
59
import org.gvsig.tools.ToolsLocator;
60

  
61
import org.slf4j.Logger;
62
import org.slf4j.LoggerFactory;
63
/**
64
 * Data provider for OSM servers
65
 *
66
 * @author Nacho Brodin (nachobrodin@gmail.com)
67
 */
68
public class OSMProvider extends AbstractRasterProvider {
69
	public static String                     NAME                     = "OSM Raster";
70
	public static String                     DESCRIPTION              = "OSM Raster Server";
71
	public final String                      METADATA_DEFINITION_NAME = NAME;
72
	private Extent                           viewRequest              = null;
73
	private TileServer                       tileServer               = null;
74
	private boolean                          open                     = false;
75
    private DataStoreTransparency            fileTransparency         = null;
76
    private static final Logger              logger                   = LoggerFactory.getLogger(OSMProvider.class);
77

  
78
	public static void register() {
79
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
80

  
81
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
82
			dataman.registerStoreProvider(NAME,
83
					OSMProvider.class, OSMDataParametersImpl.class);
84
		}
85

  
86
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
87
	}
88

  
89
	public OSMProvider() {
90
	}
91

  
92
	/**
93
	 * Opens the dataset.
94
	 * @param proj Projection
95
	 * @param fName File name
96
	 * @throws NotSupportedExtensionException
97
	 */
98
	public OSMProvider(String params) throws NotSupportedExtensionException, OpenException {
99
		super(params);
100

  
101
	}
102

  
103
	public OSMProvider (OSMDataParametersImpl params,
104
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
105
		super(params, storeServices, ToolsLocator.getDynObjectManager()
106
				.createDynObject(
107
						MetadataLocator.getMetadataManager().getDefinition(
108
								DataStore.METADATA_DEFINITION_NAME)));
109
		init(params, storeServices);
110
	}
111

  
112
	/**
113
	 * Build file references
114
	 * @param proj Projection
115
	 * @param param Load parameters
116
	 * @throws NotSupportedExtensionException
117
	 */
118
	public void init (OSMDataParametersImpl params,
119
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
120
		setParam(storeServices, params);
121
		setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE});
122
		bandCount = 4;
123
		super.init();
124
		fileSize = (long)(getWidth() * getHeight() * 3);
125

  
126
		Extent ext = getExtent();
127
		ownTransformation = new AffineTransform(
128
				ext.width() / getWidth(), 0,
129
				0, -(ext.height() / getHeight()),
130
				getExtent().getMin().getX(),
131
				getExtent().getMax().getY());
132
		externalTransformation = (AffineTransform)ownTransformation.clone();
133
		open = true;
134
	}
135

  
136
	public IProjection getProjection() {
137
		if(proj == null) {
138
			try {
139
				proj = CRSFactory.getCRS("EPSG:3857");
140
			} catch(Exception e) {
141
				logger.info("Projection not loaded", e);
142
			}
143
		}
144
		return proj;
145
	}
146

  
147
	/**
148
	 * Gets the bounding box in world coordinates.
149
	 * @return Extent
150
	 */
151
	public Extent getExtent() {
152
		return ((OSMCacheStruct)getTileServer().getStruct()).getWorldExtent();
153
	}
154

  
155
	/**
156
	 * Reloads metadata using the selected grid
157
	 */
158
	@SuppressWarnings("unused")
159
	private void reloadMetadataFromGrid() {
160
		//wktProjection = null;
161
		//CrsWkt crs = new CrsWkt(wktProjection);
162
		//IProjection proj = CRSFactory.getCRS("EPSG:23030");
163

  
164
		/*ownTransformation = new AffineTransform(
165
				scaleX, 0,
166
				0, -scaleY,
167
				pRect.getMinX(),
168
				pRect.getMaxY());*/
169
		externalTransformation = (AffineTransform)ownTransformation.clone();
170
		bandCount = 3;
171
		setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE});
172
	}
173

  
174
	public RasterProvider load() {
175
		return this;
176
	}
177

  
178
	public boolean isOpen() {
179
		return open;
180
	}
181

  
182
	public void close() {
183
	}
184

  
185
	public URI translateURI(URI uri) {
186
		return uri;
187
	}
188

  
189
	public NoData getNoDataValue() {
190
		NoData nodata = super.getNoDataValue();
191
		if(nodata != null)
192
			nodata.setNoDataTransparent(false);
193
		return noData;
194
	}
195

  
196
	/**
197
	 * Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci�n
198
	 * de la vista asignada ya que la petici�n viene en coordenadas del fichero .rmf y la vista (v)
199
	 * ha de estar en coordenadas del fichero.
200
	 */
201
	public void setView(Extent e) {
202
		viewRequest = new ExtentImpl(e);
203
	}
204

  
205
	public Extent getView() {
206
		return viewRequest;
207
	}
208

  
209
	public double getWidth() {
210
		int n = getTileServer().getStruct().getNumberOfLevels() - 1;
211
		return getExtent().width() / getTileServer().getStruct().getPixelSizeByLevel(n);
212
	}
213

  
214
	public double getHeight() {
215
		int n = getTileServer().getStruct().getNumberOfLevels() - 1;
216
		return getExtent().width() / getTileServer().getStruct().getPixelSizeByLevel(n);
217
	}
218

  
219
	public Object readBlock(int pos, int blockHeight, double scale)
220
		throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
221
		return null;
222
	}
223

  
224
	public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
225
		return null;
226
	}
227

  
228
	public int getBlockSize(){
229
		return 0;
230
	}
231

  
232
	/**
233
	 * Informa de si el driver ha supersampleado en el �ltimo dibujado. Es el driver el que colocar�
234
	 * el valor de esta variable cada vez que dibuja.
235
	 * @return true si se ha supersampleado y false si no se ha hecho.
236
	 */
237
	public boolean isSupersampling() {
238
		return false;
239
	}
240

  
241
	public void setAffineTransform(AffineTransform t){
242
		super.setAffineTransform(t);
243
	}
244

  
245
	public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
246
		if(band >= getBandCount())
247
			throw new BandAccessException("Wrong band");
248
		return 0;
249
	}
250

  
251
	public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
252
		if (band >= getBandCount())
253
			throw new BandAccessException("Wrong band");
254
		return 0;
255
	}
256

  
257
	public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
258
		if (band >= getBandCount())
259
			throw new BandAccessException("Wrong band");
260
		return 0;
261
	}
262

  
263
	public boolean isOverviewsSupported() {
264
		return true;
265
	}
266

  
267
	public boolean isReproyectable() {
268
		return true;
269
	}
270

  
271
	public String getProviderName() {
272
		return NAME;
273
	}
274

  
275
    public String getName() {
276
        return this.getParameters().getOSMLayerName();
277
    }
278

  
279
    @Override
280
    public String getFullName() {
281
        return this.uri.toString();
282
    }
283

  
284
	public OSMDataParameters getParameters() {
285
		return (OSMDataParameters)this.param;
286
	}
287

  
288
	public DataStoreTransparency getTransparency() {
289
		if(fileTransparency == null)
290
			fileTransparency = new DataStoreTransparency(getColorInterpretation());
291
		return fileTransparency;
292
	}
293

  
294
	public ColorInterpretation getColorInterpretation() {
295
		if(super.getColorInterpretation() == null) {
296
			super.setColorInterpretation(DataStoreColorInterpretation.createRGBInterpretation());
297
		}
298
		return super.getColorInterpretation();
299
	}
300

  
301
	public void setStatus(RasterProvider provider) {
302
		if(provider instanceof OSMProvider) {
303
			//Not implemented yet
304
		}
305
	}
306

  
307
	public boolean isTimeSupported() {
308
		return true;
309
	}
310

  
311
	public boolean isTiled() {
312
		return true;
313
	}
314

  
315
	public TileServer getTileServer() {
316
		if(tileServer == null) {
317
			DefaultRasterStore store = new DefaultRasterStore();
318
			store.setProvider(this);
319
			tileServer = new OSMTileServer(store,
320
					((OSMDataParameters)param).getTileSuffix(),
321
					((OSMDataParameters)param).getNumberOfLevels());
322
		}
323
		return tileServer;
324
	}
325

  
326
	@Override
327
	public void loadBuffer(SpiRasterQuery query)
328
			throws ProcessInterruptedException, RasterDriverException {
329

  
330
	}
331

  
332
    /* (non-Javadoc)
333
     * @see org.gvsig.raster.impl.provider.RasterProvider#addFile(java.io.File)
334
     */
335
    @Override
336
    public void addFile(File file) throws InvalidSourceException {
337
        // Do nothing
338
    }
339

  
340
    /* (non-Javadoc)
341
     * @see org.gvsig.raster.impl.provider.RasterProvider#removeFile(java.io.File)
342
     */
343
    @Override
344
    public void removeFile(File file) {
345
        // Do nothing
346
    }
347

  
348
    /* (non-Javadoc)
349
     * @see org.gvsig.raster.impl.provider.AbstractRasterProvider#getFileSuffix()
350
     */
351
    @Override
352
    public String getFileSuffix() {
353
        return ((OSMDataParameters)getDataParameters()).getTileSuffix();
354
    }
355
}
0 356

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.117/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
import java.net.URI;
25

  
26

  
27
/**
28
 * Parameters for the WMS provider
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public interface OSMDataParameters {
32

  
33
    public void setURI(URI uri);
34

  
35
	public URI getURI();
36

  
37
	public int getWidth();
38

  
39
	public int getHeight();
40

  
41
	public void setWidth(int w);
42

  
43
	public void setHeight(int h);
44

  
45
	public String getOSMLayerName();
46

  
47
	public void setOSMLayerName(String name);
48

  
49
	public int getNumberOfLevels();
50

  
51
	public void setNumberOfLevels(int levels);
52

  
53
	public String getTileSuffix();
54

  
55
	public void setTileSuffix(String suffix);
56
}
0 57

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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/tags/org.gvsig.raster.osm-2.2.117/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, 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff