1

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?

2
  • 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
    Commented Oct 19, 2018 at 8:52
  • Thats it, thank you @Mike! Write this as an answer and i will upvote!
    – DaniEll
    Commented Oct 19, 2018 at 9:55

2 Answers 2

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]

1

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

3
  • 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
    Commented Oct 22, 2018 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
    Commented Oct 23, 2018 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
    Commented Oct 23, 2018 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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