3

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
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Schedonn
  • 31
  • 4
  • did you read the standard - http://www.opengeospatial.org/standards/wmts – Ian Turton Jan 16 '18 at 07:25
  • This question has been answered here: https://gis.stackexchange.com/questions/133205/wmts-convert-geolocation-lat-long-to-tile-index-at-a-given-zoom-level – mipa Jan 16 '18 at 07:27
  • @mipa This doesn't work for me. The OSM and the WMTS format seem to be different. – Schedonn Jan 16 '18 at 07:30
  • @IanTurton I have already searched in the WMTS standard, but couldn't find a clear formular. – Schedonn Jan 16 '18 at 07: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 07:34
  • @mipa Strange, I already tried inverting the y-axis. Hang on, I will build an example and edit my question. – Schedonn Jan 16 '18 at 07:47
  • at zoom level 13 there are 8192 tiles per axis (index 0 - 8191). for OSM, the tile index for your given lat is 2758 (y index increasing top to bottom). for WMTS (y index increasing bottom to top) the same tile index is (8191 - 2758 = ) 5433. in the formula you referred to, replace 'n * (1 - ...' with 'n * (1 + ...' – geozelot Jan 16 '18 at 15:17
  • ...wait, also you get the right result when you invert by 1 << 13 - tileLat - 1 (5433). of course you cannot use zoom=12 for that if your index is based on zoom=13. why is the expected result 897??? – geozelot Jan 16 '18 at 15:32
  • @ThingumaBob 897 is expected because it is the tile where Wetzlar is in the centre. If I put 5433 in my request I get an error which says: "Row 5433 is out of range, min: 872 max:924" – Schedonn Jan 17 '18 at 06:25
  • This is how the query in my request looks like: TILEMATRIXSET=EPSG:4326&TILEMATRIX=EPSG:4326:12&TILEROW=5433&TILECOL=4289 My interpretation is that "EPSG:4326:12" is the zoom level and TILEROW and TILECOL are the x and y values. Or am I missing something? – Schedonn Jan 17 '18 at 06:25
  • yes (TILECOL is x)...could you maybe post your getCapabilities XML? you seem to have an unusual tile matrix origin, tile size or scale settings... – geozelot Jan 17 '18 at 07:14
  • I uploaded my getCapabilities XML. The layer I use in my request is hessen:hessen. Don't let the name fool you, it is the whole world map. – Schedonn Jan 17 '18 at 07:35

0 Answers0