Skip to content

WIP: support attribute tables #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

tiemvanderdeure
Copy link
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

Copy link
Collaborator Author

@tiemvanderdeure tiemvanderdeure left a comment

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
Copy link
Owner

rafaqz commented Jun 27, 2025

Looks great!

# 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?
Copy link
Collaborator

@asinghvi17 asinghvi17 Jun 27, 2025

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?

Copy link
Collaborator

@asinghvi17 asinghvi17 Jun 27, 2025

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
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?

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
Collaborator

Choose a reason for hiding this comment

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

💯

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