From e2af018a711754f972eec973f267d0fe24a3425a Mon Sep 17 00:00:00 2001 From: Maarten Pronk Date: Sat, 28 Feb 2026 14:50:36 +0100 Subject: [PATCH] Fix broken GeoArray constructor (issue #184) The constructor on line 42 was defined as GeoArray(A) referencing undefined variables f and crs. Fixed to GeoArray(A, f, crs::String) matching the docstring above it. Added tests for all constructor variants. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/geoarray.jl | 2 +- test/test_geoarray.jl | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/geoarray.jl b/src/geoarray.jl index 3fe9381..7bf5233 100644 --- a/src/geoarray.jl +++ b/src/geoarray.jl @@ -39,7 +39,7 @@ GeoArray(A::MatrixorArray where {T<:NumberOrMissing}, f::AffineMap) = GeoArray(A Construct a GeoArray from any Array and an `AffineMap` that specifies the coordinates and `crs` string in WKT format. """ -GeoArray(A) = GeoArray(A, f, GFT.WellKnownText(GFT.CRS(), crs), Dict{String,Any}()) +GeoArray(A, f, crs::String) = GeoArray(A, f, GFT.WellKnownText(GFT.CRS(), crs), Dict{String,Any}()) GeoArray(A, f, crs::String, d) = GeoArray(A, f, GFT.WellKnownText(GFT.CRS(), crs), d) GeoArray(A, f, crs) = GeoArray(A, f, crs, Dict{String,Any}()) GeoArray(A, f::AffineMap{Matrix{Float64},Vector{Float64}}, args...) = GeoArray(A, AffineMap(SMatrix{2,2}(f.linear), SVector{2}(f.translation)), args...) diff --git a/test/test_geoarray.jl b/test/test_geoarray.jl index 79ce1c7..f4da333 100644 --- a/test/test_geoarray.jl +++ b/test/test_geoarray.jl @@ -1,4 +1,6 @@ using CoordinateTransformations +import GeoFormatTypes as GFT +using StaticArrays @testset "Indexing" begin x = GeoArray(rand(5, 5, 5)) @@ -72,6 +74,37 @@ end end x, y = range(4, stop=8.0, length=11), range(0, stop=1, length=9) @test_throws ErrorException GeoArray(rand(10, 9), x, y) + + # Test array-only constructor (issue #184) + ga = GeoArray(rand(5, 5)) + @test ga isa GeoArray + @test size(ga) == (5, 5) + ga = GeoArray(rand(5, 5, 3)) + @test ga isa GeoArray + @test size(ga) == (5, 5, 3) + + # Test AffineMap + String CRS constructor (issue #184) + f = GeoArrays.geotransform_to_affine(SVector(0.0, 1.0, 0.0, 0.0, 0.0, 1.0)) + ga = GeoArray(rand(5, 5), f, "") + @test ga isa GeoArray + @test GFT.val(ga.crs) == "" + ga = GeoArray(rand(5, 5, 3), f, "EPSG:4326") + @test ga isa GeoArray + @test GFT.val(ga.crs) == "EPSG:4326" + + # Test AffineMap-only constructor + ga = GeoArray(rand(5, 5), f) + @test ga isa GeoArray + + # Test AffineMap + WKT CRS constructor + ga = GeoArray(rand(5, 5), f, GFT.WellKnownText(GFT.CRS(), "")) + @test ga isa GeoArray + + # Test AffineMap + String CRS + metadata constructor + ga = GeoArray(rand(5, 5), f, "EPSG:4326", Dict{String,Any}("key" => "value")) + @test ga isa GeoArray + @test GFT.val(ga.crs) == "EPSG:4326" + @test ga.metadata["key"] == "value" end @testset "Conversions" begin