Skip to content

Commit

Permalink
Determine topLeft axis order by supportedCRS of TileMatrixSet
Browse files Browse the repository at this point in the history
  • Loading branch information
jampukka committed Feb 8, 2023
1 parent 4645f17 commit 0414389
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import fi.nls.oskari.map.geometry.ProjectionHelper;
import fi.nls.oskari.map.layer.OskariLayerService;
import fi.nls.oskari.map.layer.OskariLayerServiceMybatisImpl;

import org.geotools.referencing.CRS;
import org.json.JSONObject;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

/**
* HystrixCommand that loads tiles from a WMTS service and combines them to a
Expand Down Expand Up @@ -76,6 +79,15 @@ public BufferedImage run() throws Exception {
double[] topLeft = tm.getTopLeftCorner();
double minX = topLeft[0];
double maxY = topLeft[1];
if (isAxisOrderNE(tms.getCrs())) {
// From the WMTS spec, topLeftCorner:
// Position in CRS coordinates of the top-left corner of this tile matrix
// Ordered sequence of double values
// CRS shall be inherited from the supportedCRS parameter of the parent TileMatrixSet
// The order of these axes, shall be as specified by the supportedCRS
minX = topLeft[1];
maxY = topLeft[0];
}

// Round to the nearest px
long minXPx = Math.round((bbox[0] - minX) / resolution);
Expand Down Expand Up @@ -167,6 +179,17 @@ public BufferedImage run() throws Exception {
return bi;
}

private static boolean isAxisOrderNE(String srs) {
try {
CoordinateReferenceSystem crs = CRS.decode(srs);
return ProjectionHelper.isFirstAxisNorth(crs);
// return CRS.getAxisOrder(crs) == CRS.AxisOrder.NORTH_EAST;
} catch (Exception e) {
LOG.info("Failed to decode crs from: " + srs);
return false;
}
}

private LayerCapabilitiesWMTS getLayerCapabilities() throws IllegalArgumentException {
OskariLayer oskariLayer = layer.getOskariLayer();
if (oskariLayer != null) {
Expand Down

0 comments on commit 0414389

Please sign in to comment.