Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
Writing spatial variables to rasters

Once users have simulated various continuous geospatial values such as friction coefficients or population sizes across a landscape, they will often desire a visual confirmation of these values. One approach is to export these quantities as a multiband raster file and utilize different software, such as Quetzal-CRUMBS or the raster package in R, for visualization.

To export a specific quantity, it is necessary to create a callable function that can be invoked at each location within the raster model during an arbitrary time interval. Each point of the time interval parameter will become a new band in the new raster file.

Input

1#include "quetzal/geography.hpp"
2#include <cassert>
3#include <filesystem>
4#include <iostream>
5
6using namespace quetzal;
7
8int main()
9{
10 using time_type = int;
11 using raster_type = geography::raster<time_type>;
12 using location_descriptor = typename raster_type::location_descriptor;
13
14 // The raster has 10 bands that we will assign to 2001 ... 2011.
15 std::vector<time_type> times(10);
16 std::iota(times.begin(), times.end(), 2001);
17
18 auto input_file = std::filesystem::current_path() / "data/bio1.tif";
19
20 // Read the raster
21 auto bio1 = raster_type::from_file(input_file, times);
22
23 // Define the quantity we want to print (it could be any function of space and time)
24 auto transform = [](location_descriptor x, time_type t) { return std::optional(2 * x + t); };
25
26 // Output file name
27 auto output_file = std::filesystem::current_path() / "my_quantity.tif";
28
29 // Write only between these times
30 bio1.to_geotiff(transform, 2001, 2005, output_file);
31
32 std::cout << (std::filesystem::exists("my_quantity.tif") ? "success" : "error") << std::endl;
33
34 // Clean up
35 std::filesystem::remove_all(output_file);
36}
Discrete spatio-temporal variations of an environmental variable.
Definition raster.hpp:38
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21

Output

1success