I'm following GIBS API for Developers and I need to convert long, lat of POI to col and row of tile for given zoom. For example to get right tile in endpoint like:


I'm using python and already tried few libs:

But didn't get right row, col values. As I see the main problem that all of them are basing on idea that lat map direct to y and you should just divide to 180˚ and mult to 2^zoom. But actually it doesn't work and it is very easy to check.

New Zealand location is about 41° 174°. And for zoom = 3 you should calc row that way:

row = int((90˚ + 41˚) / 180˚ * 2 ^ 3) ≈ int(5,8222) = 5 
col = int((180˚ + 174˚) / 180˚ * 2 ^ 3) ≈ int(15.73333) = 15

So here you should see New Zealand:


but actually we are out of tiles. Image:


<ExceptionReport xmlns="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd" version="1.1.0" xml:lang="en">
  <Exception exceptionCode="TileOutOfRange" locator="TILECOL">
    <ExceptionText>TILECOL is out of range, maximum value is 9</ExceptionText>
  <Exception exceptionCode="TileOutOfRange" locator="TILEROW">
    <ExceptionText>TILEROW is out of range, maximum value is 4</ExceptionText>

Why 4 and 9 are here?

As well for zoom = 0 it should be a whole planet on one tile, but not in NASA GIBS:

https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/MODIS_Terra_CorrectedReflectance_TrueColor/default/2016-09-03/250m/0/0/0.jpg : 0/0/0

so you could ever ask row=0,col=1 tile: 0/0/1

Why it is so strange and where am I wrong?

  • Did you look at the wmts standard? – Ian Turton May 7 '17 at 18:31
  • Do you mean this one portal.opengeospatial.org/files/?artifact_id=35326 ? it is about 129 pages so I have just looked thought it and didn't find algorithm of projection in any form. Can you point where could I find correct algorithm for projection long, lat to row, col of tile? – Eugene Krevenets May 7 '17 at 18:48
  • Appendix b I think but if you are writing a wmts client you should read all of it – Ian Turton May 7 '17 at 18:50
  • it has annexes only but no any appendixes. And Annex B about XML Schema Documents. Do you mean another wmts standard document? btw you could recommend any wmts clients in python which could work and fetch right tile or rectangle segment on long, lat and zoom. Because I don't really what to reinvent wheels but get any working python client to receive satellite images by long, lat – Eugene Krevenets May 7 '17 at 18:54
  • actually section 6.1 explains and Annex H has the pseudocode – Ian Turton May 7 '17 at 19:53

I've gotten comment from Lucian member of NASA team

For GIBS GCS, the level 0 resolution is 288 deg / tile, not 180 deg/tile. It was chosen to approximate the full resolution of the MODIS images, avoiding oversampling or undersampling, while still having full width tiles at most levels (2 and up).

Making this adjustment, the formula to use is:

row = ((90 - lat) * (2 ** level)) // 288
col = (180 + lon) * (2 ** level)) // 288

And it works!

Kia Ora cloudy New Zealand!

row = int((90˚ + 41˚) / 288˚ * 2 ^ 3) ≈ int(5,8222) = 3 
col = int((180˚ + 174˚) / 288˚ * 2 ^ 3) ≈ int(15.73333) = 9

https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/MODIS_Terra_CorrectedReflectance_TrueColor/default/2016-09-03/250m/3/3/9.jpg 3/3/9

| improve this answer | |

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.