Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 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 @@ -187,7 +187,17 @@ 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
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lets not delete it its mildly breaking

GeoInterface.getfeature(t::Table) = t

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


10 changes: 10 additions & 0 deletions test/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tables
import DataFrames
import GeoInterface
import GeoFormatTypes
import Extents

datadir = joinpath(@__DIR__, "data")
url = "https://github.com/nvkelso/natural-earth-vector/raw/v4.1.0"
Expand Down Expand Up @@ -211,6 +212,15 @@ end
@test DataAPI.metadata(df_cities, "GEOINTERFACE:crs"; style = false) == GeoInterface.crs(ne_cities)
end

@testset "GeoInterface" begin
@test GeoInterface.nfeature(ne_land) == length(ne_land)
feature = GeoInterface.getfeature(ne_land, 1)
@test feature.geometry == ne_land.geometry[1]
@test GeoInterface.properties(feature) == NamedTuple(first(Shapefile.getdbf(ne_land)))
@test GeoInterface.crs(ne_land) == GeoFormatTypes.ESRIWellKnownText(GeoFormatTypes.CRS(), wkt)
@test GeoInterface.extent(ne_land) isa Extents.Extent
end

# no need to use shx in Shapefile.Tables since we read the shapes into a Vector and can thus index them
# but since we have these files, we may as well try reading them
ne_shx = [path(rfs) for rfs in files(natural_earth) if endswith(path(rfs), ".shx")]
Expand Down
Loading