Nudge SpatialPolygons

nudge_sp(sp = NULL, sp_nudge = NULL, ...)

Arguments

sp

sp::SpatialPolygons object

sp_nudge

list whose names are found in names(sp), and whose values are x and y coordinates to be moved.

...

additional arguments are ignored.

rotate_degrees

numeric value in degrees (0, 360) to rotate the sp object and all contained polygons. (Not yet implemented.)

Value

object sp::SpatialPolygons.

Details

This helper function is intended to take sp::SpatialPolygons and "nudge" (move by adding a scalar value to each coordinate) only a subset of polygons identified by name.

It differs from rescale_sp() because rescale_sp() manipulates all contained polygons together.

Examples

sp <- sp_ellipses(c(3, 2), c(2, 3),
   xradius=c(1, 4),
   yradius=c(5, 2))
opar <- par("mfrow"=c(1,2));
on.exit(par(opar));
plot(sp, col=c("#FF000077", "#FFDD0077"),
   xlim=c(-2, 9));
axis(1, las=2); axis(2, las=2);
points(x=c(3, 2), y=c(2, 3), pch=c("1", "2"), add=TRUE);


sp2 <- nudge_sp(sp,
   sp_nudge=list("2"=c(3, -2))
)
plot(sp2, col=c("#FF000077", "#FFDD0077"),
   xlim=c(-2, 9));
plot(sp[2], border="blue", lty="dotted", add=TRUE);
axis(1, las=2); axis(2, las=2);
arrows(x0=2, x1=5, y0=3, y1=1)
points(x=c(3, 5), y=c(2, 1), pch=c("1", "2"), add=TRUE);