Skip to content

Commit cfadd5e

Browse files
authored
Merge pull request #50 from JuliaGeo/export-traits
export the traits
2 parents d1d9589 + f98a139 commit cfadd5e

File tree

6 files changed

+97
-60
lines changed

6 files changed

+97
-60
lines changed

docs/src/guides/developer.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Last but not least, we also provide an interface for features--geometries with p
1515

1616
```julia
1717
GeoInterface.isgeometry(geom::customgeom)::Bool = true
18-
GeoInterface.geomtype(geom::customgeom)::DataType = GeoInterface.XTrait() # <: AbstractGeometryTrait
18+
GeoInterface.geomtype(geom::customgeom)::DataType = XTrait() # <: AbstractGeometryTrait
1919
# for PointTraits
2020
GeoInterface.ncoord(geomtype(geom), geom::customgeom)::Integer
2121
GeoInterface.getcoord(geomtype(geom), geom::customgeom, i)::Real
@@ -93,79 +93,79 @@ GeoInterface.isgeometry(geom::customgeom)::Bool = true
9393

9494
A `geom::customgeom` with "Point"-like traits implements
9595
```julia
96-
GeoInterface.geomtype(geom::customgeom)::DataType = GeoInterface.PointTrait()
97-
GeoInterface.ncoord(::GeoInterface.PointTrait, geom::customgeom)::Integer
98-
GeoInterface.getcoord(::GeoInterface.PointTrait, geom::customgeom, i)::Real
96+
GeoInterface.geomtype(geom::customgeom)::DataType = PointTrait()
97+
GeoInterface.ncoord(::PointTrait, geom::customgeom)::Integer
98+
GeoInterface.getcoord(::PointTrait, geom::customgeom, i)::Real
9999

100100
# Defaults
101-
GeoInterface.ngeom(::GeoInterface.PointTrait, geom)::Integer = 0
102-
GeoInterface.getgeom(::GeoInterface.PointTrait, geom::customgeom, i) = nothing
101+
GeoInterface.ngeom(::PointTrait, geom)::Integer = 0
102+
GeoInterface.getgeom(::PointTrait, geom::customgeom, i) = nothing
103103
```
104104

105105
A `geom::customgeom` with "LineString"-like traits implements the following methods:
106106
```julia
107-
GeoInterface.geomtype(geom::customgeom)::DataType = GeoInterface.LineStringTrait()
108-
GeoInterface.ncoord(::GeoInterface.LineStringTrait, geom::customgeom)::Integer
107+
GeoInterface.geomtype(geom::customgeom)::DataType = LineStringTrait()
108+
GeoInterface.ncoord(::LineStringTrait, geom::customgeom)::Integer
109109

110110
# These alias for npoint and getpoint
111-
GeoInterface.ngeom(::GeoInterface.LineStringTrait, geom::customgeom)::Integer
112-
GeoInterface.getgeom(::GeoInterface.LineStringTrait, geom::customgeom, i) # of geomtype Point
111+
GeoInterface.ngeom(::LineStringTrait, geom::customgeom)::Integer
112+
GeoInterface.getgeom(::LineStringTrait, geom::customgeom, i) # of geomtype Point
113113

114114
# Optional
115-
GeoInterface.isclosed(::GeoInterface.LineStringTrait, geom::customgeom)::Bool
116-
GeoInterface.issimple(::GeoInterface.LineStringTrait, geom::customgeom)::Bool
117-
GeoInterface.length(::GeoInterface.LineStringTrait, geom::customgeom)::Real
115+
GeoInterface.isclosed(::LineStringTrait, geom::customgeom)::Bool
116+
GeoInterface.issimple(::LineStringTrait, geom::customgeom)::Bool
117+
GeoInterface.length(::LineStringTrait, geom::customgeom)::Real
118118
```
119119
A `geom::customgeom` with "Polygon"-like traits can implement the following methods:
120120
```julia
121-
GeoInterface.geomtype(geom::customgeom)::DataType = GeoInterface.PolygonTrait()
122-
GeoInterface.ncoord(::GeoInterface.PolygonTrait, geom::customgeom)::Integer
121+
GeoInterface.geomtype(geom::customgeom)::DataType = PolygonTrait()
122+
GeoInterface.ncoord(::PolygonTrait, geom::customgeom)::Integer
123123

