Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hyzhak opened this issue May 7, 2017 · 12 comments

Comments

@hyzhak
Copy link

hyzhak commented May 7, 2017

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

@lucianpls
Copy link
Member

lucianpls commented May 7, 2017

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

@hyzhak
Copy link
Author

hyzhak commented May 7, 2017

@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

@hyzhak hyzhak closed this as completed May 7, 2017
@lucianpls
Copy link
Member

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.

@hyzhak
Copy link
Author

hyzhak commented May 7, 2017

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)

@lucianpls
Copy link
Member

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.

@hyzhak
Copy link
Author

hyzhak commented May 8, 2017

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
Copy link
Contributor

jeffreyrhall commented May 8, 2017 via email

@hyzhak
Copy link
Author

hyzhak commented May 9, 2017

@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?

@mcechini
Copy link
Collaborator

mcechini commented May 9, 2017

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! :)

@hyzhak
Copy link
Author

hyzhak commented May 9, 2017

@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 :)

@mcechini
Copy link
Collaborator

mcechini commented May 9, 2017

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.

@hyzhak
Copy link
Author

hyzhak commented May 9, 2017

@mcechini thanks! I will ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants