diff --git a/src/table.jl b/src/table.jl index c47d2c1..6d8e8ff 100644 --- a/src/table.jl +++ b/src/table.jl @@ -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() """ @@ -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 \ No newline at end of file +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)) + + diff --git a/test/table.jl b/test/table.jl index 0e32335..6deb3ab 100644 --- a/test/table.jl +++ b/test/table.jl @@ -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" @@ -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")]