Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print: Determine topLeft axis order by supportedCRS of TileMatrixSet #920

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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