Skip to content

Commit

Permalink
Update to the latest version of GeoTIFF.jl (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv authored Nov 25, 2024
1 parent 6720274 commit d40ec99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GeoFormatTypes = "0.4"
GeoInterface = "1.0"
GeoJSON = "0.8"
GeoParquet = "0.1, 0.2"
GeoTIFF = "0.2"
GeoTIFF = "0.3"
GeoTables = "1.24.0"
GslibIO = "1.5"
ImageIO = "0.6"
Expand Down
14 changes: 6 additions & 8 deletions src/extra/geotiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ function geotiffread(fname; kwargs...)

# georeferenced grid
pipe = _pipeline(geotiff)
dims = size(geotiff) |> reverse
domain = CartesianGrid(dims) |> pipe
img = GeoTIFF.image(geotiff)
domain = CartesianGrid(size(img)) |> pipe

# adjust the image orientation
column(x) = vec(PermutedDimsArray(x, (2, 1)))
# table with colors or channels
table = if eltype(geotiff) <: Colorant
(; color=column(geotiff))
(; color=vec(img))
else
nchanels = GeoTIFF.nchannels(geotiff)
channel(i) = column(GeoTIFF.channel(geotiff, i))
channel(i) = vec(GeoTIFF.channel(geotiff, i))
(; (Symbol(:channel, i) => channel(i) for i in 1:nchanels)...)
end

Expand Down Expand Up @@ -92,8 +90,8 @@ function geotiffwrite(fname, geotable; kwargs...)
# construct the metadata
metadata = GeoTIFF.metadata(; transformation=(A, b), rastertype, modeltype, projectedcrs, geodeticcrs)

# reshape back to GeoTIFF orientation
image(x) = PermutedDimsArray(reshape(x, dims), (2, 1))
# reshape column back to image
image(x) = reshape(x, dims)
if iscolor
# the column contains valid colors
colors = image(Tables.getcolumn(table, first(names)))
Expand Down

0 comments on commit d40ec99

Please sign in to comment.