124124
# These alias for nring and getring
125-
GeoInterface.ngeom(::GeoInterface.PolygonTrait, geom::customgeom)::Integer
126-
GeoInterface.getgeom(::GeoInterface.PolygonTrait, geom::customgeom, i)::"LineStringTrait"
125+
GeoInterface.ngeom(::PolygonTrait, geom::customgeom)::Integer
126+
GeoInterface.getgeom(::PolygonTrait, geom::customgeom, i)::"LineStringTrait"
127127

128128
# Optional
129-
GeoInterface.area(::GeoInterface.PolygonTrait, geom::customgeom)::Real
130-
GeoInterface.centroid(::GeoInterface.PolygonTrait, geom::customgeom)::"PointTrait"
131-
GeoInterface.pointonsurface(::GeoInterface.PolygonTrait, geom::customgeom)::"PointTrait"
132-
GeoInterface.boundary(::GeoInterface.PolygonTrait, geom::customgeom)::"LineStringTrait"
129+
GeoInterface.area(::PolygonTrait, geom::customgeom)::Real
130+
GeoInterface.centroid(::PolygonTrait, geom::customgeom)::"PointTrait"
131+
GeoInterface.pointonsurface(::PolygonTrait, geom::customgeom)::"PointTrait"
132+
GeoInterface.boundary(::PolygonTrait, geom::customgeom)::"LineStringTrait"
133133
```
134134

135135
A `geom::customgeom` with "GeometryCollection"-like traits has to implement the following methods:
136136
```julia
137-
GeoInterface.geomtype(geom::customgeom) = GeoInterface.GeometryCollectionTrait()
138-
GeoInterface.ncoord(::GeoInterface.GeometryCollectionTrait, geom::customgeom)::Integer
139-
GeoInterface.ngeom(::GeoInterface.GeometryCollectionTrait, geom::customgeom)::Integer
140-
GeoInterface.getgeom(::GeoInterface.GeometryCollectionTrait,geom::customgeomm, i)::"GeometryTrait"
137+
GeoInterface.geomtype(geom::customgeom) = GeometryCollectionTrait()
138+
GeoInterface.ncoord(::GeometryCollectionTrait, geom::customgeom)::Integer
139+
GeoInterface.ngeom(::GeometryCollectionTrait, geom::customgeom)::Integer
140+
GeoInterface.getgeom(::GeometryCollectionTrait,geom::customgeomm, i)::"GeometryTrait"
141141
```
142142

143143
A `geom::customgeom` with "MultiPoint"-like traits has to implement the following methods:
144144
```julia
145-
GeoInterface.geomtype(geom::customgeom) = GeoInterface.MultiPointTrait()
146-
GeoInterface.ncoord(::GeoInterface.MultiPointTrait, geom::customgeom)::Integer
145+
GeoInterface.geomtype(geom::customgeom) = MultiPointTrait()
146+
GeoInterface.ncoord(::MultiPointTrait, geom::customgeom)::Integer
147147

148148
# These alias for npoint and getpoint
149-
GeoInterface.ngeom(::GeoInterface.MultiPointTrait, geom::customgeom)::Integer
150-
GeoInterface.getgeom(::GeoInterface.MultiPointTrait, geom::customgeom, i)::"PointTrait"
149+
GeoInterface.ngeom(::MultiPointTrait, geom::customgeom)::Integer
150+
GeoInterface.getgeom(::MultiPointTrait, geom::customgeom, i)::"PointTrait"
151151
```
152152

153153
A `geom::customgeom` with "MultiLineString"-like traits has to implement the following methods:
154154
```julia
155-
GeoInterface.geomtype(geom::customgeom) = GeoInterface.MultiLineStringTrait()
156-
GeoInterface.ncoord(::GeoInterface.MultiLineStringTrait, geom::customgeom)::Integer
155+
GeoInterface.geomtype(geom::customgeom) = MultiLineStringTrait()
156+
GeoInterface.ncoord(::MultiLineStringTrait, geom::customgeom)::Integer
157157

