0

Description

I have to use a WMTS-Service in EPSG:31254 and show it on an OpenLayers 5 Map in EPSG:3857. The WMTS-Service to use is this one.

My Solution

I use proj4 and configure "EPSG:31254" according to epsg.io/31254

proj4.defs("EPSG:31254", "+proj=tmerc +lat_0=0 +lon_0=10.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 +units=m +no_defs");

Then i configure OpenLayers to use proj4 and create an OpenLayers Map in EPSG:3857 (i know, its the default projection) with a default background at a given center and zoom level.

Then i add the TileLayer in EPSG:31254:

  • read WMTS Capabilities
  • build Options from Capabilities
  • build WMTS-Source with Options
  • add TileLayer with WMTS-Source

Problem

An Image is shown, but it's shown at the wrong place (e.g. the Italian Peninsula should overlap!)

wrong image

Source Code

I created an example showing the problem over at codesandbox.io
What is wrong with my solution?

  • 1
    The top left corner in the WMTS capabilities is 470000.0 -250000.0 which isn't somewhere north west of Austria as it should be. I suspect it has the x and y axes swapped, in which you won't be able to use the capabilities and will need to set up your own tile grid with origin [-250000.0,470000.0] – Mike Oct 19 '18 at 8:52
  • Thats it, thank you @Mike! Write this as an answer and i will upvote! – DaniEll Oct 19 '18 at 9:55
1

The top left corner in the WMTS capabilities is 470000.0 -250000.0 which isn't somewhere north west of Austria as it should be. I suspect it has the x and y axes swapped, in which you won't be able to use the capabilities and will need to set up your own tile grid with origin [-250000.0,470000.0]

0

TL:DR

The proj4 definition of "EPSG:31254" according to epsg.io is missing "+axis=neu".

Here is why:

Server Side / WMTS Capabilities

According to the WMTS Specification the Coordinates of the topLeftCorner of the TileMatrix should be as specified by the supportedCRS.

CRS will be inherited from the supportedCRS parameter of the parent TileMatrixSet. The order of these axes, shall be as specified by the supportedCRS. These are the precise coordinates of the top left corner of top left pixel of the 0,0 tile.

In this case, according to epsg.io the CRS is cartesian and the WMTS Capabilities are correct (Y X). In this case (470000.0 -250000.0) is (Y X) or (northing, easting).
The WMTS Capabilities are correct check

Client Side / OpenLayers

As it looks, OpenLayers does look at the supportedCrs and does switchOriginXY in case the axis orientation of the projection is 'ne' (instead of 'en')
OpenLayers is correct check

Which brings us to...

Client Side / proj4

OpenLayers uses proj4 under the hood. The given definition for EPSG:31254 according to epsg.io is

proj4.defs("EPSG:31254","+proj=tmerc +lat_0=0 +lon_0=10.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 +units=m +no_defs");

This definition is missing the axis orientation!

Solution

Add "+axis=neu" and the example works (Demo at codesandbox.io) working demo

  • As with all projections OpenLayers only has the proj4 definition to work with. There's no +axis=neu setting in there which would indicate the axes were swapped, although when I tried adding it nothing changed. – Mike Oct 22 '18 at 17:53
  • @Mike you are right +axis=neu was missing in the proj4 definition of EPSG:31254. Adding "+axis=neu" and removing the workaround (manual swapping afterwards) fixed the demo! – DaniEll Oct 23 '18 at 6:03
  • There's also an issue with proj4 and the sandbox editer. Although the map refreshes as soon as an edit is typed in proj4 doesn't refresh immediately making it appear the edit had no effect. – Mike Oct 23 '18 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.