Skip to content

Generating neutral landscapes

The purpose of this vignette is to demonstrate how we can use the NeutralLandscapes package to generate random spatial structures.

julia
using SpeciesDistributionToolkit
using CairoMakie

This functionality is supported through an extension, which is only active when the NeutralLandscapes package is loaded.

julia
using NeutralLandscapes 

Generating a neutral layer

This is simply achieved through an overload of the SDMLayer constructor, taking a neutral landscape maker, and a size:

julia
L = SDMLayer(DiamondSquare(), (90, 180))
🗺️  A 90 × 180 layer with 16200 Float64 cells
   Spatial Reference System: +proj=longlat +datum=WGS84 +no_defs

Code for the figure
julia
heatmap(L)

Generating data from an existing layer

If we have a layer already, it can be used in place of the size argument, in which case the mask of the layer is also preserved. This is useful to rapidly fill layers that have the same structure with random data.

We will illustrate this by only reading it a small part of an existing layer, a practice that is fully covered later on in this manual.

julia
T = SDMLayer(RasterData(CHELSA1, BioClim); left=4., right=9., bottom=4., top=9.)
L = SDMLayer(DiamondSquare(0.1), T)
🗺️  A 601 × 601 layer with 296179 Float64 cells
   Spatial Reference System: +proj=longlat +datum=WGS84 +no_defs

Code for the figure
julia
f = Figure()
ax = Axis(f[1,1]; aspect=DataAspect())
heatmap!(ax, L)

Additional arguments

Finally, the SDMLayer constructor, when used this way, accepts keyword arguments like the crs of the layer, as well as its x and y fields. This is important if you want to ensure that the generated data can be overlaid on an actual layer with coordinates and projections.

Note that by default, the returned layer will be entirely filled. You can mask parts of it using nodata, or by masking it with a layer containing actual data.

SimpleSDMLayers.nodata Function
julia
nodata(layer::SDMLayer, args...)

Makes a copy and calls nodata! on it

source
SimpleSDMLayers.nodata! Function
julia
nodata!(layer::SDMLayer{T}, nodata::T) where {T}

Changes the value of the layer representing no data. This modifies the layer passed as its first argument.

source
julia
nodata!(layer::SDMLayer{T}, f)

Removes the data matching a function

source
julia
nodata!(layer::SDMLayer, v)

Turns off all cells containing the value v. This is an overload only applied when v is not of the correct type for layer.

source
SimpleSDMLayers.mask! Function
julia
mask!(layer::SDMLayer, template::SDMLayer)

Updates the positions in the first layer to be those that have a value in the second layer.

source
julia
SimpleSDMLayers.mask!(layer::SDMLayer, poly::T) where T<:Union{Polygon,MultiPolygon}

Turns off all the cells outside the polygon (or within holes in the polygon). This modifies the object.

source