1

I'm currently developing a slippy map. It is perfectly working with tile coordinates that are used in openstreet maps i.e. the zoom/x/y format. I have used the formula from the OSM wiki to map longitude and latitude coordinates to their respective tiles. However I also want to implement a method to use a WMTS Tile Server. The problem is that the coordinate to tile mapping seems to be different here.

Is there a formula to get the WMTS tilenumber from a specific coordinate in longitude/latitude format with a given zoom level?

I am using geoserver to serve WMTS tiles.

I constructed an example to show my problem.

var lat = 50.5524; //Coordinates of Wetzlar, Germany
var lon = 8.5072;
var zoom = 12;
var tileLong = long2tile (lon, zoom + 1); //For some reason I need to increase the zoom level by 1 to get equivalent results in WMTS and OSM
var tileLat = lat2tile(lat, zoom +1);

tileLong -> 4289, this is correct as the OSM and the WMTS tile have the same value
tileLat -> 2758, correct in OSM, incorrect for WMTS as WMTS needs inversing the y-axis

var invertedTileLat = (1 << zoom) - tileLat - 1; //I have also tried zoom+1

invertedTileLat -> 1337, still incorrect for WMTS. The expected result is 897
  • did you read the standard - opengeospatial.org/standards/wmts – Ian Turton Jan 16 '18 at 7:25
  • This question has been answered here: gis.stackexchange.com/questions/133205/… – mipa Jan 16 '18 at 7:27
  • @mipa This doesn't work for me. The OSM and the WMTS format seem to be different. – Schedonn Jan 16 '18 at 7:30
  • @IanTurton I have already searched in the WMTS standard, but couldn't find a clear formular. – Schedonn Jan 16 '18 at 7:31
  • Sorry, yes you are right. The cited question explicitly asked for WMTS tiles but the accepted answer is for OSM tiles. Actually the only difference between the formats is that the direction of the y-axis is inverted. – mipa Jan 16 '18 at 7:34

Your Answer

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

Browse other questions tagged or ask your own question.