Revision 1240
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.221/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.221/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.221/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.221/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.221/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.221/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.221/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.221/org.gvsig.raster.osm.io/src/main/java/org/gvsig/raster/osm/cachestruct/TileMatrixSet.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.Rectangle2D; |
|
25 |
import java.io.IOException; |
|
26 |
import java.util.ArrayList; |
|
27 |
|
|
28 |
import org.kxml2.io.KXmlParser; |
|
29 |
import org.xmlpull.v1.XmlPullParserException; |
|
30 |
|
|
31 |
|
|
32 |
/** |
|
33 |
* <p>Defines a set of tiles</p> |
|
34 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
35 |
*/ |
|
36 |
public class TileMatrixSet { |
|
37 |
protected Rectangle2D bbox = null; |
|
38 |
private String supportedCRS = null; |
|
39 |
protected ArrayList<TileMatrix> tileMatrix = null; |
|
40 |
|
|
41 |
public void setBbox(Rectangle2D bbox) { |
|
42 |
this.bbox = bbox; |
|
43 |
} |
|
44 |
|
|
45 |
public Rectangle2D getBoundingBox() { |
|
46 |
return bbox; |
|
47 |
} |
|
48 |
|
|
49 |
public ArrayList<TileMatrix> getTileMatrix() { |
|
50 |
if(tileMatrix == null) |
|
51 |
tileMatrix = new ArrayList<TileMatrix>(); |
|
52 |
return tileMatrix; |
|
53 |
} |
|
54 |
|
|
55 |
public String getSupportedCRS() { |
|
56 |
return supportedCRS; |
|
57 |
} |
|
58 |
|
|
59 |
public void setSupportedCRS(String supportedCRS) { |
|
60 |
this.supportedCRS = supportedCRS; |
|
61 |
} |
|
62 |
|
|
63 |
public void parse(KXmlParser parser) throws IOException, |
|
64 |
XmlPullParserException { |
|
65 |
} |
|
66 |
|
|
67 |
public void print() { |
|
68 |
System.out.println("*****TileMatrixSet******"); |
|
69 |
if(bbox != null) |
|
70 |
System.out.println(bbox.toString()); |
|
71 |
System.out.println("supportedCRS:" + getSupportedCRS()); |
|
72 |
for (int i = 0; i < tileMatrix.size(); i++) { |
|
73 |
((TileMatrix)tileMatrix.get(i)).print(); |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
} |
|
0 | 78 |
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.221/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.221/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.221/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; |
|
138 |
//System.out.println("-Level:" + i + " " + nTilesWidth + " " + nTilesHeight + " " + pixelSizeList[i]); |
|
139 |
tm.setScaleXDenominator(pixelSizeXList[i]); |
|
140 |
tm.setScaleYDenominator(pixelSizeYList[i]); |
|
141 |
tileMatrixSet.getTileMatrix().add(tm); |
|
142 |
} |
|
143 |
|
|
144 |
double[][] r = new double [2][]; |
|
145 |
r[0] = pixelSizeXList; |
|
146 |
r[1] = pixelSizeYList; |
|
147 |
return r; |
|
148 |
} |
|
149 |
|
|
150 |
public Extent getWorldExtent() { |
|
151 |
return RasterLocator.getManager().getDataStructFactory().createExtent(worldExtent); |
|
152 |
} |
|
153 |
|
|
154 |
public int getNumberOfLevels() { |
|
155 |
return tileMatrixSet.getTileMatrix().size(); |
|
156 |
} |
|
157 |
|
|
158 |
public String getLayerName() { |
|
159 |
return layerName; |
|
160 |
} |
|
161 |
|
|
162 |
public String getServerURL() { |
|
163 |
return layerName; |
|
164 |
} |
|
165 |
|
|
166 |
public String getFileSuffix() { |
|
167 |
return fileSuffix; |
|
168 |
} |
|
169 |
|
|
170 |
public int[] getTileSizeByLevel(int level) { |
|
171 |
return new int[] { |
|
172 |
tileMatrixSet.getTileMatrix().get(level).getTileWidth(), |
|
173 |
tileMatrixSet.getTileMatrix().get(level).getTileHeight() |
|
174 |
}; |
|
175 |
} |
|
176 |
|
|
177 |
public double[] getTileSizeInRealCoordsByLevel(int level) { |
|
178 |
return new double[] { |
|
179 |
tileMatrixSet.getTileMatrix().get(level).getScaleXDenominator() * tileMatrixSet.getTileMatrix().get(level).getTileWidth(), |
|
180 |
tileMatrixSet.getTileMatrix().get(level).getScaleYDenominator() * tileMatrixSet.getTileMatrix().get(level).getTileHeight() |
|
181 |
}; |
|
182 |
} |
|
183 |
|
|
184 |
public int getLayerWidthOfTileMatrixByLevel(int level) { |
|
185 |
TileMatrixLimits l = limits.get(level); |
|
186 |
return l.getMaxTileRow() - l.getMinTileRow(); |
|
187 |
} |
|
188 |
|
|
189 |
public int getLayerHeightOfTileMatrixByLevel(int level) { |
|
190 |
TileMatrixLimits l = limits.get(level); |
|
191 |
return l.getMaxTileCol() - l.getMinTileCol(); |
|
192 |
} |
|
193 |
|
|
194 |
public int getLayerInitXTilePositionByLevel(int level) { |
|
195 |
TileMatrixLimits l = limits.get(level); |
|
196 |
return l.getMinTileCol(); |
|
197 |
} |
|
198 |
|
|
199 |
public int getLayerInitYTilePositionByLevel(int level) { |
|
200 |
TileMatrixLimits l = limits.get(level); |
|
201 |
return l.getMinTileRow(); |
|
202 |
} |
|
203 |
|
|
204 |
public long getWorldHeightOfTileMatrixByLevel(int level) { |
|
205 |
return tileMatrixSet.getTileMatrix().get(level).getMatrixWidth(); |
|
206 |
} |
|
207 |
|
|
208 |
public long getWorldWidthOfTileMatrixByLevel(int level) { |
|
209 |
return tileMatrixSet.getTileMatrix().get(level).getMatrixHeight(); |
|
210 |
} |
|
211 |
|
|
212 |
public double getPixelSizeByLevel(int level) { |
|
213 |
if(level < 0) |
|
214 |
return realPixelSize; |
|
215 |
return tileMatrixSet.getTileMatrix().get(level).getScaleXDenominator(); |
|
216 |
} |
|
217 |
|
|
218 |
public Point2D[] getTileExtent(Tile tile) { |
|
219 |
return limits.get(tile.getLevel()).getTileExtent(tile.getRow(), tile.getCol()); |
|
220 |
} |
|
221 |
|
|
222 |
public Point2D[] getTileExtent(int level, int col, int row) { |
|
223 |
return limits.get(level).getTileExtent(row, col); |
|
224 |
} |
|
225 |
|
|
226 |
public List<Tile> getTileList(Rectangle2D r) { |
|
227 |
//No se necesita el nivel de resoluci?n real ya que es solo para dibujado |
|
228 |
return null; |
|
229 |
} |
|
230 |
|
|
231 |
public List<Tile> getTileList(Point2D ul, Point2D lr, double mtsPixelXRequest) { |
|
232 |
//Selecci?n de nivel de resoluci?n |
|
233 |
int tilePxWidth = 0; |
|
234 |
int tilePxHeight = 0; |
|
235 |
double tileWCWidth = 0; |
|
236 |
double tileWCHeight = 0; |
|
237 |
int level = 0; |
|
238 |
double mtsPixelXLevel = 0; |
|
239 |
double mtsPixelYLevel = 0; |
|
240 |
for (int i = 0; i < tileMatrixSet.getTileMatrix().size(); i++) { |
|
241 |
mtsPixelXLevel = tileMatrixSet.getTileMatrix().get(i).getScaleXDenominator(); |
|
242 |
mtsPixelYLevel = tileMatrixSet.getTileMatrix().get(i).getScaleYDenominator(); |
|
243 |
if(clipDecimals(mtsPixelXRequest, 6) >= clipDecimals(mtsPixelXLevel, 6) |
|
244 |
|| i == (tileMatrixSet.getTileMatrix().size() - 1)) { |
|
245 |
level = Math.max(i, 0); |
|
246 |
//Se ajusta al m?ximo nivel disponible para esa capa |
|
247 |
if(level > (limits.size() - 1)) { |
|
248 |
level = limits.size() - 1; |
|
249 |
mtsPixelXLevel = tileMatrixSet.getTileMatrix().get(level).getScaleXDenominator(); |
|
250 |
mtsPixelYLevel = tileMatrixSet.getTileMatrix().get(level).getScaleYDenominator(); |
|
251 |
} |
Also available in: Unified diff