-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Invalid VRT Size when converting from EPSG:4326 to EPSG:3857 #8730
Comments
Do you expect that gdalwarp would automatically crop the output according to the valid area of the target srs, in this case [World between 85.06°S and 85.06°N]? Like what can to done manually
Automatic clip feels like a heavy tool because sometimes it is OK to go over the area of use, for example if the source data comes around the boundary between adjacent UTM zones. The problem comes from you asking gdalwarp to do something that is not possible, but how would you like to be informed about that? |
I believe gdalwarp is behaving as it is designed. Latitude 90 projects to infinity in EPSG:3857 in theory. In practice due to numeric imprecision it converts to a huge northing value. Then gdalwarp tries to figure out an output resolution for that, which gives a huge skew toward the Y axis, and thus explains the contraction on the X axis |
👍
That's what I thought too. Do you thing a warning will be possible for this case? |
It is certainly possible but is it worth it? Generally it is normal to go a little bit beyond the "area of use" and the transformation mathematics are accurate enough. So how to define the threshold for what is acceptable and what not? That said, you are not the first person that I have helped with this "whole world into Web Mercator" issue. |
Well right now this will lead to a really weird VRT Just for context, I do not have an issue with a specific file but I'm just trying to make sure my library can handle this kind of edge cases. At the end of the day, I do not really need a full VRT but I need the VRT |
I don't believe there's a clean solution to your problem here Vincent, getting the resolution requires dividing a geographical extent by some number of pixels, but in your case that extent is infinity 🤷♂️ |
Right, it looks odd. It is caused by an user error but users do not know automatically what are the limits of the CRS what they are using. I am also just a user but I know the limits of 3857 because I have done that error so many times. If EPSG:4326 -> EPSG:3857 is a common use case for your library, maybe you could implement the latitude cut -85 - 85 degrees into the library? But of course North Pole as EPSG:3857 is not the only impossible transformation that exists. |
…graphic to Mercator (typically EPSG:3857) (fixes OSGeo#8730)
in #8740, I've added a heuristics for that special case. Hopefully I'm not opening a can of worms here... |
@rouault I was just writing a similar suggestion wrt EPSG:3857 since it's such a common target CRS. I guess a more generic path would be Proj having a mechanism to warn users that they're operating outside the area of use for their CRS and they should expect odd things to happen. |
Actually that kind of mechanism is already running somewhere. I found 32 hits from gis.stackexchange about warnings like this
Problem with a straight-lined Proj mechanism would be to decide the tolerances. Working outside the official area of use is rather common (e.g. combining data from adjacent UTM zones) and sometimes the transformations give reasonable and reversible results far away from the nominal area of use. |
That's an interesting idea, but as often with map projections, things are tricky. For example for UTM projections, the recommended area of use is +/- 3 deg of longitude around the central meridian. But the ellipsoidal formulation of transverse mercator exists for all points of the spheroid, and the implementation in PROJ >= 4.9 is quite exact. Not fully exact, but it gives accurate results up to +/- 120 degree (perhaps even 150) away from the central meridian, and doing "gdalwarp autotest/gdrivers/data/small_world.tif out.tif -t_srs EPSG:32631 -overwrite" gives a very reasonable output for the whole world. So for a UTM projection, the area of use is mostly a loose indication, whereas for a Mercator one, it is close to be a constraint. |
Of course 😁 And the EPSG database isn't perfect either, I've personally filed a number of area-of-use bugfixes. I guess I was suggesting more of a method of warning that GDAL/OGR could propagate to the user. $ gdalwarp -of VRT -t_srs epsg:3857 world_cog.tif world_cog.vrt
WARNING: coordinate transform is operating outside the nominal area of use for EPSG:3857, which may cause problems. See https://proj.org/E12345 for more details.
Creating output file that is 66P x 802L. As you saying, ignoring the 6° bands for Transverse Mercator projections won't do anything violently terrible, but it might be a useful prompt for the user. We definitely couldn't do any automated clipping for most CRS (Polar Stereographic comes to mind alongside Mercator). |
I've been considering the case of stereographic, where the warper tries to conserve the resolution and goes for a huge extent rather than put a bounds on the number of output pixels. It seems like suggested warp output should have heuristics for number of pixels that can potentially override the quest to maintain pixel resolution across the entire expansive domain. I'll check out #8740 but I've been thinking about this in terms of what the suggested output function provides, and perhaps that's a place to add features (preserve domain, preserve resolution, cap-on-num-pixels, preserve-aoi) and put config options around those. |
gdalwarp: add a heuristic to clamp northings when projecting from geographic to Mercator (typically EPSG:3857) (fixes #8730)
…graphic to Mercator (typically EPSG:3857) (fixes #8730)
[Backport release/3.8] gdalwarp: add a heuristic to clamp northings when projecting from geographic to Mercator (typically EPSG:3857) (fixes #8730)
…graphic to Mercator (typically EPSG:3857) (fixes OSGeo#8730)
ref: cogeotiff/rio-tiler#654
Expected behavior and actual behavior.
I've got a file which span the entire world (in epsg:4326,
-180 90 180 -90
), when building a VRT in EPSG:3857 the result size seems wrong.I'm pretty sure this is because the bounds over flows the area of use of the EPSG:3857 projection.
The
Y
size (802) seems ok but theX
(66) is definitely wrong.When I use dataset which doesn't cross the
area of use
everything is fine!I'm not sure exactly if the issue in either in proj or in GDAL and if anything is possible 🤷
Steps to reproduce the problem.
Operating system
Mac OS / CentOS (AWS Lambda)
GDAL version and provenance
GDAL 3.7.2 (homebrew)
GDAL 3.8 (docker)
The text was updated successfully, but these errors were encountered: