Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
Writing spatial samples to shapefile

Users sometimes simulate quantities that do not always correspond to continuous spatial values. Instead, these quantities can be discrete and result from a sampling process across the landscape. In such cases, users often want to visually verify the sampling scheme.

One way to achieve this is by exporting the samples as a shapefile and employing various software tools like Quetzal-CRUMBS or the raster package in R to visualize them.

Input

1#include "quetzal/geography.hpp"
2#include <cassert>
3#include <filesystem>
4#include <iostream>
5#include <random>
6
7using namespace quetzal;
8
9int main()
10{
11 using time_type = int;
12 using raster_type = geography::raster<time_type>;
13 using latlon = typename raster_type::latlon;
14
15 // The raster has 10 bands that we will assign to 2001 ... 2011.
16 std::vector<time_type> times(10);
17 std::iota(times.begin(), times.end(), 2001);
18
19 auto input_file = std::filesystem::current_path() / "data/bio1.tif";
20 auto output_dir = std::filesystem::current_path() / "my_sample";
21
22 // Read the raster
23 auto bio1 = raster_type::from_file(input_file, times);
24
25 // Sampling points:
26 auto p1 = latlon(48., 0.);
27 auto p2 = latlon(51, 3.5);
28 auto p3 = latlon(38.0, 9.0);
29
30 bio1.to_shapefile({p1, p2, p3}, output_dir);
31 std::cout << (std::filesystem::is_directory(output_dir) ? "success" : "error") << std::endl;
32
33 // Clean up
34 std::filesystem::remove_all(output_dir);
35}
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