Skip to content

flesh out GI for tables and rows #136

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Base.propertynames(row::Row) = [:geometry, propertynames(getfield(row, :record))

GeoInterface.isfeature(t::Row) = true
GeoInterface.geometry(t::Row) = getfield(t, :geometry)
GeoInterface.properties(t::Row) = getfield(t, :record)
GeoInterface.properties(t::Row) = NamedTuple(getfield(t, :record)) # convert to namedtuple, always
GeoInterface.trait(::Row) = GeoInterface.FeatureTrait()

"""
Expand Down Expand Up @@ -97,8 +97,6 @@ Tables.columns(t::Table) = t
Tables.rowaccess(::Type{<:Table}) = true
Tables.columnaccess(::Type{<:Table}) = true



"""
Base.iterate(t::Table)

Expand Down Expand Up @@ -152,7 +150,16 @@ Get a vector of the geometries in a shapefile `Table`, without any metadata.
"""
shapes(t::Table) = shapes(getshp(t))

GeoInterface.extent(t::Table) = GeoInterface.extent(getshp(t))
GeoInterface.crs(t::Table) = GeoInterface.crs(getshp(t))
GeoInterface.extent(::GeoInterface.FeatureCollectionTrait, t::Table) = GeoInterface.extent(getshp(t))
GeoInterface.crs(::GeoInterface.FeatureCollectionTrait, t::Table) = GeoInterface.crs(getshp(t))

GeoInterface.trait(::Table) = GeoInterface.FeatureCollectionTrait()
GeoInterface.getfeature(t::Table) = t
Copy link
Contributor

Choose a reason for hiding this comment

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

I added a line for this to the tests. Of course it's a trivial implementation but don't we still need it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would rather leave that to the default iterator, because you call GI.getfeature on this and it returns exactly the same thing, which is pretty confusing IMO


function GeoInterface.getfeature(::GeoInterface.FeatureCollectionTrait, t::Table, i::Integer)
geom = shapes(t)[i]
record = DBFTables.Row(getdbf(t), i)
return Row(geom, record)
end
GeoInterface.nfeature(::GeoInterface.FeatureCollectionTrait, t::Table) = length(shapes(t))


Loading