-
Notifications
You must be signed in to change notification settings - Fork 523
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
Rasterio warp issue for antimeridian bounding box #2222
Comments
It's not necessarily the same, @snowman2. While the antimeridian results in coordinates that are confusing, they are usually correct. From the notebook I linked above, coordinates from Proj and from Rasterio are as follows:
Note that both have issues, in that Proj coordinates have on X coord at 175 and the other at -170, which is painful to handle. While the Rasterio coordinates are just plain wrong! |
Can you try |
Perfect, that is what I was hoping to see. When you run into that scenario, you will have to split the boundary by the antimeridian and end up with two bounding polygons. |
This is the logic to handle it: if maxx < minx:
return shapely.geometry.MultiPolygon(
[
shapely.geometry.box(minx, miny, 180, maxy),
shapely.geometry.box(-180, miny, maxx, maxy),
]
)
return shapely.geometry.box(minx, miny, maxx, maxy) NOTE: Only for geographic coordinates. |
Hmm. In the above example, the input coordinates are projected, so it's not until they're transformed that you know it crosses the antimeridian. My solution is to do this, because I know that the features I'm working with are reasonable small: transformer = Transformer.from_crs(crs, "EPSG:4326", always_xy=True)
x_min, y_min = transformer.transform(bbox[0], bbox[1])
x_max, y_max = transformer.transform(bbox[2], bbox[3])
# Stupid dateline!
if abs(x_max - x_min) > 90:
if x_max < 0:
x_max += 360
if x_min < 0:
x_min += 360 |
Correct, I am suggesting to run the code above after projecting to geograpic. You can use the Side note: |
So Proj is fine, although, handling transformed coords is still non-trivial. I'm not sure if it's an outstanding issue in Rasterio, but the latest version installable via pip is broken, as shown above. |
Added to rasterio #2208, targeted for 1.3 release. |
Thanks for the report @alexgleith, and thank you for the help @snowman2 . My understanding is that our geometry transformer |
I haven’t tested it, but I believe it’s fixed in 1.3
|
-->
Expected behavior and actual behavior.
Transformation between two coordinate systems yields the correct result
Steps to reproduce the problem.
Notebook is here: https://gist.github.com/alexgleith/f94f3f3da2f43dd6cfab84eb9d8a13f7
Key code is this:
Operating system
For example: Mac OS X 10.15.7
Rasterio version and provenance
Rasterio 1.2.6 installed on a mac with --no-binary against GDAL 3.3.0, released 2021/04/26
The text was updated successfully, but these errors were encountered: