Skip to contents

Shift and rotate a geometry object. To help translate plot layout information into spatial coordinates.

Usage

transform_geometry(
  sfgeom,
  counterclockwise_angle_deg,
  origin,
  outcrs = "ESRI:102008"
)

Arguments

sfgeom

A feature collection of class sfc

counterclockwise_angle_deg

The rotation angle counterclockwise from true north (negative bearing).

origin

A 1-row matrix of X followed by Y coordinates of the origin (usually lon, lat projected to meters).

Value

A geometry object of the same type

Examples

# coordinates derived from plot metadata and an origin on the bottom-left of the map.
cornerpoints <- rbind(c(0,0),
                     c(0,10),
                     c(10,10),
                     c(10,0),
                     c(0,0))
mygeom <- sf::st_sfc(sf::st_polygon(list(cornerpoints)))
# points used to estimate rotation:
# Eyeballed from Googled maps imagery.
topleft <- c("lon" = -80.410466 , "lat" =  43.641394)
bottomleft <- c("lon"= -80.411367,"lat" = 43.640741)
myorigin <- sf::st_coordinates(
sf::st_transform(
   sf::st_sfc(sf::st_point(c(bottomleft['lon'], bottomleft['lat'])), crs = 4326),
   "ESRI:102008"))
## calculate bearing (degrees clockwise from true north)
mybearing <- bearing(lon1 = bottomleft['lon'],
                    lat1 = bottomleft['lat'],
                    lon2 = topleft['lon'],
                    lat2 = topleft['lat'])

newpolygon <- transform_geometry(mygeom, -mybearing,myorigin)