2
2
3
3
export apply, applyreduce, TraitTarget
4
4
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
+
6
56
7
57
#=
8
58
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`
125
175
126
176
$APPLY_KEYWORDS
127
177
128
- # Example
178
+ ## Example
129
179
130
180
Flipped point the order in any feature or geometry, or iterables of either:
131
181
@@ -138,6 +188,7 @@ geom = GI.Polygon([GI.LinearRing([(1, 2), (3, 4), (5, 6), (1, 2)]),
138
188
flipped_geom = GO.apply(GI.PointTrait, geom) do p
139
189
(GI.y(p), GI.x(p))
140
190
end
191
+ ```
141
192
"""
142
193
@inline function apply (
143
194
f:: F , target, geom; calc_extent= false , threaded= false , kw...
0 commit comments