Skip to content

Commit

Permalink
Fix the Morphological transform used in geotiffread (#141)
Browse files Browse the repository at this point in the history
* Fix the 'Morphological' transform used in 'geotiffread'

* Add more tests
  • Loading branch information
eliascarv authored Nov 25, 2024
1 parent 0340d61 commit 24c8d55
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/extra/geotiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,16 @@ function _morphological(metadata)
else
epsg = EPSG{Int(code)}
CRS = CoordRefSystems.get(epsg)
Morphological() do coords
raw = CoordRefSystems.raw(coords)
CoordRefSystems.reconstruct(CRS, raw)
if CRS <: LatLon
Morphological() do coords
lon, lat = CoordRefSystems.raw(coords)
CRS(lat, lon)
end
else
Morphological() do coords
x, y = CoordRefSystems.raw(coords)
CRS(x, y)
end
end
end
end
Expand Down
Binary file added test/data/natural_earth_1.tif
Binary file not shown.
Binary file added test/data/natural_earth_1_projected.tif
Binary file not shown.
37 changes: 37 additions & 0 deletions test/io/geotiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
@test gtb.geometry isa CartesianGrid
@test size(gtb.geometry) == (108, 108)

# the "natural_earth_1.tif" file is an upscale of a NaturalEarth file
# link: https://www.naturalearthdata.com/downloads/10m-raster-data/10m-natural-earth-1/
file = joinpath(datadir, "natural_earth_1.tif")
gtb = GeoIO.load(file)
@test crs(gtb.geometry) <: LatLon
@test propertynames(gtb) == [:color, :geometry]
@test eltype(gtb.color) <: Colorant
@test gtb.geometry isa TransformedGrid
@test size(gtb.geometry) == (162, 81)

# the "natural_earth_1_projected.tif" file is a project version of "natural_earth_1.tif"
file = joinpath(datadir, "natural_earth_1_projected.tif")
gtb = GeoIO.load(file)
@test crs(gtb.geometry) <: PlateCarree
@test propertynames(gtb) == [:color, :geometry]
@test eltype(gtb.color) <: Colorant
@test gtb.geometry isa TransformedGrid
@test size(gtb.geometry) == (162, 81)

# the "utm.tif" file is from the GeoTIFF/test-data repo
# link: https://github.com/GeoTIFF/test-data/blob/main/files/utm.tif
file = joinpath(datadir, "utm.tif")
Expand Down Expand Up @@ -55,6 +74,24 @@
@test values(gtb1) == values(gtb2)
@test values(gtb1, 0) == values(gtb2, 0)

file1 = joinpath(datadir, "natural_earth_1.tif")
file2 = joinpath(savedir, "natural_earth_1.tif")
gtb1 = GeoIO.load(file1)
GeoIO.save(file2, gtb1)
gtb2 = GeoIO.load(file2)
@test isapprox(gtb1.geometry, gtb2.geometry, atol=1e-6u"m")
@test values(gtb1) == values(gtb2)
@test values(gtb1, 0) == values(gtb2, 0)

file1 = joinpath(datadir, "natural_earth_1_projected.tif")
file2 = joinpath(savedir, "natural_earth_1_projected.tif")
gtb1 = GeoIO.load(file1)
GeoIO.save(file2, gtb1)
gtb2 = GeoIO.load(file2)
@test isapprox(gtb1.geometry, gtb2.geometry, atol=1e-6u"m")
@test values(gtb1) == values(gtb2)
@test values(gtb1, 0) == values(gtb2, 0)

# float data
# single channel
file = joinpath(savedir, "float_single.tif")
Expand Down

0 comments on commit 24c8d55

Please sign in to comment.