Skip to content

Commit 8b96328

Browse files
author
Vincent Landau
committed
move from GeoData to Rasters
1 parent 559fe35 commit 8b96328

14 files changed

+61
-61
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ authors = ["Vincent A. Landau <[email protected]>"]
44
version = "0.0.1"
55

66
[deps]
7-
GeoData = "9b6fcbb8-86d6-11e9-1ce7-23a6bb139a78"
87
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
8+
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
99
SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622"
1010
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212

1313
[compat]
14-
GeoData = "0.5"
1514
Graphs = "1.4"
15+
Rasters = "0.1"
1616
julia = "1.6"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ out of the box.
1212
`AbstractSpatialGraph`s themselves contain an `AbstractGraph` in addition to
1313
metadata that details the spatial location of each vertex in the
1414
graph. At this time, only raster-based graph types have been developed (and
15-
vertex locations are stored in a `GeoData.GeoArray`), but there are plans to
15+
vertex locations are stored in a `Rasters.Raster`), but there are plans to
1616
implement graph types for vector data as well.

docs/src/graphtypes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [Graph Types in SpatialGraphs.jl](@id graph_types)
22

33
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
4+
vertex locations are stored in a `Rasters.Raster`), but there are plans to
55
eventually implement graph types for vector data as well.
66

77
## Abstract Types
@@ -14,7 +14,7 @@ AbstractSpatialGraph
1414

1515
The `AbstractRasterGraph` type is a subtype of `AbstractSpatialGraph`. All
1616
`AbstractRasterGraph` subtypes contain a field called `vertex_raster`, which is
17-
a `GeoData.GeoArray` that describes the spatial locations for the vertices in
17+
a `Rasters.Raster` that describes the spatial locations for the vertices in
1818
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

src/SpatialGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module SpatialGraphs
22

3-
using Graphs, SimpleWeightedGraphs, SparseArrays, GeoData
3+
using Graphs, SimpleWeightedGraphs, SparseArrays, Rasters
44

55
include("structs.jl")
66
include("graph_interface.jl")

src/rastergraphs.jl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
"""
2-
make_vertex_raster(A::GeoArray)
2+
make_vertex_raster(A::Raster)
33
44
Constuct a vertex raster (a raster where the value of each pixel corresponds
5-
to its ID in a graph, and 0s correspond to NoData). Returns a GeoArray. This
5+
to its ID in a graph, and 0s correspond to NoData). Returns a Raster. This
66
function is recommended for internal use only.
77
88
## Parameters
9-
`A`: The GeoArray from which a graph will be built, which is used as the
9+
`A`: The Raster from which a graph will be built, which is used as the
1010
reference for building the vertex raster. Pixels with NoData (`A.missingval`)
1111
are skipped (no vertex is assigned). Pixels with NoData will get a value of 0 in
1212
the vertex raster.
1313
"""
14-
function make_vertex_raster(A::GeoData.GeoArray)
14+
function make_vertex_raster(A::Raster)
1515
# Make an array of unique node identifiers
1616
nodemap = zeros(Int64, size(A.data))
1717
is_node = (A.data .!= A.missingval) .&
1818
((!).(isnan.(A.data)))
1919

2020
nodemap[is_node] = 1:sum(is_node)
2121

22-
nodemap = GeoData.GeoArray(nodemap, dims(A))
22+
nodemap = Raster(nodemap, dims(A))
2323

2424
nodemap
2525
end
2626

2727

