Skip to content

Commit 7ee9ace

Browse files
committed
Added doctests. Expanded the documentation.
1 parent 9ab7e2c commit 7ee9ace

File tree

10 files changed

+71
-26
lines changed

10 files changed

+71
-26
lines changed

Project.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ version = "1.0.0"
55

66
[deps]
77
Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
8-
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
98

109
[compat]
11-
RecipesBase = "1"
1210
julia = "1"
1311

1412
[extras]
13+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1514
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1615

1716
[targets]
18-
test = ["Test"]
17+
test = ["Test", "Documenter"]

docs/make.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ makedocs(;
1818
"Home" => "index.md",
1919
"Background" => Any[
2020
"Simple Features"=>"background/sf.md",
21+
"History"=>"background/history.md",
2122
],
2223
"Tutorials" => Any[
2324
"Installation"=>"tutorials/installation.md",
@@ -31,7 +32,8 @@ makedocs(;
3132
"API" => "reference/api.md"
3233
"Implementations" => "reference/integrations.md"
3334
],
34-
]
35+
],
36+
doctest=true
3537
)
3638

3739
deploydocs(;

docs/src/background/history.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# History
2+
The previous pre-1.0 releases of GeoInterface.jl were smaller in scope, aligned to geointerface in Python [^sgillies]
3+
which builds on GeoJSON [^geojson]. It provided abstract types and expected other geometries to be implemented as a subtype.
4+
Recent Julia developments have shown that subtyping is difficult--you can only choose one supertype--and many packages moved to trait-based interfaces. Tables.jl is an excellent example of traits-based interface.
5+
6+
[^sgillies]: https://gist.github.com/sgillies/2217756
7+
[^geojson]: https://geojson.org/
8+
9+
## Backwards compatibility
10+
To keep function compatibility with pre-v1 releases--even while switching to traits--we keep the following methods.
11+
```julia
12+
# for Features
13+
isfeature # new
14+
geometry
15+
properties
16+
17+
# for Geometries
18+
coordinates
19+
```
20+
21+
However, the `position` type is gone and merged with `PointTrait`.

docs/src/background/sf.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All types used here come from the SF. We added `Trait` to all geometry types her
1212
![SF Type hierarchy. From the Simple Feature standard by OGC.](types.png)
1313
`The SF Type hierarchy. From OpenGIS® Implementation Standard for Geographic information - Simple feature access - Part 1: Common architecture at http://www.opengis.net/doc/is/sfa/1.2.1.`
1414

15+
1516
## Changes with respect to SF
1617
While we try to adhere to SF, there are changes and extensions to make it more Julian.
1718

@@ -54,15 +55,6 @@ Not all SF functions are implemented, either as a possibly slower fallback or em
5455
dimension # topological dimensions
5556
spatialDimension
5657

57-
5858
locateAlong
5959
locateBetween
6060
```
61-
62-
## History
63-
The previous pre-1.0 releases of GeoInterface.jl were smaller in scope, aligned to geointerface in Python [^sgillies]
64-
which builds on GeoJSON [^geojson]. It provided abstract types and expected other geometries to be implemented as a subtype.
65-
Recent Julia developments have shown that subtyping is difficult--you can only choose one supertype--and many packages moved to trait-based interfaces. Tables.jl is an excellent example.
66-
67-
[^sgillies]: https://gist.github.com/sgillies/2217756
68-
[^geojson]: https://geojson.org/

docs/src/guides/defaults.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ nhole(p::AbstractPolygonTrait, geom) = nring(p, geom) - 1
2828
gethole(p::AbstractPolygonTrait, geom, i) = getring(p, geom, i + 1)
2929
```
3030
## LineStrings
31-
Simarly for LineStrings, we have the following
31+
Similarly for `LineStringTrait`s, we have the following
3232
```julia
3333
startpoint(geom) = getpoint(geom, 1)
3434
endpoint(geom) = getpoint(geom, length(geom))

docs/src/guides/developer.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@ CurrentModule = GeoInterface
44

55
# Implementing GeoInterface
66
GeoInterface requires six functions to be defined for a custom geometry. On top of that
7-
it could be useful to also implement some optional methods if they apply or are faster than the fallbacks.
7+
it could be useful to also implement some optional methods if they apply or are faster than the [Fallbacks](@ref).
88

99
If your package also supports geospatial operations on geometries--such as intersections--, please
1010
also implement those interfaces where applicable.
1111

12+
Last but not least, we also provide an interface for features--geometries with properties--if applicable.
13+
1214
## Required for Geometry
1315

1416
```julia
1517
GeoInterface.isgeometry(geom::customgeom)::Bool = true
16-
GeoInterface.geomtype(geom::customgeom)::DataType = GeoInterface.XTraitTrait() # <: AbstractGeometryTrait
18+
GeoInterface.geomtype(geom::customgeom)::DataType = GeoInterface.XTrait() # <: AbstractGeometryTrait
19+
# for PointTraits
1720
GeoInterface.ncoord(geomtype(geom), geom::customgeom)::Integer
18-
GeoInterface.getcoord(geomtype(geom), geom::customgeom, i)::Real # only for PointTraits
21+
GeoInterface.getcoord(geomtype(geom), geom::customgeom, i)::Real
22+
# for non PointTraits
1923
GeoInterface.ngeom(geomtype(geom), geom::customgeom)::Integer
20-
GeoInterface.getgeom(geomtype(geom), geom::customgeom, i) # geomtype -> GeoInterface.Y
24+
GeoInterface.getgeom(geomtype(geom), geom::customgeom, i)
2125
```
22-
Where the `getgeom` and `getcoord` could be an iterator (without the `i`) as well. It will return a new geom with the correct `geomtype`. The `ngeom` and `getgeom` are aliases for their geom specific counterparts, such as `npoints` and `getpoint` for LineStrings.
26+
Where the `getgeom` and `getcoord` could be an iterator (without the `i`) as well. It will return a new geom with the correct `geomtype`.
27+
This means that a call to `getgeom` on a geometry that has a `LineStringTrait` should return something that implements the `PointTrait`. This hierarchy can be checked programmatically with [`subtrait`](@ref). You read more about the `geomtype` in the [Type hierarchy](@ref).
28+
29+
The `ngeom` and `getgeom` are aliases for their geom specific counterparts, such as `npoints` and `getpoint` for `LineStringTrait`s.
2330

24-
You read more about the `geomtype` in the [Type hierarchy](@ref).
2531

2632
## Optional for Geometry
2733

@@ -71,15 +77,16 @@ union(geomtype(a), geomtype(b), a, b)
7177
```
7278

7379
## Testing the interface
74-
GeoInterface provides a Testsuite for a geom type to check whether all functions that have been implemented also work as expected.
80+
GeoInterface provides a Testsuite for a geom type to check whether the required functions that have been correctly implemented and work as expected.
7581

7682
```julia
7783
GeoInterface.testgeometry(geom)
84+
GeoInterface.testfeature(geom)
7885
```
7986

8087
## Examples
8188

82-
All custom geometies implement
89+
All custom geometries implement
8390
```julia
8491
GeoInterface.isgeometry(geom::customgeom)::Bool = true
8592
```

docs/src/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ CurrentModule = GeoInterface
1111

1212
This Package describe a set of traits based on the [Simple Features standard (SF)](https://www.opengeospatial.org/standards/sfa)
1313
for geospatial vector data, including the SQL/MM extension with support for circular geometry.
14-
Using these traits, it should be easy to parse, serialize and use different geometries in the Julia ecosystem,
14+
By using these traits, it should be easy to parse, serialize and use different custom geometries in the Julia ecosystem,
1515
without knowing the specifics of each individual package. In that regard it is similar to Tables.jl, but for geometries instead of tables.
1616

1717
Packages which support the GeoInterface.jl interface can be found in [Packages](@ref).
1818

19-
For background about the interface and Simple Features, see [Changes with respect to SF](@ref).
2019
For usage see [Traits interface](@ref), while if you look to implement GeoInterface in your own package, check out [Implementing GeoInterface](@ref).
20+
For background about the interface and Simple Features, see [Changes with respect to SF](@ref).
2121

2222
!!! compat
23-
This traits interface is new and is a major departure from previous pre-1.0 releases. Feel free to ask questions on Github.
23+
This traits interface is new and is a major departure from previous pre-1.0 releases. See [History](@ref) for more information. Feel free to ask questions on Github.

docs/src/tutorials/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ julia> geomtype(ext)
4747
GeoInterface.LineStringTrait()
4848
julia> getcoords.(getpoint.(Ref(ext), 1:npoint(ext)))
4949
[[1.,2.],[2.,3.],[1.,2.]]
50-
julia> coords(geom) # fallback based on ngeom & npoint above
50+
julia> coordinates(geom) # fallback based on ngeom & npoint above
5151
5252
```

src/defaults.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,28 @@ function coordinates(::AbstractGeometryTrait, geom)
9595
end
9696

9797
# Subtraits
98+
99+
"""
100+
subtrait(t::AbstractGeometryTrait)
101+
102+
Gets the expected (sub)trait for subgeometries (retrieved with [`getgeom`](@ref)) of trait `t`.
103+
This follows the [Type hierarchy](@ref) of Simple Features.
104+
105+
# Examples
106+
```jldoctest; setup = :(using GeoInterface)
107+
julia> GeoInterface.subtrait(GeoInterface.LineStringTrait())
108+
GeoInterface.PointTrait
109+
julia> GeoInterface.subtrait(GeoInterface.MultiPointTrait())
110+
GeoInterface.PointTrait
111+
```
112+
```jldoctest; setup = :(using GeoInterface)
113+
# `nothing` is returned when there's no subtrait or when it's not known beforehand
114+
julia> isnothing(GeoInterface.subtrait(GeoInterface.PointTrait()))
115+
true
116+
julia> isnothing(GeoInterface.subtrait(GeoInterface.GeometryCollectionTrait()))
117+
true
118+
```
119+
"""
98120
subtrait(::PointTrait) = nothing
99121
subtrait(::LineStringTrait) = PointTrait
100122
subtrait(::PolygonTrait) = LineStringTrait

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using GeoInterface
2+
using Documenter
23
using Test
34

45
include("test_primitives.jl")
6+
doctest(GeoInterface)

0 commit comments

Comments
 (0)