transform_coordinates: Function to convert coordinates within a data frame.

View source: R/transform_coordinates.R

transform_coordinatesR Documentation

Function to convert coordinates within a data frame.

Description

transform_coordinates converts coordinate pairs from one projection system to another. transform_coordinates is useful when tabular data are supplied and the coordinate system is different that what is desired.

Usage

transform_coordinates(
  df,
  latitude = "latitude",
  longitude = "longitude",
  from,
  to
)

Arguments

df

Data frame with coordinates to be transformed.

latitude

Name of latitude/y variable.

longitude

Name of longitude/x variable.

from

A proj4 string which represents what coordinate system the data frame's coordinates are in.

to

A proj4 string which represents what coordinate system the converted coordinates will be converted to.

Details

transform_coordinates works by coercing the input data frame to a spatial object, applies spTransform to convert the coordinates, converts the spatial object back to a data frame and then returns the data frame with the transformed coordinates. The transformed coordinates can be optionally renamed and reordered.

transform_coordinates requires a CRS projection string for the from and to arguments. to by default is set as WGS 84/EPSG:4326 (+proj=longlat +datum=WGS84).

Value

Tibble.

Author(s)

Stuart K. Grange

See Also

sp_transform, sp_from_data_frame

Examples


## Not run: 

# Convert British National Grid/Ordnance Survey National Grid/OSGB36/EPSG:7405
# to latitude and longitude (WGS 84/EPSG:4326)

data_oxford_transform <- transform_coordinates(
  data_oxford, 
  latitude = "latitude", 
  longitude = "longitude", 
  from = projection_bng()
)
  

## End(Not run)


skgrange/gissr documentation built on June 20, 2024, 12:02 a.m.