From 80d05112ff939485d0b8c7ab9f87af24fef4e076 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 24 Sep 2024 10:49:48 -0300 Subject: [PATCH] Add 'lenunit' option to Image loading --- src/extra/img.jl | 6 +++++- test/io/images.jl | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/extra/img.jl b/src/extra/img.jl index c40d244..1c7ad98 100644 --- a/src/extra/img.jl +++ b/src/extra/img.jl @@ -8,6 +8,10 @@ function imgread(fname; lenunit) values = (; color=vec(data)) # translation followed by rotation is faster transform = Translate(-dims[1], 0) → Rotate(-π / 2) - domain = CartesianGrid(dims) |> transform + # construct the grid + u = lenunit + origin = Point(ntuple(i -> 0.0u, length(dims))) + spacing = ntuple(i -> 1.0u, length(dims)) + domain = CartesianGrid(dims, origin, spacing) |> transform georef(values, domain) end diff --git a/test/io/images.jl b/test/io/images.jl index 833e4f3..28595b7 100644 --- a/test/io/images.jl +++ b/test/io/images.jl @@ -3,6 +3,10 @@ gtb = GeoIO.load(joinpath(datadir, "image.jpg")) @test gtb.geometry isa TransformedGrid @test length(gtb.color) == length(gtb.geometry) + + # custom lenunit + gtb = GeoIO.load(joinpath(datadir, "image.jpg"), lenunit=cm) + @test unit(Meshes.lentype(crs(gtb.geometry))) == cm end @testset "save" begin