SimpleSDMLayers
Base.stride — Method
Base.stride(layer::SDMLayer)Return the stride for a single dimension, where 1 is northing and 2 is easting
Base.stride — Method
Base.stride(layer::SDMLayer)Return the stride (the length of half a cell) for a layer. The result is given as northing, easting stride.
SimpleSDMLayers._centroid_rotation — Method
_centroid_rotation(xy, degrees)Rotates a group of points around their centroid by an angle given in degrees
SimpleSDMLayers._parse_projection_from_string — Method
_parse_projection_from_string(p::String)This function will return the ArchGDAL SRS from a string. The three options are an EPSG (or ESRI) string, a PROJ4 string, or the WKT itself.
SimpleSDMLayers._read_geotiff — Method
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.
SimpleSDMLayers._rotation_x — Method
_rotation_x(x, y, z, θ)Rotation along the axis ending at the Bay of Guinea
SimpleSDMLayers._rotation_y — Method
_rotation_y(x, y, z, θ)Rotation along the axis ending at the Bay of Bengal
SimpleSDMLayers._rotation_z — Method
_rotation_z(x, y, z, θ)Rotation around the polar axis – latitude is constant but longitude changes
SimpleSDMLayers._spherical_rotation — Function
_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
SimpleSDMLayers._write_geotiff — Method
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.
SimpleSDMLayers.burnin! — Method
burnin!(L::SDMLayer{T}, v::Vector{T})Replaces the values of L by the values in the vector v.
SimpleSDMLayers.burnin — Method
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.
SimpleSDMLayers.cellarea — Method
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.
SimpleSDMLayers.coarsen — Function
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).
SimpleSDMLayers.findrotation — Method
findrotation(L, P; rotations=(-180., 180), maxiter=50)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.
The output of this method is either nothing (no valid rotation found), or a rotator function (see the documentation for rotator).
Note that it is almost always a valid strategy to look for shifts and rotations on a raster at a coarser resolution.
SimpleSDMLayers.interpolate! — Method
interpolate!(destination::SDMLayer, source::SDMLayer)Interpolates the data from the source layer into the destination layer. This is useful when the two layers have different resolutions, or different projections.
SimpleSDMLayers.interpolate — Method
interpolate(layer::SDMLayer, destination::SDMLayer)Interpolates a layer target so that it uses the same grid, crs, etc as destination.
SimpleSDMLayers.interpolate — Method
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.
SimpleSDMLayers.localrotation — Method
localrotation(angle)Returns a function to create a rotation of coordinates around their centroids.
SimpleSDMLayers.lonlat — Method
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!.
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.
SimpleSDMLayers.mask — Method
mask(layer::SDMLayer, template::SDMLayer)Returns a copy of the first layer masked according to the second layer. See also mask!.
SimpleSDMLayers.mosaic — Method
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.
SimpleSDMLayers.nodata! — Method
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.
SimpleSDMLayers.nodata! — Method
nodata!(layer::SDMLayer{T}, f)Removes the data matching a function
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.
SimpleSDMLayers.nodata — Method
nodata(layer::SDMLayer, args...)Makes a copy and calls nodata! on it
SimpleSDMLayers.projection — Method
projection(layer::SDMLayer)Returns the ArchGDAL SRS for a given layer.
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.
SimpleSDMLayers.quantiletransfer — Method
quantiletransfer(target, reference)Non-mutating version of quantiletransfer!
SimpleSDMLayers.reclassify — Method
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 mask all other cells. You can use multiple rules, in which case they are applied sequentially (a later rule can overwrite an earlier one).
SimpleSDMLayers.reconcile! — Method
reconcile!(L::Vector{<:SDMLayer})Takes a stack of layers, and ensure that they have the same x and y values. This should be used as a last resort when some data providers have layers that don't fully align after clipping.
SimpleSDMLayers.reconcile — Method
reconcile(L::Vector{<:SDMLayer})Non-mutating version of reconcile!.
SimpleSDMLayers.rotator — Method
rotator(longitude::T, latitude::T, rotation::T) where T <: NumberReturns 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 centroidAll 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.
SimpleSDMLayers.shiftandrotate! — Method
shiftandrotate!(L::SDMLayer, P::SDMLayer, rotator)Returns the output of shifting and rotating the layer L on the layer P, according to a rotator function, obtained with for example findrotation. This function overwrites L.
SimpleSDMLayers.shiftandrotate! — Method
shiftandrotate!(L::Vector{<:SDMLayer}, P::Vector{<:SDMLayer}, rotator)SimpleSDMLayers.shiftandrotate — Method
shiftandrotate(L::SDMLayer, P::SDMLayer, rotator)Returns the output of shifting and rotating the layer L on the layer P, according to a rotator function, obtained with for example findrotation. This function generates a copy of L.
SimpleSDMLayers.shiftlatitudes — Method
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.
SimpleSDMLayers.shiftlongitudes — Method
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.
SimpleSDMLayers.slidingwindow! — Method
slidingwindow!(destination::SDMLayer, f::Function, layer::SDMLayer; radius::AbstractFloat=100.0)Performs a sliding window analysis in which all cells in the destination layer receive the output of applying the function f to all cells in a radius of radius kilometer on the layer layer.
The f function must take a vector of value as an input, and must return a single value as an output. The destination layer must have the correct type re. what is returned by f.
If the centervalue keyword is set to true (default is false), then the f function must take (r, v) an input, where r is the value for the reference cell, and v is the vector of values for all other cells in the window. This is useful to measure, for example, z-scores within a known distance radius: (r,v) -> (r-mean(v))/std(v).
Internally, this function uses threads to speed up calculation quite a bit.
SimpleSDMLayers.slidingwindow — Method
slidingwindow(f::Function, layer::SDMLayer; kwargs...)Performs a sliding window analysis in which all cells in the returned layer receive the output of applying the function f to all cells in a radius of radius kilometer on the layer layer.
The f function must take a vector of values as an input, and must return a single value as an output. The returned layer will have the type returned by f.
If the centervalue keyword is set to true (default is false), then the f function must take (r, v) an input, where r is the value for the reference cell, and v is the vector of values for all other cells in the window. This is useful to measure, for example, z-scores within a known distance radius: (r,v) -> (r-mean(v))/std(v).
Internally, this function uses threads to speed up calculation quite a bit, and uses the slidingwindow! function.
SimpleSDMLayers.tiles — Function
tiles(layer::SDMLayer, size::Tuple{Int64,Int64})SimpleSDMLayers.IncompatibleProjectionError — Type
IncompatibleProjectionErrorAn error returned when two layers do not have compatible projections. Compatibility is evaluated by converting the SRS of layers to their proj4 string and then testing for string equality.
SimpleSDMLayers.SDMLayer — Type
SDMLayer{T}Defines a layer of geospatial information.
The type has two data fields:
- grid: a
Matrixof typeT - indices: a
BitMatrixto 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
Stringrepresentation of the CRS which can be handled byProj.jl- the default is EPSG:4326
Note that we recommend that the SRS be represented as WKT, then as the "EPSG:xxx" format, and then as a a PROJ4 string, by order of decreasing preference. An ArchGDAL representation is always accessible through the projection method. Note that the functions will, internally, convert the projection to different formats in order to achieve specific tasks.