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
transform_bounds does not appear to support bbox crossing the antimeridian #311
Comments
This seems like an issue for |
This problem affects EPSG:4326 projection especially. If not, sorry for bothering you. |
@yonda-yonda thanks for the issue! I will tend to think that this is a rasterio issue or a GDAL issue. rio-tiler now uses I've also encountered some weird behaviour of GDAL/Rasterio with coordinates outside the projection limits: https://github.com/developmentseed/morecantile/blob/master/tests/test_morecantile.py#L285-L287 We could patch I guess the issue is then |
FYI, instead of re-writting import rasterio
from rasterio.warp import transform_bounds
from rasterio.warp import transform
print(rasterio.__gdal_version__)
>>> 2.4.4
print(transform_bounds('EPSG:32601', 'EPSG:4326', 365474, 7591951, 477094, 7696071))
>>> (-179.90689695793938, 68.40816857051695, 179.96969316611757, 69.37306968939305)
x = (365474, 477094)
y = (7591951, 7696071)
xs, ys = transform('EPSG:32601', 'EPSG:4326', x, y)
print((xs[0], ys[0], xs[1], ys[1])
>>> (179.72295317650574, 68.40816857051695, -177.58262682964732, 69.37306968939305) Edits: 🤦 https://github.com/mapbox/rasterio/blob/master/rasterio/warp.py#L128 so yeah rasterio |
Sample GeoJSON
Apart from the antimeridian problem, If improve def tile_exists(self, tile_z: int, tile_x: int, tile_y: int) -> bool:
tile = Tile(x=tile_x, y=tile_y, z=tile_z)
tile_bounds = self.tms.bounds(*tile)
bounds = self.bounds[:]
if bounds[0] > bounds[2]:
if tile_bounds[0] < 0:
bounds[0] = -180
elif tile_bounds[2] > 0:
bounds[2] = 180
return (
(tile_bounds[0] < bounds[2])
and (tile_bounds[2] > bounds[0])
and (tile_bounds[3] > bounds[1])
and (tile_bounds[1] < bounds[3])
) It has to be that |
this is not really defined anywhere in the docs, but yeah Feel free to start a PR to improve |
I thought that's all I need are fixing Oh, dear. I'll think about it some more. |
Alright @yonda-yonda, first thanks for starting the PR I really appreciate it. Working with bounds, crs and antimeridan is definitely not an easy task. I'd like for us to take a step back and define clearly:
|
Problem is incorrect bounds and maxzoom/minzoom in scenes crossing the antimeridian. When found this problem, I thought this is a matter of how using rasterio and morecantile. We need to find more simpler solution in rio-tiler or improve rasterio/morecantile. |
example (EPSG:32601)
rasterio. warp.transform_bounds
return flattened bounds.correct bounds
(179.5819541972332, 68.40816857051695, -177.55854062377162, 69.37306968939305)
It seems to need checking transformed points is crossing the antimeridian.
For example, like this.
cogeo.bounds
,cogeo.get_zooms
,reader.part
, etc., a lot of methods to create tile are affected.Couldn't we improve?
The text was updated successfully, but these errors were encountered: