Revision 2613 org.gvsig.raster.wmts/trunk/org.gvsig.raster.wmts/org.gvsig.raster.wmts.ogc/org.gvsig.raster.wmts.ogc.impl/src/main/java/org/gvsig/raster/wmts/ogc/impl/struct/WMTSLayerImpl.java
WMTSLayerImpl.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.raster.wmts.ogc.impl.struct; |
23 | 23 |
|
24 |
import java.awt.geom.Rectangle2D; |
|
24 | 25 |
import java.util.ArrayList; |
25 | 26 |
import java.util.List; |
26 |
import java.util.regex.Matcher; |
|
27 |
import java.util.regex.Pattern; |
|
28 | 27 |
|
28 |
import org.cresques.cts.ICoordTrans; |
|
29 |
import org.cresques.cts.IProjection; |
|
30 |
import org.gvsig.fmap.crs.CRSFactory; |
|
29 | 31 |
import org.gvsig.raster.wmts.ogc.WMTSStatus; |
30 | 32 |
import org.gvsig.raster.wmts.ogc.impl.base.WMTSServerDescription; |
31 |
import org.gvsig.raster.wmts.ogc.impl.base.WMTSStatusImpl; |
|
32 | 33 |
import org.gvsig.raster.wmts.ogc.struct.WMTSBoundingBox; |
33 | 34 |
import org.gvsig.raster.wmts.ogc.struct.WMTSDimension; |
34 | 35 |
import org.gvsig.raster.wmts.ogc.struct.WMTSLayer; |
35 | 36 |
import org.gvsig.raster.wmts.ogc.struct.WMTSResourceURL; |
36 | 37 |
import org.gvsig.raster.wmts.ogc.struct.WMTSStyle; |
37 |
import org.gvsig.raster.wmts.ogc.struct.WMTSTile; |
|
38 | 38 |
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrix; |
39 | 39 |
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixLimits; |
40 | 40 |
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSet; |
41 | 41 |
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSetLink; |
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
42 | 44 |
|
43 | 45 |
/** |
44 | 46 |
* Describes the attributes of a layer in a WMTS server |
... | ... | |
46 | 48 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
47 | 49 |
*/ |
48 | 50 |
public abstract class WMTSLayerImpl extends WMTSBaseStruct implements WMTSLayer { |
49 |
protected WMTSBoundingBoxImpl wgs84bbox = null;
|
|
50 |
protected WMTSBoundingBoxImpl bbox = null;
|
|
51 |
protected WMTSBoundingBox wgs84bbox = null;
|
|
52 |
protected WMTSBoundingBox bbox = null;
|
|
51 | 53 |
private List<WMTSStyle> style = null; |
52 | 54 |
private List<String> imageFormat = null; |
53 | 55 |
private List<String> infoFormat = null; |
... | ... | |
57 | 59 |
private List<WMTSTileMatrixSetLink> tileMatrixSetLinkList = null; |
58 | 60 |
private List<WMTSResourceURL> resourceURL = null; |
59 | 61 |
protected WMTSServerDescription status = null; |
60 |
protected boolean forceLongitudeFirstAxisOrder = false; |
|
62 |
private Logger log = LoggerFactory.getLogger(WMTSLayerImpl.class); |
|
63 |
protected boolean forceChangeAxisOrder = false; |
|
61 | 64 |
|
62 | 65 |
/** |
63 | 66 |
* Sets longitude first in the axis order read from the capabilities file |
64 | 67 |
* @param force |
65 | 68 |
*/ |
66 |
public void setForceLongitudeFirstAxisOrder(boolean force) {
|
|
67 |
this.forceLongitudeFirstAxisOrder = force;
|
|
69 |
public void setForceChangeAxisOrder(boolean force) {
|
|
70 |
this.forceChangeAxisOrder = force;
|
|
68 | 71 |
} |
69 | 72 |
|
70 | 73 |
public WMTSLayerImpl(WMTSServerDescription status) { |
... | ... | |
99 | 102 |
this.keywords = k; |
100 | 103 |
} |
101 | 104 |
|
102 |
public abstract WMTSBoundingBox getWGS84BBox(); |
|
105 |
public WMTSBoundingBox getWGS84BBox() { |
|
106 |
return wgs84bbox; |
|
107 |
} |
|
103 | 108 |
|
104 |
public abstract WMTSBoundingBox getBBox(); |
|
109 |
public Rectangle2D getWGS84BBoxTransformed(String epsg) { |
|
110 |
IProjection projSrc = CRSFactory.getCRS("EPSG:4326"); |
|
111 |
try { |
|
112 |
IProjection projDst = CRSFactory.getCRS(epsg); |
|
113 |
if(projDst != null) { |
|
114 |
try { |
|
115 |
ICoordTrans t = projSrc.getCT(projDst); |
|
116 |
return t.convert(wgs84bbox.toRectangle2D()); |
|
117 |
} catch (Exception e) { |
|
118 |
log.info("I cannot get the transformation between EPSG:4326 and " + epsg, e); |
|
119 |
} |
|
120 |
} |
|
121 |
} catch (Exception e1) { |
|
122 |
log.info("I cannot get " + epsg, e1); |
|
123 |
} |
|
124 |
return null; |
|
125 |
} |
|
105 | 126 |
|
127 |
public WMTSBoundingBox getBBox() { |
|
128 |
return bbox; |
|
129 |
} |
|
130 |
|
|
131 |
public void setWGS84BBox(WMTSBoundingBox wgs84bbox) { |
|
132 |
this.wgs84bbox = wgs84bbox; |
|
133 |
} |
|
134 |
|
|
135 |
public void setBBox(WMTSBoundingBox bbox) { |
|
136 |
this.bbox = bbox; |
|
137 |
} |
|
138 |
|
|
106 | 139 |
public List<WMTSResourceURL> getResourceURL() { |
107 | 140 |
if(resourceURL == null) |
108 | 141 |
resourceURL = new ArrayList<WMTSResourceURL>();//resourceURL = (WMTSResourceURL)status.createVersionObject("WMTSResourceURL"); |
109 | 142 |
return resourceURL; |
110 | 143 |
} |
111 | 144 |
|
112 |
public List<WMTSDimension> getDimension() { |
|
145 |
public List<WMTSDimension> getDimensions() {
|
|
113 | 146 |
if(dimension == null) |
114 | 147 |
dimension = new ArrayList<WMTSDimension>(); //(WMTSDimension)status.createVersionObject("WMTSDimension"); |
115 | 148 |
return dimension; |
... | ... | |
194 | 227 |
/** |
195 | 228 |
* Builds the list of URL whether the capabilities file uses templates. |
196 | 229 |
*/ |
197 |
public void buildResourceURLListFromTemplate(WMTSStatus status, String defaultDimension) { |
|
198 |
String template = getTemplate(status.getFormat(), status.getStyle()); |
|
199 |
String dimensionValueToWrite = defaultDimension; |
|
200 |
|
|
201 |
if(template == null) |
|
202 |
return; |
|
203 |
|
|
204 |
if(dimensionValueToWrite == null) |
|
205 |
dimensionValueToWrite = getDimensionValueToWriteInTemplate(template); |
|
206 |
|
|
207 |
replacePatternsInTemplate(template, status, dimensionValueToWrite); |
|
230 |
public void buildResourceURLListFromTemplate(WMTSStatus status) { |
|
231 |
TemplateSupport templateSupport = new TemplateSupport(getDimensions(), getResourceURL()); |
|
232 |
templateSupport.buildResourceURLListFromTemplate(status); |
|
208 | 233 |
} |
209 | 234 |
|
210 |
/** |
|
211 |
* Gets the dimension which we want to write in the template, replacing the |
|
212 |
* dimension identifier. This function is just called if the user has not passed |
|
213 |
* this value. |
|
214 |
* @param template |
|
215 |
* @return |
|
216 |
*/ |
|
217 |
private String getDimensionValueToWriteInTemplate(String template) { |
|
218 |
for (int iDimension = 0; iDimension < getDimension().size(); iDimension++) { |
|
219 |
WMTSDimension dim = getDimension().get(iDimension); |
|
220 |
String idDim = dim.getIdentifier(); |
|
221 |
if(template.toLowerCase().contains("{" + idDim.toLowerCase() + "}")) { |
|
222 |
return dim.getDefaultValue(); |
|
223 |
} |
|
224 |
} |
|
225 |
return null; |
|
226 |
} |
|
227 |
|
|
228 |
/** |
|
229 |
* Replaces strings in the template and load each URL in an array in <code>WMTSStatus</code> |
|
230 |
* @param template |
|
231 |
* @param status |
|
232 |
* @param dimensionValue |
|
233 |
*/ |
|
234 |
private void replacePatternsInTemplate(String template, WMTSStatus status, String dimensionValue) { |
|
235 |
String idDimensionToBeReplaced = getDimensionIDToReplace(template); |
|
236 |
template = template.replaceAll("(?i)\\{" + idDimensionToBeReplaced + "\\}", dimensionValue); |
|
237 |
template = template.replace("{TileMatrixSet}", status.getTileMatrixSet()); |
|
238 |
template = template.replace("{TileMatrix}", status.getTileMatrix()); |
|
239 |
|
|
240 |
for (int i = 0; i < status.getTileList().size(); i++) { |
|
241 |
WMTSTile tile = status.getTileList().get(i); |
|
242 |
String url = new String(template); |
|
243 |
url = url.replace("{TileRow}", tile.getRow() + ""); |
|
244 |
url = url.replace("{TileCol}", tile.getCol() + ""); |
|
245 |
((WMTSStatusImpl)status).addResourceURL(tile.getRow() + "" + tile.getCol() + "", url); |
|
246 |
} |
|
247 |
} |
|
248 |
|
|
249 |
/** |
|
250 |
* Gets the dimension identifier to be replaced by the dimension value |
|
251 |
* @param template |
|
252 |
* @return |
|
253 |
*/ |
|
254 |
private String getDimensionIDToReplace(String template) { |
|
255 |
for (int iDimension = 0; iDimension < getDimension().size(); iDimension++) { |
|
256 |
WMTSDimension dim = getDimension().get(iDimension); |
|
257 |
String idDim = dim.getIdentifier(); |
|
258 |
if(template.toLowerCase().contains("{" + idDim.toLowerCase() + "}")) { |
|
259 |
return idDim; |
|
260 |
} |
|
261 |
} |
|
262 |
return null; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Return a template which supports the format and the style selected |
|
267 |
* @param format |
|
268 |
* @param style |
|
269 |
* @return |
|
270 |
*/ |
|
271 |
private String getTemplate(String format, String style) { |
|
272 |
for (int iResourceURL = 0; iResourceURL < getResourceURL().size(); iResourceURL++) { |
|
273 |
String currentFormat = getResourceURL().get(iResourceURL).getFormat(); |
|
274 |
if(currentFormat != null && currentFormat.equals(format)) { |
|
275 |
String template = getResourceURL().get(iResourceURL).getTemplate(); |
|
276 |
if(isStyleSupported(template, style)) { |
|
277 |
return template; |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
return null; |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* Returns true if the style is supported in the template URL |
|
286 |
* @param template |
|
287 |
* @param style |
|
288 |
* @return |
|
289 |
*/ |
|
290 |
private boolean isStyleSupported(String template, String style) { |
|
291 |
Pattern p = Pattern.compile("/" + style + "/", Pattern.CASE_INSENSITIVE); |
|
292 |
Matcher m = p.matcher(template); |
|
293 |
if(m.find()) |
|
294 |
return true; |
|
295 |
return false; |
|
296 |
} |
|
297 |
|
|
298 | 235 |
public void print() { |
299 | 236 |
System.out.println("*****WMTSLayer******"); |
300 | 237 |
System.out.println("Abstract:" + getAbstract()); |
... | ... | |
312 | 249 |
} |
313 | 250 |
((WMTSBoundingBoxImpl)getBBox()).print(); |
314 | 251 |
((WMTSBoundingBoxImpl)getWGS84BBox()).print(); |
315 |
for (int i = 0; i < getDimension().size(); i++) { |
|
316 |
((WMTSDimensionImpl)getDimension().get(i)).print(); |
|
252 |
for (int i = 0; i < getDimensions().size(); i++) {
|
|
253 |
((WMTSDimensionImpl)getDimensions().get(i)).print();
|
|
317 | 254 |
} |
318 | 255 |
System.out.println("Metadata:" + getMetadata()); |
319 | 256 |
for (int i = 0; i < getTileMatrixSetLink().size(); i++) { |
Also available in: Unified diff