158158
# These alias for nlinestring and getlinestring
159-
GeoInterface.ngeom(::GeoInterface.MultiLineStringTrait, geom::customgeom)::Integer
160-
GeoInterface.getgeom(::GeoInterface.MultiLineStringTrait,geom::customgeomm, i)::"LineStringTrait"
159+
GeoInterface.ngeom(::MultiLineStringTrait, geom::customgeom)::Integer
160+
GeoInterface.getgeom(::MultiLineStringTrait,geom::customgeomm, i)::"LineStringTrait"
161161
```
162162

163163
A `geom::customgeom` with "MultiPolygon"-like traits has to implement the following methods:
164164
```julia
165-
GeoInterface.geomtype(geom::customgeom) = GeoInterface.MultiPolygonTrait()
166-
GeoInterface.ncoord(::GeoInterface.MultiPolygonTrait, geom::customgeom)::Integer
165+
GeoInterface.geomtype(geom::customgeom) = MultiPolygonTrait()
166+
GeoInterface.ncoord(::MultiPolygonTrait, geom::customgeom)::Integer
167167

168168
# These alias for npolygon and getpolygon
169-
GeoInterface.ngeom(::GeoInterface.MultiPolygonTrait, geom::customgeom)::Integer
170-
GeoInterface.getgeom(::GeoInterface.MultiPolygonTrait, geom::customgeom, i)::"PolygonTrait"
169+
GeoInterface.ngeom(::MultiPolygonTrait, geom::customgeom)::Integer
170+
GeoInterface.getgeom(::MultiPolygonTrait, geom::customgeom, i)::"PolygonTrait"
171171
```

docs/src/tutorials/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ julia> geom = createpolygon(...)::ArchGDAL.IGeometry # no idea about the interf
4141
julia> isgeometry(geom)
4242
True
4343
julia> geomtype(geom)
44-
GeoInterface.PolygonTrait()
44+
PolygonTrait()
4545
julia> ext = exterior(geom);
4646
julia> geomtype(ext)
47-
GeoInterface.LineStringTrait()
47+
LineStringTrait()
4848
julia> getcoords.(getpoint.(Ref(ext), 1:npoint(ext)))
4949
[[1.,2.],[2.,3.],[1.,2.]]
5050
julia> coordinates(geom) # fallback based on ngeom & npoint above

src/GeoInterface.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,43 @@ using Base.Iterators: flatten
44

55
export testgeometry, isgeometry, geomtype, ncoord, getcoord, ngeom, getgeom
66

7+
# traits
8+
export AbstractGeometryTrait,
9+
AbstractGeometryCollectionTrait,
10+
GeometryCollectionTrait,
11+
AbstractPointTrait,
12+
PointTrait,
13+
AbstractCurveTrait,
14+
AbstractLineStringTrait,
15+
LineStringTrait,
16+
LineTrait,
17+
LinearRingTrait,
18+
CircularStringTrait,
19+
CompoundCurveTrait,
20+
AbstractSurfaceTrait,
21+
AbstractCurvePolygonTrait,
22+
CurvePolygonTrait,
23+
AbstractPolygonTrait,
24+
PolygonTrait,
25+
TriangleTrait,
26+
RectangleTrait,
27+
QuadTrait,
28+
PentagonTrait,
29+
HexagonTrait,
30+
AbstractPolyHedralSurfaceTrait,
31+
PolyHedralSurfaceTrait,
32+
TINTrait,
33+
AbstractMultiPointTrait,
34+
MultiPointTrait,
35+
AbstractMultiCurveTrait,
36+
MultiCurveTrait,
37+
AbstractMultiLineStringTrait,
38+
MultiLineStringTrait,
39+
AbstractMultiSurfaceTrait,
40+
MultiSurfaceTrait,
41+
AbstractMultiPolygonTrait,
42+
MultiPolygonTrait
43+
744
include("types.jl")
845
include("interface.jl")
946
include("fallbacks.jl")

src/fallbacks.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ Gets the expected, possible abstract, (sub)trait for subgeometries (retrieved wi
112112
113113
# Examples
114114
```jldoctest; setup = :(using GeoInterface)
115-
julia> GeoInterface.subtrait(GeoInterface.LineStringTrait())
116-
GeoInterface.AbstractPointTrait
117-
julia> GeoInterface.subtrait(GeoInterface.PolygonTrait()) # Any of LineStringTrait, LineTrait, LinearRingTrait
118-
GeoInterface.AbstractLineStringTrait
115+
julia> GeoInterface.subtrait(LineStringTrait())
116+
AbstractPointTrait
117+
julia> GeoInterface.subtrait(PolygonTrait()) # Any of LineStringTrait, LineTrait, LinearRingTrait
118+
AbstractLineStringTrait
119119
```
120120
```jldoctest; setup = :(using GeoInterface)
121121
# `nothing` is returned when there's no subtrait or when it's not known beforehand
122-
julia> isnothing(GeoInterface.subtrait(GeoInterface.PointTrait()))
122+
julia> isnothing(GeoInterface.subtrait(PointTrait()))
123123
true
124-
julia> isnothing(GeoInterface.subtrait(GeoInterface.GeometryCollectionTrait()))
124+
julia> isnothing(GeoInterface.subtrait(GeometryCollectionTrait()))
125125
true
126126
```
127127
"""

src/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ properties(feat) = nothing
4343
"""
4444
GeoInterface.geomtype(geom) => T <: AbstractGeometry
4545
46-
Returns the geometry type, such as [`GeoInterface.PolygonTrait`](@ref) or [`GeoInterface.PointTrait`](@ref).
46+
Returns the geometry type, such as [`PolygonTrait`](@ref) or [`PointTrait`](@ref).
4747
"""
4848
geomtype(geom) = nothing
4949

test/test_primitives.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ using Test
1212
struct MyCollection end
1313

1414
GeoInterface.isgeometry(::MyPoint) = true
15-
GeoInterface.geomtype(::MyPoint) = GeoInterface.PointTrait()
16-
GeoInterface.ncoord(::GeoInterface.PointTrait, geom::MyPoint) = 2
17-
GeoInterface.getcoord(::GeoInterface.PointTrait, geom::MyPoint, i) = [1, 2][i]
15+
GeoInterface.geomtype(::MyPoint) = PointTrait()
16+
GeoInterface.ncoord(::PointTrait, geom::MyPoint) = 2
17+
GeoInterface.getcoord(::PointTrait, geom::MyPoint, i) = [1, 2][i]
1818

1919
GeoInterface.isgeometry(::MyCurve) = true
20-
GeoInterface.geomtype(::MyCurve) = GeoInterface.LineStringTrait()
21-
GeoInterface.ngeom(::GeoInterface.LineStringTrait, geom::MyCurve) = 2
22-
GeoInterface.getgeom(::GeoInterface.LineStringTrait, geom::MyCurve, i) = MyPoint()
23-
Base.convert(::Type{MyCurve}, ::GeoInterface.LineStringTrait, geom) = geom
20+
GeoInterface.geomtype(::MyCurve) = LineStringTrait()
21+
GeoInterface.ngeom(::LineStringTrait, geom::MyCurve) = 2
22+
GeoInterface.getgeom(::LineStringTrait, geom::MyCurve, i) = MyPoint()
23+
Base.convert(::Type{MyCurve}, ::LineStringTrait, geom) = geom
2424

2525
GeoInterface.isgeometry(::MyPolygon) = true
26-
GeoInterface.geomtype(::MyPolygon) = GeoInterface.PolygonTrait()
27-
GeoInterface.ngeom(::GeoInterface.PolygonTrait, geom::MyPolygon) = 2
28-
GeoInterface.getgeom(::GeoInterface.PolygonTrait, geom::MyPolygon, i) = MyCurve()
26+
GeoInterface.geomtype(::MyPolygon) = PolygonTrait()
27+
GeoInterface.ngeom(::PolygonTrait, geom::MyPolygon) = 2
28+
GeoInterface.getgeom(::PolygonTrait, geom::MyPolygon, i) = MyCurve()
2929

3030

3131
@testset "Point" begin
@@ -65,17 +65,17 @@ using Test
6565
end
6666

6767
@testset "Defaults" begin
68-
@test GeoInterface.subtrait(GeoInterface.TINTrait()) == GeoInterface.TriangleTrait
68+
@test GeoInterface.subtrait(TINTrait()) == TriangleTrait
6969
end
7070

7171
@testset "Feature" begin
7272
struct Row end
7373
struct Point end
7474

7575
GeoInterface.isgeometry(::Point) = true
76-
GeoInterface.geomtype(::Point) = GeoInterface.PointTrait()
77-
GeoInterface.ncoord(::GeoInterface.PointTrait, geom::Point) = 2
78-
GeoInterface.getcoord(::GeoInterface.PointTrait, geom::Point, i) = [1, 2][i]
76+
GeoInterface.geomtype(::Point) = PointTrait()
77+
GeoInterface.ncoord(::PointTrait, geom::Point) = 2
78+
GeoInterface.getcoord(::PointTrait, geom::Point, i) = [1, 2][i]
7979

8080
GeoInterface.isfeature(::Row) = true
8181
GeoInterface.geometry(r::Row) = Point()

0 commit comments

Comments
 (0)