Skip to content

Commit 0a48711

Browse files
committed
make docs good
1 parent 3e69a76 commit 0a48711

File tree

2 files changed

+124
-3
lines changed

2 files changed

+124
-3
lines changed

docs/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
[deps]
2+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3+
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
24
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
5+
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
6+
GeoInterfaceMakie = "0edc0954-3250-4c18-859d-ec71c1660c08"
7+
NaturalEarth = "436b0209-26ab-4e65-94a9-6526d86fea76"
38
TGGeometry = "d7e755d2-3c95-4bcf-9b3c-79ab1a78647b"

docs/src/index.md

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,127 @@ CurrentModule = TGGeometry
44

55
# TGGeometry
66

7-
Documentation for [TGGeometry](https://github.com/JuliaGeo/TGGeometry.jl).
7+
TGGeometry.jl is a Julia wrapper around the [`tg`](https://github.com/tidwall/tg) C library for planar geometric predicates. Specifically, it provides:
8+
9+
- [`intersects(geom1, geom2)`](@ref intersects)
10+
- [`contains(geom1, geom2)`](@ref contains)
11+
- [`touches(geom1, geom2)`](@ref touches)
12+
- [`disjoint(geom1, geom2)`](@ref disjoint)
13+
- [`equals(geom1, geom2)`](@ref equals)
14+
- [`covers(geom1, geom2)`](@ref covers)
15+
- [`coveredby(geom1, geom2)`](@ref coveredby)
16+
- [`within(geom1, geom2)`](@ref within)
17+
18+
from the [DE-9IM](https://en.wikipedia.org/wiki/DE-9IM) model.
19+
20+
It is fully [GeoInterface.jl](https://github.com/JuliaGeo/GeoInterface.jl) compatible, and is able to accept any combination of GeoInterface-compatible geometries as input (from GeoDataFrames, GeoJSON, ArchGDAL, GeometryOps, and many more packages!).
821

922
```@index
1023
```
1124

12-
```@autodocs
13-
Modules = [TGGeometry]
25+
## Quick start
26+
27+
### Installation
28+
29+
Install via `]add TGGeometry` in the REPL, or `Pkg.add("TGGeometry")`.
30+
31+
### Basic usage
32+
33+
Since TGGeometry allows any GeoInterface-compatible geometry as input, let's start with some geometries from NaturalEarth.jl:
34+
```@example quickstart
35+
using NaturalEarth
36+
using TGGeometry
37+
all_countries = naturalearth("admin_0_countries", 10)
38+
germany = all_countries.geometry[findfirst(==("Germany"), all_countries.NAME)]
39+
belgium = all_countries.geometry[findfirst(==("Belgium"), all_countries.NAME)]
40+
using CairoMakie, GeoInterfaceMakie
41+
f, a, p = poly(germany; label = "Germany", axis = (; aspect = DataAspect(),)) # hide
42+
poly!(a, belgium; label = "Belgium") # hide
43+
leg = axislegend(a) # hide
44+
hidedecorations!(a) # hide
45+
f # hide
46+
```
47+
48+
```@example quickstart
49+
TGGeometry.intersects(germany, belgium)
50+
```
51+
52+
```@example quickstart
53+
TGGeometry.contains(germany, belgium)
1454
```
55+
56+
```@example quickstart
57+
TGGeometry.touches(germany, belgium)
58+
```
59+
60+
```@example quickstart
61+
TGGeometry.disjoint(germany, belgium)
62+
```
63+
64+
You can use any data loader, like GeoJSON, GeoDataFrames, ArchGDAL, etc. You can also construct your own geometries via GeometryBasics, GeoInterface wrapper geometries, or accepted basic types like 2-tuple points.
65+
66+
```@example quickstart
67+
berlin = (13.4050, 52.5200) # berlin (longitude, latitude)
68+
scatter!(a, [berlin], color = :red, label = "Berlin") # hide
69+
delete!(leg) # hide
70+
leg = axislegend(a) # hide
71+
f # hide`
72+
```
73+
74+
```@example quickstart
75+
TGGeometry.contains(germany, berlin)
76+
```
77+
78+
### "Preparing" using `TGGeom`
79+
80+
TGGeometry is fast naturally, but you can make it even faster by "preparing" your geometries by converting them to `TGGeom`s. This converts the geometries to opaque pointers to a `tg` geometry - still fully GeoInterface-compatible though, but they have the acceleration benefits and don't have to be continually converted every time you call a predicate.
81+
82+
The way to convert is to call `GeoInterface.convert(TGGeometry, geom)`. This will convert the geometry to a `TGGeom` and return the new `TGGeom` object.
83+
84+
Let's see the difference in speed, between using a `TGGeom` and a GeoJSON polygon:
85+
86+
```@example quickstart
87+
using Chairmarks, GeoInterface
88+
gj_bench = @be TGGeometry.contains($germany, $berlin)
89+
```
90+
91+
```@example quickstart
92+
# Convert to TGGeom
93+
germany_tg = GeoInterface.convert(TGGeometry, germany)
94+
95+
tg_bench = @be TGGeometry.contains($germany_tg, $berlin)
96+
```
97+
98+
The prepared approach is about **340x** faster!
99+
100+
## Predicates
101+
102+
Predicates from the DE-9IM model are available (but not a full `relate` function that would return the full DE-9IM matrix).
103+
104+
```@docs
105+
intersects
106+
contains
107+
touches
108+
disjoint
109+
equals
110+
covers
111+
coveredby
112+
within
113+
```
114+
115+
## TGGeom
116+
117+
The `TGGeom` type is a wrapper around the `tg_geom` object returned by the `tg` library. It is fully [GeoInterface.jl](https://github.com/JuliaGeo/GeoInterface.jl) compatible, and is able to accept any combination of GeoInterface-compatible geometries as input (from GeoDataFrames, GeoJSON, ArchGDAL, GeometryOps, and many more packages!).
118+
119+
```@docs
120+
TGGeom
121+
```
122+
123+
## Installation
124+
125+
It's as simple as `]add TGGeometry`.
126+
127+
## License
128+
129+
This project is licensed under the MIT License - see the LICENSE file for details.
130+

0 commit comments

Comments
 (0)