Skip to content

Commit

Permalink
Fix 'affineparams2D'
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Nov 25, 2024
1 parent 0db7a86 commit e9622a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/userutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
26 changes: 26 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GeoTIFF
using TiffImages
using ColorTypes
using StaticArrays
using FixedPointNumbers
using Test

Expand Down Expand Up @@ -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)
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit e9622a9

Please sign in to comment.