Skip to content

Commit 4f0a08d

Browse files
authored
Finalize 1st draft of types and structs, add docs (#1)
* first pass at basic types and structs * fix types * fix typo * some type/struct fixes and simplification * add some docstrings * some cleanup, adjust types and structs * change node to vertex through to match JuliaGraphs terminology * update readme * update docs
1 parent de0e7e1 commit 4f0a08d

File tree

7 files changed

+144
-7
lines changed

7 files changed

+144
-7
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# SpatialGraphs.jl
22

3-
SpatialGraphs.jl is low level package that offers types and constructors for
4-
spatially referenced graphs. The primary type is `SpatialGraph`, which is a
5-
`LightGraphs.AbstractGraph`.
3+
SpatialGraphs.jl introduces the `AbstractSpatialGraph`. `AbstractSpatialGraphs`
4+
are a subtype of `LightGraphs.AbstractGraph`, and can be weighted or directed.
5+
AbstractSpatialGraphs are AbstractGraphs, methods from LightGraphs.jl and
6+
SimpleWeightedGraphs.jl work right out of the box.
7+
8+
`AbstractSpatialGraph`s themselves contain an `AbstractGraph` in addition to
9+
metadata that details the spatial location of each vertex in the
10+
graph. At this time, only raster-based graph types have been developed (and
11+
vertex locations are stored in a `GeoData.GeoArray`), but there are plans to
12+
implement graph types for vector data as well.

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ makedocs(
1717
modules = [SpatialGraphs],
1818
authors = "Vincent A. Landau",
1919
sitename = "SpatialGraphs.jl",
20-
pages = ["About" => "index.md"],
20+
pages = ["About" => "index.md",
21+
"Graph Types" => "graphtypes.md"],
2122
)
2223

2324
deploydocs(

docs/src/graphtypes.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Graph Types in SpatialGraphs.jl
2+
3+
At this time, only raster-based graph types have been developed (and
4+
vertex locations are stored in a `GeoData.GeoArray`), but there are plans to
5+
eventually implement graph types for vector data as well.
6+
7+
## Abstract Types
8+
The overarching type in SpatialGraphs.jl is the `AbstractSpatialGraph`. All
9+
`AbstractSpatialGraph` subtypes contain a field called `graph`, which is itself
10+
an `AbstractGraph`.
11+
```@docs
12+
AbstractSpatialGraph
13+
```
14+
15+
The `AbstractRasterGraph` type is as subtype of `AbstractSpatialGraph`. All
16+
`AbstractRasterGraph` subtypes contain a field called `vertex_raster`, which is
17+
a `GeoData.GeoArray` that describes the spatial locations for the vertices in
18+
the graph. If your graph has 10 vertices, then the corresponding `GeoArray`
19+
must have 10 unique values, starting at 1 (which corresponds to the first vertex
20+
in the graph) and going up to 10 (which corresponds to the tenth vertex in the
21+
graph). To find the location of a given graph vertex, _n_, you simply identify
22+
the pixel(s) with a value of _n_.
23+
```@docs
24+
AbstractRasterGraph
25+
```
26+
27+
## AbstractRasterGraph Subtypes
28+
SpatialGraphs.jl has raster graph types for undirected, directed, unweighted,
29+
and weighted graphsm each detailed below.
30+
31+
```@docs
32+
SimpleRasterGraph
33+
SimpleRasterDiGraph
34+
WeightedRasterGraph
35+
WeightedRasterDiGraph
36+
```

docs/src/index.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# SpatialGraphs.jl
22

3-
SpatialGraphs.jl is low level package that offers types and constructors for
4-
spatially referenced graphs. The primary type is `SpatialGraph`, which is a
5-
`LightGraphs.AbstractGraph`.
3+
SpatialGraphs.jl introduces the `AbstractSpatialGraph`. `AbstractSpatialGraphs`
4+
are a subtype of `LightGraphs.AbstractGraph`, and can be weighted or directed.
5+
SpatialGraphs.jl is useful for turning spatial data into graphs. This can be
6+
useful for landscape connectivity analysis, hydrology, and other spatial
7+
network processes. AbstractSpatialGraphs are AbstractGraphs, methods from
8+
LightGraphs.jl and SimpleWeightedGraphs.jl work right out of the box.
9+
Go to [Graph Types](@ref) for more details on the graph types implemented in
10+
this package.
11+

src/SpatialGraphs.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ module SpatialGraphs
22

33
using LightGraphs, SimpleWeightedGraphs, ArchGDAL
44

5+
## Types and Structs
6+
export AbstractSpatialGraph, AbstractSpatialWeightedGraph, RasterGraph,
7+
RasterDiGraph, WeightedRasterGraph, WeightedRasterDiGraph
8+
59
end # module

src/graph_interface.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Methods for the LightGraphs ad SimpleWeightedGraphs interfaces
2+
## With these methods defined, functions from LightGraphs should "just work"
3+
4+
### LightGraphs interface
5+
nv(g::AbstractSpatialGraph) = nv(g.graph)
6+
ne(g::AbstractSpatialGraph) = ne(g.graph)
7+
vertices(g::AbstractSpatialGraph) = vertices(g.graph)
8+
edges(g::AbstractSpatialGraph) = edges(g.graph)
9+
Base.eltype(g::AbstractSpatialGraph) = eltype(g.graph)
10+
edgetype(g::AbstractSpatialGraph) = edgetype(g.graph)
11+
has_edge(g::AbstractSpatialGraph, s, d) = has_edge(g.graph, s, d)
12+
has_vertex(g::AbstractSpatialGraph, v) = has_vertex(g.graph, v)
13+
inneighbors(g::AbstractSpatialGraph, v) = inneighbors(g.graph, v)
14+
outneighbors(g::AbstractSpatialGraph, v) = outneighbors(g.graph, v)
15+
is_directed(g::AbstractSpatialGraph) = is_directed(g.graph)
16+
Base.zero(g::AbsractSpatialGraph) = zero(g.graph)
17+
18+
### SimpleWeightedGraphs interface
19+
get_weight(g::AbstractWeightedSpatialGraph, u::Integer, v::Integer) = get_weight(g.graph, u, v)

src/structs.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## All types and structs for SpatialGraphs.jl
2+
"""
3+
AbstractSpatialGraph{T}
4+
5+
An abstract type representing a spatially referenced graph.
6+
7+
An AbstractSpatialGraph must contain the following attributes/element:
8+
9+
- `graph::AbstractGraph`
10+
"""
11+
abstract type AbstractSpatialGraph{T} <: AbstractGraph{T} end
12+
13+
"""
14+
AbstractRsterGraph{T}
15+
16+
An abstract type representing a spatially referenced graph, with graph vertices corresponding to pixels in a raster.
17+
18+
An AbstractSpatialGraph must contain the following attributes/element:
19+
20+
- `graph::AbstractGraph`
21+
- `vertex_raster::GeoArray`
22+
"""
23+
abstract type AbstractRasterGraph{T} <: AbstractSpatialGraph{T} end
24+
25+
"""
26+
WeightedRasterGraph{T}
27+
28+
A composite type for a spatially referenced weighted graph. Vertices are spatially referenced based on a raster.
29+
"""
30+
mutable struct WeightedRasterGraph{T<:Integer, U<:Real} <: AbstractRasterGraph{T}
31+
graph::SimpleWeightedGraph{T, U} # a SimpleWeightedGraph with edge weights
32+
vertex_raster::GeoArray # A GeoArray raster, where a pixel's value denotes its vertex ID in the graph
33+
end
34+
"""
35+
WeightedRasterDiGraph{T}
36+
37+
A composite type for a spatially referenced, weighted, directed graph. Vertices are spatially referenced based on a raster.
38+
"""
39+
mutable struct WeightedRasterDiGraph{T<:Integer, U<:Real} <: AbstractRasterGraph{T}
40+
graph::SimpleWeightedDiGraph{T, U} # a SimpleWeightedDiGraph with edge weights
41+
vertex_raster::GeoArray # A GeoArray raster, where a pixel's value denotes its vertex ID in the graph
42+
end
43+
44+
"""
45+
SimpleRasterGraph{T}
46+
47+
A composite type for a spatially referenced graph. Vertices are spatially referenced based on a raster.
48+
49+
A RasterGraph
50+
"""
51+
mutable struct SimpleRasterGraph{T<:Integer} <: AbstractRasterGraph{T}
52+
graph::SimpleGraph{T} # A SimpleGraph
53+
vertex_raster::GeoArray # A GeoArray raster, where a pixel's value denotes its vertex ID in the graph
54+
end
55+
56+
"""
57+
SimpleRasterDiGraph{T}
58+
59+
A composite type for a spatially referenced directed graph. Vertices are spatially referenced based on a raster.
60+
"""
61+
mutable struct SimpleRasterDiGraph{T<:Integer} <: AbstractRasterGraph{T}
62+
graph::SimpleDiGraph{T} # A SimpleDiGraph
63+
vertex_raster::GeoArray # A GeoArray raster, where a pixel's value denotes its vertex ID in the graph
64+
end

0 commit comments

Comments
 (0)