ITADN

Albers projection `inbounds` check is too strict.

#336Openjamesrhester 创建于 2026-01-01
J
jamesrhestercommented
This issue was exposed by #335 . Consider the following error: ```julia julia> pt = Point(LatLon{GDA94}(-35.2, 142.1)) Point with GeodeticLatLon{GDA94} coordinates ├─ lat: -35.2° └─ lon: 142.1° julia> pt |> Proj(EPSG{3577}) ERROR: ArgumentError: coordinates outside of the projection domain: Albers{0.0°, -18.0°, -36.0°, GDA94, CoordRefSystems.Shift{Unitful.Quantity{Float64, NoDims, Unitful.FreeUnits{(°,), NoDims, nothing}}, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}(132.0°, 0.0 m, 0.0 m)} Stacktrace: [1] convert @ ~/programs/CoordRefSystems.jl/src/crs/projected.jl:197 [inlined] [2] _proj @ ~/.julia/packages/Meshes/dLMkX/src/transforms/proj.jl:82 [inlined] [3] applycoord @ ~/.julia/packages/Meshes/dLMkX/src/transforms/proj.jl:42 [inlined] [4] apply @ ~/.julia/packages/Meshes/dLMkX/src/transforms/proj.jl:34 [inlined] [5] Transform @ ~/.julia/packages/TransformsBase/w6gll/src/interface.jl:124 [inlined] [6] |>(x::Point{🌐, GeodeticLatLon{…}}, f::Proj{Albers{…}}) @ Base ./operators.jl:972 [7] top-level scope @ REPL[49]:1 ``` This error is clearly incorrect as the provided point is well within the typical range for the Australian Albers projection (3577). The error is caused because the value of rho returned by `_ambersp` in `albers.jl` is negative. It is negative because `n` is negative. `n` is negative because it behaves as `(cos(phi1)^2 - cos(phi2)^2)/(sin(phi2) - sin(phi1))`. If `phi1` and `phi2` are both positive, then this quotient is always positive. If both negative, it is always negative, which would mean any Albers projection in the southern hemisphere is not allowed. Looking at [the relevant line in the PROJ package](https://github.com/OSGeo/PROJ/blob/dae0354a866b7139825204bef38a50caf3057e82/src/projections/aea.cpp#L76), this check is there to make sure the square root of a negative number is not taken. However, in PROJ, this check is on the value of `C - n alpha`, not `sqrt(C-n alpha)/n` which is the case here. So there's no point checking the sign of rho after the square root is taken and this check should be removed or placed in `_ambersp`.
1 条评论