Skip to content

Commit 3305aef

Browse files
committed
Completed subtrait method.
1 parent 66b68e4 commit 3305aef

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

src/defaults.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ end
102102
"""
103103
subtrait(t::AbstractGeometryTrait)
104104
105-
Gets the expected (sub)trait for subgeometries (retrieved with [`getgeom`](@ref)) of trait `t`.
105+
Gets the expected, possible abstract, (sub)trait for subgeometries (retrieved with [`getgeom`](@ref)) of trait `t`.
106106
This follows the [Type hierarchy](@ref) of Simple Features.
107107
108108
# Examples
109109
```jldoctest; setup = :(using GeoInterface)
110110
julia> GeoInterface.subtrait(GeoInterface.LineStringTrait())
111111
GeoInterface.PointTrait
112-
julia> GeoInterface.subtrait(GeoInterface.MultiPointTrait())
113-
GeoInterface.PointTrait
112+
julia> GeoInterface.subtrait(GeoInterface.PolygonTrait()) # Any of LineStringTrait, LineTrait, LinearRingTrait
113+
GeoInterface.AbstractLineStringTrait
114114
```
115115
```jldoctest; setup = :(using GeoInterface)
116116
# `nothing` is returned when there's no subtrait or when it's not known beforehand
@@ -120,10 +120,15 @@ julia> isnothing(GeoInterface.subtrait(GeoInterface.GeometryCollectionTrait()))
120120
true
121121
```
122122
"""
123-
subtrait(::PointTrait) = nothing
124-
subtrait(::LineStringTrait) = PointTrait
125-
subtrait(::PolygonTrait) = LineStringTrait
126-
subtrait(::MultiPointTrait) = PointTrait
127-
subtrait(::MultiLineStringTrait) = LineStringTrait
128-
subtrait(::MultiPolygonTrait) = PolygonTrait
129-
subtrait(::GeometryCollectionTrait) = nothing
123+
subtrait(::AbstractPointTrait) = nothing
124+
subtrait(::AbstractCurveTrait) = AbstractPointTrait
125+
subtrait(::AbstractCurvePolygonTrait) = AbstractCurveTrait
126+
subtrait(::AbstractPolygonTrait) = AbstractLineStringTrait
127+
subtrait(::AbstractPolyHedralSurfaceTrait) = AbstractPolygonTrait
128+
subtrait(::TINTrait) = TriangleTrait
129+
subtrait(::AbstractMultiPointTrait) = AbstractPointTrait
130+
subtrait(::AbstractMultiLineStringTrait) = AbstractLineStringTrait
131+
subtrait(::AbstractMultiPolygonTrait) = AbstractPolygonTrait
132+
subtrait(::AbstractMultiSurfaceTrait) = AbstractSurfaceTrait
133+
subtrait(::AbstractGeometryCollectionTrait) = nothing
134+
subtrait(::AbstractGeometryTrait) = nothing # fallback

src/types.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct MultiLineStringTrait <: AbstractMultiLineStringTrait end
7373

7474
"""An AbstractMultiSurfaceTrait type for all multisurfaces."""
7575
abstract type AbstractMultiSurfaceTrait <: AbstractGeometryCollectionTrait end
76+
"""A MultiSurfaceTrait is a collection of [`AbstractSurfaceTrait`](@ref)s."""
77+
struct MultiSurfaceTrait <: AbstractMultiSurfaceTrait end
7678
"""An AbstractMultiPolygonTrait type for all multipolygons."""
7779
abstract type AbstractMultiPolygonTrait <: AbstractMultiSurfaceTrait end
7880
"""A MultiPolygonTrait is a collection of [`PolygonTrait`](@ref)s."""

src/utils.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ function testgeometry(geom)
1313
n = ngeom(geom)
1414
if n >= 1 # geometry could be empty
1515
g2 = getgeom(geom, 1)
16-
geomtype(g2) == subtrait(type)
16+
subtype = subtrait(type)
17+
if !isnothing(subtype)
18+
@assert geomtype(g2) isa subtype
19+
end
1720
@assert testgeometry(g2) # recursive testing of subgeometries
1821
end
1922
end

test/test_primitives.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
struct MyCurve end
2-
struct MyPoint end
1+
32

43
@testset "Developer" begin
54
# Implement interface
6-
5+
struct MyCurve end
6+
struct MyPoint end
77
GeoInterface.isgeometry(::MyPoint) = true
88
GeoInterface.isgeometry(::MyCurve) = true
99
GeoInterface.geomtype(::MyPoint) = GeoInterface.PointTrait()
@@ -26,5 +26,8 @@ struct MyPoint end
2626
point = GeoInterface.getgeom(geom, 1)
2727
@test GeoInterface.y(point) == 2
2828

29+
end
2930

31+
@testset "Defaults" begin
32+
@test GeoInterface.subtrait(GeoInterface.TINTrait()) == GeoInterface.TriangleTrait
3033
end

0 commit comments

Comments
 (0)