2828
"""
2929
weightedrastergraph(
30-
weight_raster::GeoArray;
30+
weight_raster::Raster;
3131
directed::Bool = false,
32-
condition_raster::GeoArray = weight_raster,
32+
condition_raster::Raster = weight_raster,
3333
condition::Function = is_data,
3434
cardinal_neighbors_only::Bool = false,
3535
connect_using_avg_weights::Bool = true
@@ -42,7 +42,7 @@ on vertices, edge weights are calculated as the average of the weights for each
4242
vertex.
4343
4444
## Parameters
45-
`weight_raster`: A GeoData.GeoArray contained values that, where applicable
45+
`weight_raster`: A Rasters.Raster contained values that, where applicable
4646
based on other arguments, determines which pixels to connect and the edge
4747
weights between pixels. Any pixel in `weight_raster` with a value not equal to
4848
`weight_raster.missingval` will be assigned a vertex in the graph (corresponding
@@ -90,9 +90,9 @@ neighbors) of the weights in `weight_raster` is used.
9090
9191
"""
9292
function weightedrastergraph(
93-
weight_raster::GeoArray;
93+
weight_raster::Raster;
9494
directed::Bool = false,
95-
condition_raster::GeoArray = weight_raster,
95+
condition_raster::Raster = weight_raster,
9696
condition::Function = is_data,
9797
cardinal_neighbors_only::Bool = false,
9898
connect_using_avg_weights::Bool = true
@@ -120,7 +120,7 @@ end
120120

121121
"""
122122
RasterGraph(
123-
raster::GeoArray;
123+
raster::Raster;
124124
directed::Bool = true,
125125
condition::Function = is_data,
126126
cardinal_neighbors_only::Bool = false
@@ -130,7 +130,7 @@ Construct a `RasterGraph` or `RasterDiGraph` (if
130130
`directed = true`) from a raster dataset.
131131
132132
## Parameters
133-
`raster`: A GeoData.GeoArray on which to base the graph. Any pixel in `raster`
133+
`raster`: A Rasters.Raster on which to base the graph. Any pixel in `raster`
134134
with a value not equal to `raster.missingval` will be assigned a vertex
135135
in the graph (corresponding to its centroid). The values in the raster can also
136136
be used to determine which vertices to connect. See `condition` below for more
@@ -162,7 +162,7 @@ increased distance between them (as compared to the distance between cardinal
162162
neighbors) is accounted for.
163163
"""
164164
function rastergraph(
165-
raster::GeoArray;
165+
raster::Raster;
166166
condition::Function = is_data,
167167
directed::Bool = true,
168168
cardinal_neighbors_only::Bool = false,
@@ -187,10 +187,10 @@ end
187187

188188
"""
189189
make_weighted_raster_graph(
190-
weight_raster::GeoArray,
191-
vertex_raster::GeoArray;
190+
weight_raster::Raster,
191+
vertex_raster::Raster;
192192
directed::Bool = false,
193-
condition_raster::GeoArray = weight_raster,
193+
condition_raster::Raster = weight_raster,
194194
condition::Function = is_data,
195195
cardinal_neighbors_only::Bool = false,
196196
connect_using_avg_weights::Bool = true,
@@ -206,13 +206,13 @@ vertex. Since edges are between rather than on vertices, edge weights are
206206
calculated as the average of the weights for each vertex being connected.
207207
208208
## Parameters
209-
`weight_raster`: A `GeoData.GeoArray` containing values that, where applicable
209+
`weight_raster`: A `Rasters.Raster` containing values that, where applicable
210210
based on other arguments, determine which pixels to connect and the edge
211211
weights between pixels. Any pixel in `weight_raster` with a value not equal to
212212
`weight_raster.missingval` will be assigned a vertex in the graph (corresponding
213213
to its centroid).
214214
215-
`vertex_raster`: A `GeoData.GeoArray` with integer values ranging from 1:n,
215+
`vertex_raster`: A `Rasters.Raster` with integer values ranging from 1:n,
216216
where n is the number of unique vertices in the graph.
217217
218218
## Arguments
@@ -256,10 +256,10 @@ of vertices, how should the weight be chosen? Defaults to `min`. See the docs
256256
for `SparseArrays.sparse()` for more information.
257257
"""
258258
function make_weighted_raster_graph(
259-
weight_raster::GeoArray,
260-
vertex_raster::GeoArray;
259+
weight_raster::Raster,
260+
vertex_raster::Raster;
261261
directed::Bool = false,
262-
condition_raster::GeoArray = weight_raster,
262+
condition_raster::Raster = weight_raster,
263263
condition::Function = is_data,
264264
cardinal_neighbors_only::Bool = false,
265265
connect_using_avg_weights::Bool = true,
@@ -289,8 +289,8 @@ end
289289

290290
"""
291291
make_simple_raster_graph(
292-
raster::GeoArray,
293-
vertex_raster::GeoArray;
292+
raster::Raster,
293+
vertex_raster::Raster;
294294
directed::Bool = false,
295295
condition::Function = is_data,
296296
cardinal_neighbors_only::Bool = false,
@@ -305,13 +305,13 @@ in the graph, and `raster` is used to construct the graph and determine which
305305
vertices to connect.
306306
307307
## Parameters
308-
`raster`: A GeoData.GeoArray on which to base the graph. Any pixel in `raster`
308+
`raster`: A Rasters.Raster on which to base the graph. Any pixel in `raster`
309309
with a value not equal to `raster.missingval` will be assigned a vertex
310310
in the graph (corresponding to its centroid). The values in the raster can also
311311
be used to determine which vertices to connect. See `condition` below for more
312312
information.
313313
314-
`vertex_raster`: A `GeoData.GeoArray` with integer values ranging from 1:n,
314+
`vertex_raster`: A `Rasters.Raster` with integer values ranging from 1:n,
315315
where n is the number of unique vertices in the graph.
316316
317317
## Arguments
@@ -355,8 +355,8 @@ of vertices, how should the weight be chosen? Defaults to `min`. See the docs
355355
for `SparseArrays.sparse()` for more information.
356356
"""
357357
function make_simple_raster_graph(
358-
raster::GeoArray,
359-
vertex_raster::GeoArray;
358+
raster::Raster,
359+
vertex_raster::Raster;
360360
directed::Bool = false,
361361
condition::Function = is_data,
362362
cardinal_neighbors_only::Bool = false,
@@ -378,11 +378,11 @@ end
378378

379379

380380
function make_raster_graph(
381-
raster::GeoArray,
382-
vertex_raster::GeoArray;
381+
raster::Raster,
382+
vertex_raster::Raster;
383383
directed::Bool = false,
384384
weighted::Bool = true,
385-
condition_raster::GeoArray = raster,
385+
condition_raster::Raster = raster,
386386
condition::Function = is_data,
387387
cardinal_neighbors_only::Bool = false,
388388
connect_using_avg_weights::Bool = true,
@@ -410,7 +410,7 @@ function make_raster_graph(
410410
# Add the edges
411411
# Only need to do neighbors down or to the right for undirected graphs
412412
# because edge additions will be redundant.
413-
# Cardinal directions are in quotes since sometimes GeoArray are permuted
413+
# Cardinal directions are in quotes since sometimes Raster are permuted
414414
# such that the top row doesn't necessarily correspond to the northern-most
415415
# pixels
416416
for row in 1:dims[1]

src/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function show(io::IO, g::AbstractRasterGraph)
1212
)
1313
printstyled(" with dimensions:\n", color=:light_black)
1414

15-
x_dim = dims(g.vertex_raster, XDim)
16-
y_dim = dims(g.vertex_raster, YDim)
15+
x_dim = dims(g.vertex_raster, X)
16+
y_dim = dims(g.vertex_raster, Y)
1717
printstyled(" X", color=:cyan)
1818
print(
1919
": range($(minimum(x_dim)), $(maximum(x_dim)), step=$(x_dim.val[2] - x_dim.val[1]))\n"

src/structs.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ An abstract type representing a spatially referenced graph, with graph vertices
1818
An AbstractRasterGraph must contain the following fields:
1919
2020
- `graph::AbstractGraph`
21-
- `vertex_raster::GeoArray`
21+
- `vertex_raster::Raster`
2222
"""
2323
abstract type AbstractRasterGraph{T} <: AbstractSpatialGraph{T} end
2424

@@ -29,7 +29,7 @@ A composite type for a spatially referenced weighted graph. Vertices are spatial
2929
"""
3030
mutable struct WeightedRasterGraph{T<:Integer, U<:Real} <: AbstractRasterGraph{T}
3131
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
32+
vertex_raster::Raster # A Raster raster, where a pixel's value denotes its vertex ID in the graph
3333
end
3434
"""
3535
WeightedRasterDiGraph{T}
@@ -38,7 +38,7 @@ A composite type for a spatially referenced, weighted, directed graph. Vertices
3838
"""
3939
mutable struct WeightedRasterDiGraph{T<:Integer, U<:Real} <: AbstractRasterGraph{T}
4040
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
41+
vertex_raster::Raster # A Raster raster, where a pixel's value denotes its vertex ID in the graph
4242
end
4343

4444
"""
@@ -48,7 +48,7 @@ A composite type for a spatially referenced graph. Vertices are spatially refere
4848
"""
4949
mutable struct RasterGraph{T<:Integer} <: AbstractRasterGraph{T}
5050
graph::Graph{T} # A Graph
51-
vertex_raster::GeoArray # A GeoArray raster, where a pixel's value denotes its vertex ID in the graph
51+
vertex_raster::Raster # A Raster raster, where a pixel's value denotes its vertex ID in the graph
5252
end
5353

5454
"""
@@ -58,5 +58,5 @@ A composite type for a spatially referenced directed graph. Vertices are spatial
5858
"""
5959
mutable struct RasterDiGraph{T<:Integer} <: AbstractRasterGraph{T}
6060
graph::DiGraph{T} # A DiGraph
61-
vertex_raster::GeoArray # A GeoArray raster, where a pixel's value denotes its vertex ID in the graph
61+
vertex_raster::Raster # A Raster raster, where a pixel's value denotes its vertex ID in the graph
6262
end

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
is_data(a::Number, b::Number)
44
55
This function is the default used for deciding whether to connect two neighbors
6-
in a GeoArray when constructing a graph. It always returns `true`, so all
6+
in a Raster when constructing a graph. It always returns `true`, so all
77
neighbors will be connected
88
99
Returns `true`
@@ -22,7 +22,7 @@ res_cardinal_avg(x, y) = (x + y) / 2
2222
res_diagonal_avg(x, y) = ((x + y) * 2) / 2
2323

2424

25-
# function get_dims(A::GeoData.GeoArray)
25+
# function get_dims(A::Rasters.Raster)
2626
# y_first = dims(mytif)[1] isa XDim
2727
# first_dim_type = y_first ? YDim : XDim
2828
# second_dim_type = y_first ? XDim : YDim

test/lg_interface.jl renamed to test/graph_interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SpatialGraphs, Test, GeoData, Graphs, SimpleWeightedGraphs
1+
using SpatialGraphs, Test, Rasters, Graphs, SimpleWeightedGraphs
22
## This script tests methods for the LightGraph interface that aren't already
33
## used in other tests
44

@@ -8,7 +8,7 @@ x = X(1:4)
88
y = Y(1:3)
99
band = Band(1:1)
1010

11-
weight_raster = GeoArray(A_array, (y, x, band), missingval = -9999)
11+
weight_raster = Raster(A_array, (y, x, band), missingval = -9999)
1212
rasgraph = weightedrastergraph(weight_raster)
1313

1414
@test nv(rasgraph) == maximum(rasgraph.vertex_raster)

test/rasterdigraphs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GeoData, Graphs, SimpleWeightedGraphs, SpatialGraphs, Test
1+
using Rasters, Graphs, SimpleWeightedGraphs, SpatialGraphs, Test
22

33
condition_array = Array{Float64}(undef, (3, 4, 1))
44
condition_array[:,:,:] = [1, 0.5, 5, 2, 4, 8, 5, -9999, 2, 3, 6, 7]
@@ -7,7 +7,7 @@ x = X(1:4)
77
y = Y(1:3)
88
band = Band(1:1)
99

10-
condition_raster = GeoArray(condition_array, (y, x, band), missingval = -9999)
10+
condition_raster = Raster(condition_array, (y, x, band), missingval = -9999)
1111

1212
compare = <
1313
rasgraph = rastergraph(

0 commit comments

Comments
 (0)