-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement crs and geometrycolumn fallbacks via DataAPI (#161)
* Implement crs and geometrycolumn fallbacks via DataAPI * fix function name * use type not object to query DataAPI * Move core functionality to a new `metadata.jl` * add aftercare for geometry columns * add docs about geometrycolumns and crs for feature collections * minor bugfixes + add tests * avoid extra entry * add constants that define what the keys are, for portability
- Loading branch information
1 parent
1db072e
commit 334c0ec
Showing
7 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file contains internal helper functions to get metadata from DataAPI objects. | ||
# At some point, it may also contain methods to set metadata. | ||
|
||
""" | ||
Internal function. | ||
## Extended help | ||
_get_dataapi_metadata(geom, key, default) | ||
Get metadata associated with key `key` from some object, `geom`, that has DataAPI.jl metadata support. | ||
If the object does not have metadata support, or the key does not exist, return `default`. | ||
""" | ||
function _get_dataapi_metadata(geom::GeomType, key, default) where GeomType | ||
if DataAPI.metadatasupport(GeomType).read # check that the type has metadata, and supports reading it | ||
if key in DataAPI.metadatakeys(geom) # check that the key exists | ||
return DataAPI.metadata(geom, key; style = false) # read the metadata | ||
end | ||
end | ||
return default | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Test | ||
using GeoInterface | ||
using GeoFormatTypes: EPSG | ||
using GeoInterface.DataAPI | ||
|
||
struct TestMetadata | ||
geometrycolumns | ||
crs | ||
end | ||
|
||
DataAPI.metadatasupport(::Type{TestMetadata}) = (; read = true, write = false) | ||
DataAPI.metadatakeys(::TestMetadata) = ("GEOINTERFACE:geometrycolumns", "GEOINTERFACE:crs") | ||
function DataAPI.metadata(x::TestMetadata, key::String; style::Bool=false) | ||
if key === "GEOINTERFACE:geometrycolumns" | ||
style ? (x.geometrycolumns, :note) : x.geometrycolumns | ||
elseif key === "GEOINTERFACE:crs" | ||
style ? (x.crs, :note) : x.crs | ||
else | ||
nothing | ||
end | ||
end | ||
DataAPI.metadata(x::TestMetadata, key::String, default; style::Bool=false) = something(DataAPI.metadata(x, key; style), style ? (default, :note) : default) | ||
|
||
|
||
|
||
|
||
|
||
@testset "DataAPI" begin | ||
td = TestMetadata((:g,), nothing) | ||
@test GeoInterface.geometrycolumns(td) == (:g,) | ||
@test GeoInterface.crs(td) === nothing | ||
|
||
td = TestMetadata((:g,), EPSG(4326)) | ||
@test GeoInterface.geometrycolumns(td) == (:g,) | ||
@test GeoInterface.crs(td) == EPSG(4326) | ||
|
||
td = TestMetadata("geometry1", EPSG(4326)) | ||
@test GeoInterface.geometrycolumns(td) == (:geometry1,) | ||
@test GeoInterface.crs(td) == EPSG(4326) | ||
end |