nasa-gibs/onearth

How could I get right tile (WGS 84 / Lat-lon / Geographic / EPSG:4326) by long, lat and zoom?

hyzhak opened this issue ยท 12 comments

I'm trying to get tile by long, lat and zoom by formula:

row = int((90 - lat) / 180 * 2 ** zoom)
col = int((180 + lon) / 180 * 2 ** zoom)

but it doesn't work.
Here is related question https://gis.stackexchange.com/questions/239496/how-to-convert-long-lat-to-a-tile-of-nasa-gibs-wgs-84-lat-lon-geographic

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

@lucianpls oh big thanks it works ๐ŸŽ‰ !

I've spent weekend on it trying understand why it doesn't work ๐Ÿ˜ซ , you should put this magic number into wiki of GIBS or something like that, it will be very helpful

If you fetch and process the WMTS capabilities response from GIBS, you'll find all the information there, just as the standard requires. But there are hardly any software clients that do that, most expect a binary division of the whole world. Which only works for global projections and for a fixed set of resolutions.

If you have real data and you don't want to distort it too much, using custom tiling grids is the only choice.

hm, sadly I'm not so deep in GIS yet. What do you mean by a binary division of the whole world.?
Could I find any article with recommendations -- what is the best way (best practice) to prepare GIBS data to work with? I'm using python related libs (numpy, scipy, pandas, tensorflow and etc)

Web Mercator assumes the world map fits in a square tile of 256x256, then keeps subdividing. There is also a GCS grid where the whole world fits in two tiles side by side at top level, the way your original formula works. There are no partial content tiles ever. Those are the most common tiling schemes.

You might want to look at GDAL, it has python bindings and knows how to fetch the data from GIBS, using the GDAL WMS, hiding the tiling aspect.

Thanks! Yes, I'm using both projections and going to try EPSG:3413 and EPSG:3031 as well. Btw could you point which transformation could I use for them and do they have additional coefficients like EPSG:4326 has?

Btw, I know it is completely unrelated to current issue, but is these issues good place for asking questions slightly related to how is it better to work with NASA GIBS?

  • I'm trying to show gif animation of Earth random rectangle area. Thanks to you I've found how to get tile by location (bbox) but is there any tool which sticks and animates GIBS tiles?

@jeffreyrhall @lucianpls thanks for your help! btw after some searching I've found that other folks use another much more useful API, based on https://gibs.earthdata.nasa.gov/image-download endpoint. I wonder why I can't find any information about this endpoint on noted wiki https://wiki.earthdata.nasa.gov/ or official NASA pages?

That endpoint is not a standards-based service and is not an official GIBS imagery endpoint. Obviously, we're not obscuring its existence for those that can sniff it out in the web traffic. Access methods such as the GDAL WMS driver described previously leverage our more efficient tile-based APIs. Image download currently does not, which has performance implications for both server and client. This is something we may formally support in the future, but for now it is not advertised.

With regards to providing a simple way to get the tile for a specified lat/lon/zoom... others have provided the math in here. However, this is one of those things that it would be nice if we had a script in our toolkit that one could run. I know I would benefit. Feel free to contribute to the open source project if you want! :)

@mcechini Big thanks for your help! I love NASA open data, and I like hack it :).

And actually these issues are part of my space apps challenge project https://github.com/botstory/nasa-bot where I try to create chat bot assistant to GIBS dataset :). I thought it would be much easy but stuck exactly on trying to show right map region by coords so noted endpoint https://gibs.earthdata.nasa.gov/image-download would save a lot of time on prototyping phase. But actually I have almost done client to download and compose map animation and once it would work property I could extract it to separate python utility/service which could be used for creating map animation. Hope I'm not reinventing the wheels :)

Sounds like great work. If there are things you want to contribute back to the project, we can take a look if there is a place for it.

@mcechini thanks! I will ;)