move_and_resize: Move and Resize an sf Object

View source: R/move_and_resize.R

move_and_resizeR Documentation

Move and Resize an sf Object

Description

Move and resize a simple feature collection of polygons, multipolygons or points.

Usage

move_and_resize(x, mask = NULL, xy, prj, k = 1)

Arguments

x

an sf POINT, POLYON or MULTIPOLYGON object to resize and move.

mask

an sf or sfc POLYGON or MULTIPOLYGON object used to select the area to move an resize.

xy

coordinates used to move the inset, bottomleft corner of the inset.

prj

CRS string of the output projection of the inset.

k

factor used to resize.

Value

An sf object is returned.

Examples

library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
nc <- st_transform(nc, 32119)

plot(st_geometry(nc))
bb <- st_bbox(nc[nc$CNTY_ID == '2030',])
mask <- create_mask(bb = bb, add = TRUE)
inset <- move_and_resize(nc, mask, xy = c(190000, 1000), k = 3)
plot(st_geometry(inset), add = TRUE)

plot(st_geometry(nc))
mask <- st_buffer(st_centroid(st_geometry(nc[nc$CNTY_ID == 2026,])),
                  dist = 30000)
plot(st_geometry(mask), border = "red", lwd = 2, add = TRUE)
inset <- move_and_resize(nc, mask, xy = c(270000, 5000), k = 2.5)
plot(st_geometry(inset), add = TRUE)

riatelab/mapinsetr documentation built on June 15, 2025, 4:29 a.m.