Skip to content

Commit a5a76fc

Browse files
evetionrafaqz
authored andcommitted
Add geometrycolumns as an interface method.
1 parent 1069a5f commit a5a76fc

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

docs/src/guides/developer.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,27 @@ Base.convert(::Type{T}, ::LineStringTrait, geom::T) = geom # fast fallthrough w
5050
Base.convert(::Type{T}, ::LineStringTrait, geom) = ... # slow custom conversion based on ngeom and getgeom
5151
```
5252

53-
## Required for Feature
53+
## Required for Feature(Collection)s
54+
A Feature is a geometry with properties, and in modern parlance, a row in table.
55+
A FeatureCollection is thus a Vector of Features, often represented as a table.
56+
57+
A Feature implements the following:
5458
```julia
5559
GeoInterface.isfeature(feat::customfeat)::Bool = true
5660
GeoInterface.properties(feat::customfeat)
5761
GeoInterface.geometry(feat::customfeat)
5862
```
5963

64+
While a FeatureCollection implements the following:
65+
```julia
66+
GeoInterface.isfeaturecollection(::Type{customcollection}) = true
67+
GeoInterface.getfeature(trait(::customcollection), ::customcollection, i)
68+
GeoInterface.nfeature(trait(::customcollection), ::customcollection)
69+
GeoInterface.geometrycolumns(::customcollection) = (:geometry,) # can be multiple!
70+
```
71+
72+
The `geometrycolumns` enables other packages to know which field in a row, or column in a table, contains the geometry or geometries.
73+
6074
## GeoSpatial Operations
6175
```julia
6276
distance(geomtrait(a), geomtrait(b), a, b)

src/GeoInterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export AbstractGeometryTrait,
4343
MultiPolygonTrait,
4444
AbstractFeatureTrait,
4545
FeatureTrait,
46-
AbstractCollectionFeatureTrait,
46+
AbstractFeatureCollectionTrait,
4747
FeatureCollectionTrait
4848

4949

src/interface.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ automatically delegate to this method.
3838
isfeaturecollection(x::T) where {T} = isfeaturecollection(T)
3939
isfeaturecollection(::Type{T}) where {T} = false
4040

41+
"""
42+
GeoInterface.geometrycolumns(featurecollection) => (:geom,)
43+
44+
Retrieve the geometrycolumn(s) of `featurecollection`; the fields (or columns in a table)
45+
which contain geometries that support GeoInterface.
46+
"""
47+
geometrycolumns(featurecollection) = (:geometry,)
48+
4149
"""
4250
GeoInterface.geometry(feat) => geom
4351
@@ -60,15 +68,15 @@ properties(feat) = nothing
6068
Retrieve the features of `collection` as some iterable of features.
6169
It is expected that `isfeature(feature) === true`.
6270
"""
63-
getfeature(collection) = getfeature(trait(collection), collection)
71+
getfeature(collection) = getfeature(trait(collection), collection)
6472
getfeature(collection, i::Integer) = getfeature(trait(collection), collection, i)
6573

6674
"""
6775
GeoInterface.nfeature(collection)
6876
6977
Retrieve the number of features in a feature collection.
7078
"""
71-
nfeature(collection) = nfeature(trait(collection), collection)
79+
nfeature(collection) = nfeature(trait(collection), collection)
7280

7381
"""
7482
GeoInterface.geomtrait(geom) => T <: AbstractGeometry
@@ -80,7 +88,7 @@ geomtrait(geom) = nothing
8088
"""
8189
GeoInterface.trait(geom) => T <: AbstractGeometry
8290
83-
Returns the object type, such as [`FeatureTrait`](@ref).
91+
Returns the object type, such as [`FeatureTrait`](@ref).
8492
For all `isgeometry` objects `trait` is the same as `geomtrait(obj)`,
8593
e.g. [`PointTrait`](@ref).
8694
"""

src/utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function testfeature(feature)
4646
props = properties(feature)
4747
if !isnothing(props)
4848
@assert first(propertynames(props)) isa Symbol "`propertynames` of $props does not return an iterable of `Symbol`"
49-
map(n -> getproperty(props, n), propertynames(props))
49+
map(n -> getproperty(props, n), propertynames(props))
5050
end
5151
ext = extent(feature)
5252
@assert ext isa Union{Nothing,Extent}
@@ -70,5 +70,6 @@ function testfeaturecollection(fc)
7070
@warn "`nfeatures == 0` for feature collection, cannot test some properties"
7171
end
7272
@assert coordinates(fc) == coordinates.(getfeature(fc))
73+
@assert geometrycolumns(fc) isa NTuple "feature collection $fc doesn't return a `NTuple` from `geometrycolumns`."
7374
return true
7475
end

0 commit comments

Comments
 (0)