Skip to content

Commit 39528c9

Browse files
mforetsvisr
authored andcommitted
fix doctests
1 parent b74da16 commit 39528c9

File tree

4 files changed

+140
-69
lines changed

4 files changed

+140
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.jl.mem
44
.DS_Store
55
/Manifest.toml
6+
docs/build/

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ using Documenter
44

55
using GeometryBasics
66

7+
DocMeta.setdocmeta!(GeometryBasics, :DocTestSetup, :(using GeometryBasics); recursive=true)
8+
79
# Copy the README to serve as the homepage
810
cp(joinpath(@__DIR__, "..", "README.md"), joinpath(@__DIR__, "src", "index.md"))
911

docs/src/metadata.md

Lines changed: 136 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,187 @@
11
# Metadata
2+
23
## Meta
3-
The `Meta` method provides metadata handling capabilities in GeometryBasics. Similarly to remove the metadata and keep only the geometry, use `metafree`, and for vice versa i.e., remove the geometry and keep the metadata use `meta`.
44

5+
The `Meta` method provides metadata handling capabilities in GeometryBasics.
6+
Similarly to remove the metadata and keep only the geometry, use `metafree`, and
7+
for vice versa i.e., remove the geometry and keep the metadata use `meta`.
58

69
### Syntax
7-
```
10+
11+
```julia
812
meta(geometry, meta::NamedTuple)
913
meta(geometry; meta...)
1014

