View source: R/vis-make_transition.r
make_transition | R Documentation |
Create transition layer for interpolate_path()
spatial object.
make_transition(poly, res, receiver_points = NULL, epsg = 3175, buffer = NULL)
poly |
A spatial polygon object of class SpatialPolygonsDataFrame or a sf::sf() object with a geometry column of polygon and/or multipolygon objects. |
res |
two element vector that specifies the x and y dimension of output
raster cells. Units are same as |
receiver_points |
Object containing coordinates of receiver locations.
Must be of class |
epsg |
coordinate reference code that describes projection used for buffers. Defaults to NAD83/Great Lakes and St. Lawrence Albers. |
buffer |
Buffer, in same units as |
make_transition
uses jarasterize()
to convert a polygon
shapefile into a raster layer and geo-corrected transition layer
interpolate_path()
. Raster cell values on land equal 0, cells in water
equal 1. Output is a two-object list containing the raster layer and
transition layer.
If receiver_points
is provided, any receiver not in water is
buffered by the distance from the receiver to the nearest water. This
allows all receivers to be coded as in water if the receiver is on land.
Poly object is transformed into planer map projection specified by
epsg argument for calculation of transition object if receiver_points is
provided. Output is projected to crs of input poly
.
output transition layer is corrected for projection distortions
using gdistance::geoCorrection
. Adjacent cells are connected by 16
directions and transition function returns 0 (land) for movements between
land and water and >0 for all over-water movements.
Note that this function underwent breaking changes between 0.7.3 and
0.8.0 (uses jasterize
instead of gdalUtilities::gdal_rasterize
see
NEWS).
A list with two elements:
a geo-corrected transition raster layer where land = 0
and water = 1
(see gdistance::Transition
)
rasterized input layer of class raster
Todd Hayden, Chris Holbrook
# Example 1 - read from sf polygon object
# use example polygon for Great lakes
# calculate resolution in degrees (from meters)
# note this applies to cell at center, cell sizes will vary
res <- scale_meters_to_degrees(5000, sf = great_lakes_polygon)
# make_transition layer
tst <- make_transition(great_lakes_polygon, res = res)
## Not run:
# plot raster layer (notice water = 1, land = 0)
raster::plot(tst$rast)
# compare to polygon
plot(sf::st_geometry(great_lakes_polygon), add = TRUE)
## End(Not run)
# Example 2 - add 1 km buffer (same resolution)
# make_transition layer
tst2 <- make_transition(great_lakes_polygon,
res = res,
buffer = 3000
)
## Not run:
# plot raster layer (notice water = 1, land = 0)
raster::plot(tst2$rast)
# compare to polygon
plot(sf::st_geometry(great_lakes_polygon), add = TRUE)
## End(Not run)
# Example 3 - read from ESRI Shapefile and include receiver file
# to account for any receivers outside of great lakes polygon
# path to polygon shapefile
poly <- system.file("extdata", "shoreline.zip", package = "glatos")
poly <- sf::st_read(paste0("/vsizip/", poly))
# read in glatos receivers object
rec_file <- system.file("extdata", "sample_receivers.csv",
package = "glatos"
)
recs <- read_glatos_receivers(rec_file)
# change a coordinate to on-land to show impact...
recs[1, "deploy_lat"] <- recs[1, "deploy_lat"] + 4
# make_transition layer (roughly 500 m res)
tst <- make_transition(poly, res = c(0.065, 0.046), receiver_points = recs)
## Not run:
# plot raster layer
# notice the huge circle rasterized as "water" north of Lake Superior.
# This occurred because we had a "receiver" deployed at that locations
raster::plot(tst$rast)
points(recs$deploy_long, recs$deploy_lat, col = "red", pch = 20)
# plot transition layer
raster::plot(raster::raster(tst$transition))
## End(Not run)
# Example 4- transition layer of Lake Huron only with receivers
# transform to great lakes projection
poly <- sf::st_transform(great_lakes_polygon, crs = 3175)
# set attribute-geometry relationship to constant.
# this avoids error when cropping
sf::st_agr(poly) <- "constant"
# crop Great lakes polygon file
poly <- sf::st_crop(
x = poly, xmin = 829242.55, ymin = 698928.27,
xmax = 1270000.97, ymax = 1097196.15
)
# read in glatos receivers object
rec_file <- system.file("extdata", "sample_receivers.csv",
package = "glatos"
)
recs <- read_glatos_receivers(rec_file)
# extract receivers in "HECWL" project
# all receiver stations except one is in Lake Huron
recs <- recs[recs$glatos_project == "HECWL", ]
# remove two stations not in Lake Huron
recs <- recs[!recs$glatos_array %in% c("MAU", "LVD"), ]
# convert recs to simple feature object (sf)
recs <- sf::st_as_sf(recs,
coords = c("deploy_long", "deploy_lat"),
crs = 4326
)
# transform receivers to same projection as great lakes polygon
recs <- sf::st_transform(recs, crs = 3175)
## Not run:
# check by plotting
plot(sf::st_geometry(poly), col = NA)
plot(sf::st_geometry(recs), col = "red", add = TRUE)
## End(Not run)
# create slightly higher resolution transition layer
# (note that res in in meters here because crs is 3175)
tst1 <- make_transition(poly, res = 5000, receiver_points = recs)
## Not run:
# plot raster layer
raster::plot(tst1$rast)
plot(sf::st_geometry(recs),
add = TRUE, col = "red", pch = 20
)
# plot transition layer
raster::plot(raster::raster(tst1$transition))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.