Skip to content
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

Implement crs and geometrycolumn fallbacks via DataAPI #161

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ authors = ["JuliaGeo and contributors"]
version = "1.3.6"

[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"
Expand Down
1 change: 1 addition & 0 deletions src/GeoInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 11 additions & 2 deletions src/fallbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,17 @@
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)

Check warning on line 104 in src/fallbacks.jl

View check run for this annotation

Codecov / codecov/patch

src/fallbacks.jl#L103-L104

Added lines #L103 - L104 were not covered by tests
end
end
return default
end
Comment on lines +101 to +108
Copy link
Member Author

Choose a reason for hiding this comment

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

Should I move this to some other location / file?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe to (a new) metadata.jl? I discussed having a Geometadata.jl package with @rafaqz, but that's probably overkill for now.


# FeatureCollection
getfeature(t::AbstractFeatureCollectionTrait, fc) = (getfeature(t, fc, i) for i in 1:nfeature(t, fc))
Expand Down
2 changes: 1 addition & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading