Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/geoarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
33 changes: 33 additions & 0 deletions test/test_geoarray.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using CoordinateTransformations
import GeoFormatTypes as GFT
using StaticArrays

@testset "Indexing" begin
x = GeoArray(rand(5, 5, 5))
Expand Down Expand Up @@ -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
Expand Down
Loading