Rasters.jl icon indicating copy to clipboard operation
Rasters.jl copied to clipboard

`reproject` is not conceptually correct on `Center` loci

Open rafaqz opened this issue 1 year ago • 8 comments

It seems to give slightly different results if shiftlocus(Center, rast) is used before or after reproject. This could be intrinsically from shiftlocus being weird on an Irregular lookup. But it needs investigation.

rafaqz avatar Dec 05 '24 17:12 rafaqz

I would expect some error, since the midpoint in the source space may not be the midpoint in the target space as well. See this example in web mercator, where the midpoint between 70 and 80 N is 75 N in lat long, but 75.84 N in web mercator. So the space matters, since it is a nonlinear scaling.

julia> using Proj

julia> trf = Proj.Transformation("EPSG:4326", "EPSG:3857"; always_xy = true)
Transformation pipeline
    description: axis order change (2D) + Popular Visualisation Pseudo-Mercator
    definition: proj=pipeline step proj=unitconvert xy_in=deg xy_out=rad step proj=webmerc lat_0=0 lon_0=0 x_0=0 y_0=0 ellps=WGS84
    direction: forward

julia> p1 = trf(0, 70)
(0.0, 1.1068715659379492e7)

julia> p2 = trf(0, 80)
(0.0, 1.5538711096309224e7)

julia> inv(trf)((p1 .+ p2) ./ 2)
(0.0, 75.83979753052014)

julia> inv(trf)
Transformation pipeline
    description: axis order change (2D) + Popular Visualisation Pseudo-Mercator
    definition: proj=pipeline step proj=unitconvert xy_in=deg xy_out=rad step proj=webmerc lat_0=0 lon_0=0 x_0=0 y_0=0 ellps=WGS84
    direction: inverse

asinghvi17 avatar Dec 05 '24 18:12 asinghvi17

Just updated the example btw

asinghvi17 avatar Dec 05 '24 18:12 asinghvi17

But we should document this!

asinghvi17 avatar Dec 05 '24 18:12 asinghvi17

Yeah. I guess for Intervals we should do the interval bounds properly and make them Explicit then do the center as well separately.

(and yes I'm noticing this a lot plotting norway/svalbard!)

rafaqz avatar Dec 05 '24 18:12 rafaqz

Hmm that is only necessary if the intervals are Center I think, because of the difference in the nature of the spaces. For Start or End, since the transform is invertible we already get this for free with irregular but implicit intervals.

asinghvi17 avatar Dec 05 '24 18:12 asinghvi17

Yeah the center moving is the problem. I guess instead it could just never return Center intervals

rafaqz avatar Dec 05 '24 19:12 rafaqz

This is also a nice candidate for bin edges style explicit...

asinghvi17 avatar Apr 27 '25 01:04 asinghvi17

Totally, still a bit weird that the centre won't be in the center

rafaqz avatar Apr 29 '25 07:04 rafaqz