From b761f79ae72accf090adf092f39c301538276b00 Mon Sep 17 00:00:00 2001 From: Elias Carvalho <73039601+eliascarv@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:50:53 -0300 Subject: [PATCH] Fix 'affineparams2D' (#15) --- src/userutils.jl | 9 ++++++++- test/Project.toml | 1 + test/runtests.jl | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/userutils.jl b/src/userutils.jl index c45a131..734c33b 100644 --- a/src/userutils.jl +++ b/src/userutils.jl @@ -113,7 +113,14 @@ function affineparams2D(metadata::Metadata) b = SA[tx, ty] A, b elseif !isnothing(transformation) - transformation.A[1:2, 1:2], transformation.b[1:2] + Aₜ = transformation.A + bₜ = transformation.b + A = SA[ + Aₜ[1, 1] Aₜ[1, 2] + Aₜ[2, 1] Aₜ[2, 2] + ] + b = SA[bₜ[1], bₜ[2]] + A, b else nothing end diff --git a/test/Project.toml b/test/Project.toml index b5c967d..d1db2b6 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,5 +1,6 @@ [deps] ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TiffImages = "731e570b-9d59-4bfa-96dc-6df516fadf69" diff --git a/test/runtests.jl b/test/runtests.jl index 663a40f..6a13d43 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using GeoTIFF using TiffImages using ColorTypes +using StaticArrays using FixedPointNumbers using Test @@ -32,7 +33,11 @@ savedir = mktempdir() @test isnothing(GeoTIFF.modeltype(metadata)) @test isnothing(GeoTIFF.epsgcode(metadata)) @test GeoTIFF.affineparams2D(metadata) == (A2D, b2D) + @test GeoTIFF.affineparams2D(metadata)[1] isa SMatrix + @test GeoTIFF.affineparams2D(metadata)[2] isa SVector @test GeoTIFF.affineparams3D(metadata) == (A3D, b3D) + @test GeoTIFF.affineparams3D(metadata)[1] isa SMatrix + @test GeoTIFF.affineparams3D(metadata)[2] isa SVector geotiff = GeoTIFF.load(joinpath(datadir, "test_gray.tif")) metadata = GeoTIFF.metadata(geotiff) @@ -42,7 +47,11 @@ savedir = mktempdir() @test isnothing(GeoTIFF.modeltype(metadata)) @test isnothing(GeoTIFF.epsgcode(metadata)) @test GeoTIFF.affineparams2D(metadata) == (A2D, b2D) + @test GeoTIFF.affineparams2D(metadata)[1] isa SMatrix + @test GeoTIFF.affineparams2D(metadata)[2] isa SVector @test GeoTIFF.affineparams3D(metadata) == (A3D, b3D) + @test GeoTIFF.affineparams3D(metadata)[1] isa SMatrix + @test GeoTIFF.affineparams3D(metadata)[2] isa SVector # tiff files with metadata geotiff = GeoTIFF.load(joinpath(datadir, "utm.tif")) @@ -55,6 +64,8 @@ savedir = mktempdir() A = [121.52985600000001 0.0; 0.0 -164.762688] b = [688258.223819, 4.555765966137e6] @test GeoTIFF.affineparams2D(metadata) == (A, b) + @test GeoTIFF.affineparams2D(metadata)[1] isa SMatrix + @test GeoTIFF.affineparams2D(metadata)[2] isa SVector # GeoTIFF format swaps axis order geotiff = GeoTIFF.load(joinpath(datadir, "natural_earth_1.tif")) @@ -68,6 +79,8 @@ savedir = mktempdir() A = [2.222222222222001 0.0; 0.0 -2.222222222222001] b = [-180.0, 90.0] @test GeoTIFF.affineparams2D(metadata) == (A, b) + @test GeoTIFF.affineparams2D(metadata)[1] isa SMatrix + @test GeoTIFF.affineparams2D(metadata)[2] isa SVector end @testset "GeoTIFFImage" begin @@ -149,6 +162,19 @@ savedir = mktempdir() @test GeoTIFF.epsgcode(metadata2) === GeoTIFF.epsgcode(metadata1) @test GeoTIFF.affineparams2D(metadata2) === GeoTIFF.affineparams2D(metadata1) + file1 = joinpath(datadir, "natural_earth_1.tif") + file2 = joinpath(savedir, "natural_earth_1.tif") + geotiff1 = GeoTIFF.load(file1) + GeoTIFF.save(file2, geotiff1) + geotiff2 = GeoTIFF.load(file2) + metadata1 = GeoTIFF.metadata(geotiff1) + metadata2 = GeoTIFF.metadata(geotiff2) + @test eltype(geotiff2) === eltype(geotiff1) + @test GeoTIFF.rastertype(metadata2) === GeoTIFF.rastertype(metadata1) + @test GeoTIFF.modeltype(metadata2) === GeoTIFF.modeltype(metadata1) + @test GeoTIFF.epsgcode(metadata2) === GeoTIFF.epsgcode(metadata1) + @test GeoTIFF.affineparams2D(metadata2) === GeoTIFF.affineparams2D(metadata1) + # tiff files file = joinpath(savedir, "tiff_file.tiff") tiff = TiffImages.load(joinpath(datadir, "test.tif"))