Skip to content

Commit cdc4085

Browse files
authored
Graph constructors and tests (#2)
* add constructor methods * rework filenames, add tests, update docs * more tests, fixes to DiGraph construction
1 parent 4800c72 commit cdc4085

File tree

12 files changed

+599
-7
lines changed

12 files changed

+599
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ run-dev.sh
33
Manifest.toml
44
docs/build
55
docs/make-local.jl
6+
local

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212

1313
[compat]
1414
ArchGDAL = "0.6"
15-
GeoData = "0.4.6"
1615
julia = "1.6"

docs/make.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const formats = Any[
55
assets = [
66
"assets/custom.css"
77
],
8-
edit_link = :commit,
8+
edit_link = :commit,
99
),
1010
]
1111

@@ -15,7 +15,8 @@ makedocs(
1515
authors = "Vincent A. Landau",
1616
sitename = "SpatialGraphs.jl",
1717
pages = ["About" => "index.md",
18-
"Graph Types" => "graphtypes.md"],
18+
"Graph Types" => "graphtypes.md",
19+
"User Guide" => "userguide.md"],
1920
)
2021

2122
deploydocs(

docs/src/graphtypes.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ AbstractSpatialGraph
1515
The `AbstractRasterGraph` type is as subtype of `AbstractSpatialGraph`. All
1616
`AbstractRasterGraph` subtypes contain a field called `vertex_raster`, which is
1717
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`
18+
the graph. If your graph has 10 vertices, then the corresponding `vertex_raster`
1919
must have 10 unique values, starting at 1 (which corresponds to the first vertex
2020
in the graph) and going up to 10 (which corresponds to the tenth vertex in the
2121
graph). To find the location of a given graph vertex, _n_, you simply identify
22-
the pixel(s) with a value of _n_.
22+
the pixel(s) with a value of _n_. For pixels/elements in `vertex_raster` for
23+
which there shouldn't be a graph vertex, use a value of 0.
2324
```@docs
2425
AbstractRasterGraph
2526
```
2627

2728
## AbstractRasterGraph Subtypes
2829
SpatialGraphs.jl has raster graph types for undirected, directed, unweighted,
29-
and weighted graphsm each detailed below.
30+
and weighted graphs, each detailed below.
3031

3132
```@docs
3233
SimpleRasterGraph

docs/src/userguide.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# User Guide
2+
3+
## Building Graphs from Rasters
4+
5+
SpatialGraphs.jl offers options methods for constructing graphs from raster
6+
data.
7+
8+
```@docs
9+
weightedrastergraph
10+
make_raster_graph
11+
```

src/SpatialGraphs.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ using LightGraphs, SimpleWeightedGraphs, ArchGDAL, GeoData
44

55
include("structs.jl")
66
include("graph_interface.jl")
7+
include("rastergraphs.jl")
8+
include("utils.jl")
79
## Types and Structs
810
export AbstractSpatialGraph, AbstractRasterGraph, SimpleRasterGraph,
911
SimpleRasterDiGraph, WeightedRasterGraph, WeightedRasterDiGraph
1012

13+
## Raster graph
14+
export make_raster_graph, weightedrastergraph
15+
1116
end # module

src/graph_interface.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## Methods for the LightGraphs ad SimpleWeightedGraphs interfaces
22
## With these methods defined, functions from LightGraphs should "just work"
3+
import LightGraphs:
4+
nv, ne, vertices, edges, eltype, edgetype, has_edge, has_vertex,
5+
inneighbors, outneighbors, is_directed, add_edge!
6+
7+
import SimpleWeightedGraphs:
8+
add_edge!, get_weight
9+
10+
import Base:
11+
eltype, zero
312

413
### LightGraphs interface
514
nv(g::AbstractSpatialGraph) = nv(g.graph)
@@ -14,3 +23,8 @@ inneighbors(g::AbstractSpatialGraph, v) = inneighbors(g.graph, v)
1423
outneighbors(g::AbstractSpatialGraph, v) = outneighbors(g.graph, v)
1524
is_directed(g::AbstractSpatialGraph) = is_directed(g.graph)
1625
Base.zero(g::AbstractSpatialGraph) = zero(g.graph)
26+
add_edge!(g::AbstractSpatialGraph, a::Integer, b::Integer, c::Number) = add_edge!(g.graph, a, b, c)
27+
28+
### SimpleWeightedGraphs
29+
get_weight(g::WeightedRasterGraph, a::Integer, b::Integer) = get_weight(g.graph, a, b)
30+
get_weight(g::WeightedRasterDiGraph, a::Integer, b::Integer) = get_weight(g.graph, a, b)

0 commit comments

Comments
 (0)