1115
metafree(meta-geometry)
1216
meta(meta-geometry)
13-
```
14-
### Example
15-
```jldoctest
16-
using GeometryBasics
17-
p1 = Point(2.2, 3.6)
18-
19-
poi = meta(p1, city="Abuja", rainfall=1221.2)
20-
2-element PointMeta{2,Int64,Point{2,Int64},(:city, :rainfall),Tuple{String,Float64}} with indices SOneTo(2):
21-
3
22-
1
23-
24-
# metadata is stored in a NamedTuple and can be retrieved as such
25-
meta(poi)
17+
```
18+
19+
### Examples
20+
21+
```jldoctest meta
22+
julia> using GeometryBasics
23+
24+
julia> p1 = Point(2.2, 3.6)
25+
2-element Point{2,Float64} with indices SOneTo(2):
26+
2.2
27+
3.6
28+
29+
julia> poi = meta(p1, city="Abuja", rainfall=1221.2)
30+
2-element PointMeta{2,Float64,Point{2,Float64},(:city, :rainfall),Tuple{String,Float64}} with indices SOneTo(2):
31+
2.2
32+
3.6
33+
```
34+
35+
Metadata is stored in a NamedTuple and can be retrieved as such
36+
37+
```jldoctest meta
38+
julia> meta(poi)
2639
(city = "Abuja", rainfall = 1221.2)
40+
```
41+
42+
Specific metadata attributes can be directly retrieved
2743

28-
# specific metadata attributes can be directly retrieved
29-
poi.rainfall
44+
```jldoctest meta
45+
julia> poi.rainfall
3046
1221.2
3147
32-
metafree(poi)
33-
2-element Point{2,Int64} with indices SOneTo(2):
34-
3
35-
1
48+
julia> metafree(poi)
49+
2-element Point{2,Float64} with indices SOneTo(2):
50+
2.2
51+
3.6
52+
```
53+
54+
For other geometries metatypes are predefined
3655

37-
# for other geometries metatypes are predefined
38-
multipoi = MultiPointMeta([p1], city="Abuja", rainfall=1221.2)
39-
1-element MultiPointMeta{Point{2,Int64},MultiPoint{2,Int64,Point{2,Int64},Array{Point{2,Int64},1}},(:city, :rainfall),Tuple{String,Float64}}:
40-
[3, 1]
56+
```jldoctest meta
57+
julia> multipoi = MultiPointMeta([p1], city="Abuja", rainfall=1221.2)
58+
1-element MultiPointMeta{Point{2,Float64},MultiPoint{2,Float64,Point{2,Float64},Array{Point{2,Float64},1}},(:city, :rainfall),Tuple{String,Float64}}:
59+
[2.2, 3.6]
4160
```
4261
In the above example we have also used geometry specific meta methods.
4362

44-
### Example
45-
```@jldoctest
46-
GeometryBasics.MetaType(Polygon)
63+
64+
```jldoctest meta
65+
julia> GeometryBasics.MetaType(Polygon)
4766
PolygonMeta
4867
49-
GeometryBasics.MetaType(Mesh)
68+
julia> GeometryBasics.MetaType(Mesh)
5069
MeshMeta
5170
```
5271
The metageometry objects are infact composed of the original geometry types.
53-
```@jldoctest
54-
GeometryBasics.MetaFree(PolygonMeta)
72+
73+
```jldoctest meta
74+
julia> GeometryBasics.MetaFree(PolygonMeta)
5575
Polygon
5676
57-
GeometryBasics.MetaFree(MeshMeta)
77+
julia> GeometryBasics.MetaFree(MeshMeta)
5878
Mesh
5979
```
80+
6081
## MetaT
61-
In GeometryBasics we can a have tabular layout for a collection of meta-geometries by putting them into a StructArray that extends the [Tables.jl](https://github.com/JuliaData/Tables.jl) API.
6282

63-
In practice it's not necessary for the geometry or metadata types to be consistent. Eg: A geojson format can have heterogeneous geometries.
64-
Hence, such cases require automatic widening of the geometry data types to the most appropriate type. The MetaT method works around the fact that, a collection of geometries and metadata of different types can be represented tabularly whilst widening to the appropriate type.
83+
In GeometryBasics we can a have tabular layout for a collection of meta-geometries
84+
by putting them into a StructArray that extends the [Tables.jl](https://github.com/JuliaData/Tables.jl) API.
85+
86+
In practice it's not necessary for the geometry or metadata types to be consistent.
87+
For example, a geojson format can have heterogeneous geometries. Hence, such cases require
88+
automatic widening of the geometry data types to the most appropriate type.
89+
The MetaT method works around the fact that, a collection of geometries and metadata
90+
of different types can be represented tabularly whilst widening to the appropriate type.
91+
6592
### Syntax
66-
```
93+
94+
```julia
6795
MetaT(geometry, meta::NamedTuple)
6896
MetaT(geometry; meta...)
69-
```
97+
```
7098
Returns a `MetaT` that holds a geometry and its metadata `MetaT` acts the same as `Meta` method.
7199
The difference lies in the fact that it is designed to handle geometries and metadata of different/heterogeneous types.
72100

73-
eg: While a Point MetaGeometry is a `PointMeta`, the MetaT representation is `MetaT{Point}`
101+
For example, while a Point MetaGeometry is a `PointMeta`, the MetaT representation is `MetaT{Point}`.
102+
103+
### Examples
74104

75-
### Example
76-
```@jldoctest
77-
MetaT(Point(1, 2), city = "Mumbai")
105+
```jldoctest meta
106+
julia> MetaT(Point(1, 2), city = "Mumbai")
78107
MetaT{Point{2,Int64},(:city,),Tuple{String}}([1, 2], (city = "Mumbai",))
79108
```
80109

81110
For a tabular representation, an iterable of `MetaT` types can be passed on to a `metatable` method.
82111

