Skip to content

Commit 73f64df

Browse files
authored
Add more docs to the primitive code explaining why this is awesome (#85)
* Add more docs to the primitive code explaining why this is awesome * Add a tip to the reproject docstring
1 parent 81864cb commit 73f64df

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/primitives.jl

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,57 @@
22

33
export apply, applyreduce, TraitTarget
44

5-
# This file mainly defines the [`apply`](@ref) function and its relatives.
5+
#=
6+
7+
This file mainly defines the [`apply`](@ref) and [`applyreduce`](@ref) functions, and some related functionality.
8+
9+
In general, the idea behind the `apply` framework is to take
10+
as input any geometry, vector of geometries, or feature collection,
11+
deconstruct it to the given trait target (any arbitrary GI.AbstractTrait
12+
or `TraitTarget` union thereof, like `PointTrait` or `PolygonTrait`)
13+
and perform some operation on it.
14+
15+
This allows for a simple and consistent framework within which users can
16+
define their own operations trivially easily, and removes a lot of the
17+
complexity involved with handling complex geometry structures.
18+
19+
For example, a simple way to flip the x and y coordinates of a geometry is:
20+
21+
```julia
22+
flipped_geom = GO.apply(GI.PointTrait, geom) do p
23+
(GI.y(p), GI.x(p))
24+
end
25+
```
26+
27+
As simple as that. There's no need to implement your own decomposition because it's done for you.
28+
29+
Functions like [`flip`](@ref), [`reproject`](@ref), [`transform`](@ref), even [`segmentize`](@ref) and [`simplify`](@ref) have been implemented
30+
using the `apply` framework. Similarly, [`centroid`](@ref), [`area`](@ref) and [`distance`](@ref) have been implemented using the
31+
[`applyreduce`](@ref) framework.
32+
33+
## Docstrings
34+
35+
### Functions
36+
37+
```@docs
38+
apply
39+
applyreduce
40+
GeometryOps.unwrap
41+
GeometryOps.flatten
42+
GeometryOps.reconstruct
43+
GeometryOps.rebuild
44+
```
45+
46+
## Types
47+
48+
```@docs
49+
TraitTarget
50+
```
51+
52+
## Implementation
53+
54+
=#
55+
656

757
#=
858
We pass `threading` and `calc_extent` as types, not simple boolean values.
@@ -125,7 +175,7 @@ The result is a functionally similar geometry with values depending on `f`
125175
126176
$APPLY_KEYWORDS
127177
128-
# Example
178+
## Example
129179
130180
Flipped point the order in any feature or geometry, or iterables of either:
131181
@@ -138,6 +188,7 @@ geom = GI.Polygon([GI.LinearRing([(1, 2), (3, 4), (5, 6), (1, 2)]),
138188
flipped_geom = GO.apply(GI.PointTrait, geom) do p
139189
(GI.y(p), GI.x(p))
140190
end
191+
```
141192
"""
142193
@inline function apply(
143194
f::F, target, geom; calc_extent=false, threaded=false, kw...

src/transformations/reproject.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Reproject any GeoInterface.jl compatible `geometry` from `source_crs` to `target
2020
The returned object will be constructed from `GeoInterface.WrapperGeometry`
2121
geometries, wrapping views of a `Vector{Proj.Point{D}}`, where `D` is the dimension.
2222
23+
!!! tip
24+
The `Proj.jl` package must be loaded for this method to work,
25+
since it is implemented in a package extension.
26+
2327
## Arguments
2428
2529
- `geometry`: Any GeoInterface.jl compatible geometries.

0 commit comments

Comments
 (0)