SimpleSDMLayers

SimpleSDMLayers._read_geotiffMethod
geotiff(file; bandnumber::Integer=1, left=nothing, right=nothing, bottom=nothing, top=nothing, driver)

The geotiff function reads a geotiff file, and returns it as a matrix of the correct type. The optional arguments left, right, bottom, and left are defining the bounding box to read from the file. This is particularly useful if you want to get a small subset from large files.

source
SimpleSDMLayers._spherical_rotationFunction
_spherical_rotation(xy, degrees, axis=1)

Rotation of the Earth alongside three axes, by a given angle in degrees.

Axis 1 - x rotation - rotates around the axis ending in the Bay of Guinea

Axis 2 - y rotation - rotates around the axis ending in the Gulf of Bengal

Axis 3 - z rotation - rotates around the axis ending at the North Pole

source
SimpleSDMLayers._write_geotiffMethod
geotiff(file::AbstractString, layers::Vector{SDMLayer{T}}; nodata::T=convert(T, -9999)) where {T <: Number}

Stores a series of layers in a file, where every layer in a band. See geotiff for other options.

source
SimpleSDMLayers.burninMethod
burnin(L::SDMLayer, v::Vector{T}) where {T}

Writes the value of v in a layer similar to L, and returns it. It is ASSUMED (but essentially impossible to check) that the values of v are presented in the correct order. This uses burnin! internally.

source
SimpleSDMLayers.cellareaMethod
cellarea(layer::T; R = 6371.0)

Returns the area of each cell in km², assuming a radius of the Earth or R (in km). This is only returned for layers in WGS84, which can be forced with interpolate.

source
SimpleSDMLayers.coarsenFunction
coarsen(f, L::SDMLayer, mask=(2, 2))

Coarsens a layer by collecting a sub-grid of size mask, and applying the function f to all non-empty cells within this mask. The core constraint is that f must take a vector and return a single element (and the size of the mask must be compatible with the size of the layer).

source
SimpleSDMLayers.findrotationMethod
findrotation(L, P; longitudes=-10:0.1:10, latitudes=-10:0.1:10, rotations=-10:0.1:10, maxiter=10_000)

Find a possible rotation for the shiftandrotate function, by attempting to move a target layer L until all of the shifted and rotated coordinates are valid coordinates in the layer P. The range of angles to explore is given as keywords, and the function accepts a maxiter argument after which, if no rotation is found, it returns nothing.

Note that it is almost always a valid strategy to look for shifts and rotations on a raster at a coarser resolution.

source
SimpleSDMLayers.interpolateMethod
interpolate(layer::SDMLayer, destination::SDMLayer)

Interpolates a layer target so that it uses the same grid, crs, etc as destination.

source
SimpleSDMLayers.interpolateMethod
interpolate(layer::SDMLayer; dest="+proj=natearth2", newsize=nothing)

Returns an interpolated version of the later under the new destination CRS (natearth2 by default), and with optionally a new size of newsize.

source
SimpleSDMLayers.lonlatMethod
lonlat(L::SDMLayer)

Returns a vector of longitudes and latitudes for a layer. This will handle the CRS of the layer correctly. Note that only the positions that are valued (i.e. using keys) will be returned. The values are given in an order suitable for use in burnin!.

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

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

source
SimpleSDMLayers.maskMethod
mask(layer::SDMLayer, template::SDMLayer)

Returns a copy of the first layer masked according to the second layer. See also mask!.

source
SimpleSDMLayers.mosaicMethod
mosaic(f, stack::Vector{<:SDMLayer})

Returns a layer that is the application of f to the values at each cell in the array of layers given as the second argument.

source
SimpleSDMLayers.nodata!Method
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
SimpleSDMLayers.quantiletransfer!Method
quantiletransfer!(target::SDMLayer{T}, reference::SDMLayer) where {T <: Real}

Replaces the values in the target layer so that they follow the distribution of the values in the reference layer. This works by (i) identifying the quantile of each cell in the target layer, then (ii) replacing this with the value for the same quantile in the reference layer.

source
SimpleSDMLayers.reclassifyMethod
reclassify(L::SDMLayer, rules::Pair...)

Returns a layer where the cells are updated as a function of rules, given as (function) => value, where the function must return a Bool value. For example, reclassify(layer, (x -> abs(x)<=1)=>true) will set a value of true to all cells with values in -1;1, and maks all other cells. You can use multiple rules, in which case they are applied sequentially (a later rule can overwrite an earlier one).

source
SimpleSDMLayers.shiftandrotateMethod
shiftandrotate(longitude::T, latitude::T, rotation::T) where T <: Number

Returns a function to transform a vector of lon,lat points according to three operations done in order:

- a shift of the longitudes
- a shift of the latitudes (the order of these two operations is actually irrelevant)
- a local rotation around the centroid

All the angles are given in degrees. The output of this function is a function that takes a vector of coordinates to transform. The transformations do account for the curvature of the Earth. For this reason, rotations and changes in the latitudes will deform the points, but shift in the longitudes will not.

source
SimpleSDMLayers.shiftlatitudesMethod
shiftlatitudes(angle)

Returns a function to move coordinates up or down in latitudes by a given angle in degree. Note that this accounts for the curvature of the Earth, and therefore requires three distinct operations. First, the points are moved so that their centroid has a longitude of 0; then, the points are shifted in latitute by performing a rotation along the pitch axis by the desired angle; finally, the centroid of the points is brought back to its original longitude. For this reason, and because the rotation along the pitch axis accounts for the curvature of the Earth, this function will deform the shape, and specifically change the range of longitudes covered.

source
SimpleSDMLayers.shiftlongitudesMethod
shiftlongitudes(angle)

Shifts the longitudes of a group of points by performing a rotation alonside the yaw axis (going through the Nort pole). This preserves the latitudes of all points exactly and does not deform the shape.

source
SimpleSDMLayers.SDMLayerType
SDMLayer{T}

Defines a layer of geospatial information.

The type has two data fields:

  • grid: a Matrix of type T
  • indices: a BitMatrix to see which positions are valued

Each row in the grid field represents a slice of the raster of equal northing, i.e. the information is laid out in the matrix as it would be represented on a map once displayed. Similarly, columns have the same easting.

The geospatial information is represented by three positional fields:

  • x and y: two tuples, indicating the coordinates of the corners alongside the x and y dimensions (e.g. easting/northing) - the default values are (-180., 180.) and (-90., 90.), which represents the entire surface of the globe in WGS84
  • crs: any String representation of the CRS which can be handled by Proj.jl - the default is "+proj=longlat +datum=WGS84 +no_defs", which represents a latitude/longitude coordinate system
source