83112
### Syntax
84-
```@jldoctest
113+
114+
```julia
85115
meta_table(iter)
86-
```
87-
### Example
88-
```@jldoctest
89-
using DataFrames
90-
# Create an array of 2 linestrings
91-
ls = [LineString([Point(i, i+1), Point(i-1,i+5)]) for i in 1:2]
116+
```
117+
118+
### Examples
119+
120+
Create an array of 2 linestrings:
121+
122+
```jldoctest meta
123+
julia> ls = [LineString([Point(i, i+1), Point(i-1,i+5)]) for i in 1:2];
124+
125+
julia> coordinates.(ls)
126+
2-element Array{Array{Point{2,Int64},1},1}:
127+
[[1, 2], [0, 6]]
128+
[[2, 3], [1, 7]]
129+
```
130+
131+
Create a multi-linestring:
132+
133+
```jldoctest meta
134+
julia> mls = MultiLineString(ls);
92135
93-
# Create a MultiLineString
94-
mls = MultiLineString(ls)
136+
julia> coordinates.(mls)
137+
2-element Array{Array{Point{2,Int64},1},1}:
138+
[[1, 2], [0, 6]]
139+
[[2, 3], [1, 7]]
140+
```
141+
142+
Create a polygon:
95143

96-
# Create a Polygon
97-
poly = Polygon(Point{2, Int}[(40, 40), (20, 45), (45, 30), (40, 40)])
144+
```jldoctest meta
145+
julia> poly = Polygon(Point{2, Int}[(40, 40), (20, 45), (45, 30), (40, 40)]);
98146
99-
# Put all of it in an Array
100-
geom = [ls..., mls, poly]
101-
102-
# Generate some random metadata
103-
prop = [(country_states = "India$(i)", rainfall = (i*9)/2) for i in 1:4]
104-
105-
# Create an Array of MetaT
106-
feat = [MetaT(i, j) for (i,j) = zip(geom, prop)]
147+
julia> coordinates(poly)
148+
4-element Array{Point{2,Int64},1}:
149+
[40, 40]
150+
[20, 45]
151+
[45, 30]
152+
[40, 40]
153+
```
107154

108-
# Generate a StructArray/Table
109-
sa = meta_table(feat)
155+
Put all geometries into an array:
110156

111-
sa.main
112-
sa.country_states
113-
sa.rainfall
157+
```jldoctest meta
158+
julia> geom = [ls..., mls, poly];
114159
```
115160

116-
### Disadvantages:
117-
* The MetaT is pretty generic in terms of geometry types, it's not subtype to geometries. eg : A `MetaT{Point, NamedTuple{Names, Types}}` is not subtyped to `AbstractPoint` like a `PointMeta` is.
118-
* This might cause problems on using `MetaT` with other constructors/methods inside or even outside GeometryBasics methods designed to work with the main `Meta` types.
161+
:Generate some random metadata:
162+
163+
```jldoctest meta
164+
julia> prop = [(country_states = "India$(i)", rainfall = (i*9)/2) for i in 1:4]
165+
4-element Array{NamedTuple{(:country_states, :rainfall),Tuple{String,Float64}},1}:
166+
(country_states = "India1", rainfall = 4.5)
167+
(country_states = "India2", rainfall = 9.0)
168+
(country_states = "India3", rainfall = 13.5)
169+
(country_states = "India4", rainfall = 18.0)
170+
171+
julia> feat = [MetaT(i, j) for (i,j) = zip(geom, prop)]; # create an array of MetaT
172+
```
173+
174+
We can now generate a `StructArray` / `Table` with `meta_table`. Fields are accessed with `sa.main`, `sa.country_states`, `sa.rainfall`.
175+
176+
```jldoctest meta
177+
julia> sa = meta_table(feat);
178+
```
179+
180+
### Disadvantages
181+
182+
* The MetaT is pretty generic in terms of geometry types, it's not subtype to
183+
geometries. eg : A `MetaT{Point, NamedTuple{Names, Types}}` is not subtyped to
184+
`AbstractPoint` like a `PointMeta` is.
119185

186+
* This might cause problems on using `MetaT` with other constructors/methods
187+
inside or even outside GeometryBasics methods designed to work with the main `Meta` types.

src/basic_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ end
197197
"""
198198
LineString(points::AbstractVector{<: AbstractPoint}, skip = 1)
199199
200-
Creates a LineString from a vector of points
200+
Creates a LineString from a vector of points.
201201
With `skip == 1`, the default, it will connect the line like this:
202202
```julia
203203
points = Point[a, b, c, d]

0 commit comments

Comments
 (0)