Skip to content

WIP: support attribute tables#987

Draft
tiemvanderdeure wants to merge 2 commits into
mainfrom
tvd/attributetable
Draft

WIP: support attribute tables#987
tiemvanderdeure wants to merge 2 commits into
mainfrom
tvd/attributetable

Conversation

@tiemvanderdeure

Copy link
Copy Markdown
Collaborator

Implements a new modification for raster attribute tables. In this standard, the .tif contains integers which correspond to a row in an attribute table.

It's a pretty obscure standard. One example I've seen have integer values 0,1,2,3, and the other has 0, 12,13,14 for some reason. One has a column called VALUE and the other Value.

The idea here is to store a dict in a AbstractModifications and then just perform a lookup within readblock!

GDAL reads some of these tables but not all and then can have different file extension names, so _tablemod I still need to implement

@tiemvanderdeure tiemvanderdeure left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally I've just implemented _tablemod like this

function Rasters._tablemod(filename, missingval, name::Rasters.NoKW)
    table = Tables.columntable(DBFTables.Table(filename))
    idx = findfirst(k -> k !== :VALUE && k !== :COUNT && k !== :Value && k !== :Count, keys(table))
    name = keys(table)[idx]
    return Rasters.AttributeMod(table, name, missingval)
end

function Rasters._tablemod(filename, missingval, name::Symbol)
    table = Tables.columntable(DBFTables.Table(filename))
    return Rasters.AttributeMod(table, name, missingval)
end

This works at least for the example I posted in #921

@tiemvanderdeure tiemvanderdeure marked this pull request as draft June 27, 2025 11:52
@rafaqz

rafaqz commented Jun 27, 2025

Copy link
Copy Markdown
Owner

Looks great!

Comment thread src/array.jl
# Generate mod for scaling
mod = isnokw(mod) ? _mod(eltype(var), metadata_out, missingval_out; scaled, coerce) : mod
mod = if isnokw(mod)
if !raw && isfile(filename .* ".vat.dbf") # todo: how to detect a RAT/VAT?

@asinghvi17 asinghvi17 Jun 27, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this be able to pick up ArchGDAL rats. Maybe that goes in the extension?

@asinghvi17 asinghvi17 Jun 27, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because those have .tif.rat or something which is a different format...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I have to think about how to check for all of that. I'm not sure if there are more formats than just those two? And if different file extensions than .tif could have a RAT or something similar?

Comment thread src/modifieddiskarray.jl
function AttributeMod(table::NamedTuple, column::Symbol, missingval::Mi) where {Mi}
keycol = identity.(first(table))
valcol = identity.(table[column])
dict = DD.OrderedCollections.LittleDict(keycol, valcol) |> DD.OrderedCollections.freeze

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@asinghvi17 asinghvi17 moved this to In progress in SDSL 25 planning Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants