Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
Embedding vertex/edge information

The focal point of the provided code snippet revolves around the process of constructing a spatial graph from raster data. This spatial graph serves as a powerful tool for visualizing and analyzing spatial relationships and patterns present within the underlying geographic data.

In addition to forming the basic structure of vertices and edges, the code snippet emphasizes the integration of supplementary information. By utilizing custom structures, developers can enrich vertices and edges with additional details specific to their application domain. For instance, vertices can be decorated with labels or population data, while edges can incorporate distance metrics or other spatial attributes.

This approach enables the creation of spatial graphs that not only capture the topological relationships between locations but also incorporate contextual information essential for comprehensive spatial analysis and modeling.

Input

1#include "quetzal/geography.hpp"
2
3namespace geo = quetzal::geography;
4
5// User-defined data structure to store arbitrary vertex information
6struct MyVertexInfo {
7 std::string population_label = "NA";
8 std::vector<double> population_data_chunk;
9 // ... anything else required by the user context
10};
11
12// User-defined data structure to store arbitrary edge information
13struct MyEdgeInfo {
14 mp_units::quantity<mp_units::si::metre> distance;
15 // needs to be default-constructible
16 MyEdgeInfo() = default;
17 // constructor required by from_grid method: takes a source and a target vertex descriptor, and a spatial grid
18 MyEdgeInfo(auto s, auto t, auto const& raster){
19 distance = raster.to_lonlat(s).great_circle_distance_to( raster.to_lonlat(t) );
20 }
21};
22
23int main()
24{
25 auto file = std::filesystem::current_path() / "data/bio1.tif";
26
27 // The raster have 10 bands that we will assign to 2001 ... 2010.
28 std::vector<int> times(10);
29 std::iota(times.begin(), times.end(), 2001);
30
31 // Landscape construction
32 using landscape_type = geo::raster<>;
33 auto land = geo::raster<>::from_file(file, times);
34
35 // Graph construction with vertex and edge info
37
38 std::cout << "Graph has " << graph.num_vertices() << " vertices, " << graph.num_edges() << " edges." << std::endl;
39
40 for( auto const& e : graph.edges() ){
41 std::cout << graph.source(e) << " <-> " << graph.target(e) << " : " << graph[e].distance << std::endl;
42 }
43
44}
Individuals can not escape the landscape's borders.
Definition bound_policy.hpp:20
Discrete spatio-temporal variations of an environmental variable.
Definition raster.hpp:38
Geospatial data formatting and processing.
Definition geography.hpp:17
auto from_grid(SpatialGrid const &grid, VertexProperty const &v, EdgeProperty const &e, Vicinity const &vicinity, Directionality dir, Policy const &bounding_policy)
Spatial graph construction method.
Definition from_grid.hpp:36
boost::undirectedS isotropy
Property of a process independent of the direction of movement.
Definition directionality.hpp:18
Definition geography_graph_7.cpp:13
Definition geography_graph_7.cpp:6
Definition vicinity.hpp:53

Output

1Graph has 9 vertices, 36 edges.
21 <-> 0 : 0 m
32 <-> 0 : 0 m
42 <-> 1 : 0 m
53 <-> 0 : 0 m
63 <-> 1 : 0 m
73 <-> 2 : 0 m
84 <-> 0 : 0 m
94 <-> 1 : 0 m
104 <-> 2 : 0 m
114 <-> 3 : 0 m
125 <-> 0 : 0 m
135 <-> 1 : 0 m
145 <-> 2 : 0 m
155 <-> 3 : 0 m
165 <-> 4 : 0 m
176 <-> 0 : 0 m
186 <-> 1 : 0 m
196 <-> 2 : 0 m
206 <-> 3 : 0 m
216 <-> 4 : 0 m
226 <-> 5 : 0 m
237 <-> 0 : 0 m
247 <-> 1 : 0 m
257 <-> 2 : 0 m
267 <-> 3 : 0 m
277 <-> 4 : 0 m
287 <-> 5 : 0 m
297 <-> 6 : 0 m
308 <-> 0 : 0 m
318 <-> 1 : 0 m
328 <-> 2 : 0 m
338 <-> 3 : 0 m
348 <-> 4 : 0 m
358 <-> 5 : 0 m
368 <-> 6 : 0 m
378 <-> 7 : 0 m