diff --git a/Project.toml b/Project.toml index 25efe04..ff889f3 100644 --- a/Project.toml +++ b/Project.toml @@ -4,10 +4,12 @@ authors = ["JuliaGeo and contributors"] version = "1.3.7" [deps] +DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910" GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f" [compat] +DataAPI = "1" Extents = "0.1.1" GeoFormatTypes = "0.4" julia = "1" diff --git a/src/GeoInterface.jl b/src/GeoInterface.jl index b2c16c2..2bb7a8c 100644 --- a/src/GeoInterface.jl +++ b/src/GeoInterface.jl @@ -3,6 +3,7 @@ module GeoInterface using Extents: Extents, Extent using GeoFormatTypes: CoordinateReferenceSystemFormat using Base.Iterators: flatten +import DataAPI export testgeometry, isgeometry, trait, geomtrait, ncoord, getcoord, ngeom, getgeom diff --git a/src/fallbacks.jl b/src/fallbacks.jl index 9c501ad..ef21381 100644 --- a/src/fallbacks.jl +++ b/src/fallbacks.jl @@ -95,8 +95,17 @@ issimple(t::AbstractMultiPointTrait, geom) = allunique((getgeom(t, geom))) issimple(t::AbstractMultiCurveTrait, geom) = all(issimple.(getgeom(t, geom))) isclosed(t::AbstractMultiCurveTrait, geom) = all(isclosed.(getgeom(t, geom))) -crs(::Nothing, geom) = nothing -crs(::AbstractTrait, geom) = nothing +crs(::Nothing, geom) = _get_dataapi_metadata(geom, "GEOINTERFACE:crs", nothing) +crs(::AbstractTrait, geom) = _get_dataapi_metadata(geom, "GEOINTERFACE:crs", nothing) + +function _get_dataapi_metadata(geom::GeomType, key, default) where GeomType + if DataAPI.metadatasupport(GeomType).read + if key in DataAPI.metadatakeys(geom) + return DataAPI.metadata(geom, key; style = false) + end + end + return default +end # FeatureCollection getfeature(t::AbstractFeatureCollectionTrait, fc) = (getfeature(t, fc, i) for i in 1:nfeature(t, fc)) diff --git a/src/interface.jl b/src/interface.jl index 3acb556..f381f31 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -44,7 +44,7 @@ isfeaturecollection(::Type{T}) where {T} = false Retrieve the geometrycolumn(s) of `featurecollection`; the fields (or columns in a table) which contain geometries that support GeoInterface. """ -geometrycolumns(featurecollection) = (:geometry,) +geometrycolumns(featurecollection) = _get_dataapi_metadata(featurecollection, "GEOINTERFACE:geometrycolumns", (:geometry,)) """ GeoInterface.geometry(feat) => geom