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

Image bounds are in geographic coordinate system #354

Closed
mcvittal opened this issue Feb 17, 2021 · 5 comments
Closed

Image bounds are in geographic coordinate system #354

mcvittal opened this issue Feb 17, 2021 · 5 comments

Comments

@mcvittal
Copy link

mcvittal commented Feb 17, 2021

Hello!

I'm not sure what I'm doing wrong here, but I'm trying to generate tiles from a GeoTIFF, but it can't assess that a tile is within its bounds because in the tile_exists method within base.py, the bounds array contains geographic lat/lon coordinates instead of projected coordinates.

My basic code is as follows:

from rio_tiler.io import COGReader 

with COGReader("myraster_projected.tif") as img:
  img.tile(1, 1, 1)

Which throws the error

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/mnt/c/Users/Alex/WORK/coding/landsat-tiler/rio-tiler/rio_tiler/io/cogeo.py", line 264, in tile
    raise TileOutsideBounds(
rio_tiler.errors.TileOutsideBounds: Tile 1/1/1 is outside myraster_projected.tif bounds

I've tried re-projecting my raster to EPSG:3857 but the issue still prevails - I've added some print statements to get the bounds array contents and it still prints out that it is in a geographic coordinate system. Is there an additional step I should be doing?

@vincentsarago
Copy link
Member

Hi @mcvittal thanks for opening the issue.

the error message says that the Mercator Tile x=1, y=1, z=1 bounds coordinates do no intersect with your raster bounds.

what is the output of

from rio_tiler.io import COGReader
import morecantile

tms = morecantile.tms.get("WebMercatorQuad")
print(tms.bounds(1, 1, 1)

with COGReader("myraster_projected.tif") as img:
    print(img.bounds)

@mcvittal
Copy link
Author

Thanks for the quick reply!

This outputs

BoundingBox(left=-2.0078911277343066e-13, bottom=-85.05112877980652, right=179.9999999999992, top=2.0355549961366507e-13)

(2.125432099751016, 48.64001935810568, 2.147842404720507, 48.65631726102131)

@vincentsarago
Copy link
Member

BoundingBox(left=-2.0078911277343066e-13, bottom=-85.05112877980652, right=179.9999999999992, top=2.0355549961366507e-13)

(2.125432099751016, 48.64001935810568, 2.147842404720507, 48.65631726102131)

☝️ shows that your raster doesn't intersect with tile 1-1-1 (latitude of your file is ~48 North, while grid max lat is ~0)

I'm going to close this issue because it's not bug, but please feel free to re-open if you feel the documentation should better explain that we cannot read tiles that are outside your raster bounds 🙏

@mcvittal
Copy link
Author

I'm just a little bit confused here. The image is a small high-res image located in Paris, France (Hence the location of 2, 48) - this should be well within the bounds of the Web Mercator maximum and minimum bounds. I'm trying to serve this as a tiled webmap, and thought that this tool would be the best way to do something like this on the fly. Below is a screenshot of the image with a Google Maps basemap:

image

Obviously, at zoom level 1, it would be a pretty useless webmap tile as it is very small, but it should be able to generate something at least.

@vincentsarago
Copy link
Member

@mcvittal you are right, rio-tiler can create tile from you file (but I wouldn't recommend using it for really low zoom level).
The error you are experiencing for tile 1-1-1 is absolutely expected, the tile x=1, y=1, z=1 DO NOT intersect with your file thus rio-tiler CANNOT read the corresponding data for the tile bounds ... because it doesn't exist.

if you try tile x=1, y=0, z=1. it should work (but it will be really memory intensive: see #348)

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

2 participants