Reprojects an sf spatial object to a new coordinate reference system.

spReprojectVector(
  layer,
  dsn = NULL,
  crs.new,
  exportsp = FALSE,
  savedata_opts = NULL
)

Arguments

layer

sf class R object or String. The spatial layer must have a defined projection (test using sf::st_crs(layer)).

dsn

String. Data source name (dsn; i.e., folder or database name) of splayer. The dsn varies by driver. See gdal OGR vector formats (https://www.gdal.org/ogr_formats.html). Optional if layer is an R object.

crs.new

EPSG Integer or PROJ.4 String. New EPSG Geodetic Parameter Dataset definition or gdal PROJ.4 string identifying the new coordinate system (e.g., "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0").

exportsp

Logical. If TRUE, the spatial reprojected object is exported to outfolder (see spExportSpatial for details).

savedata_opts

List. See help(savedata_options()) for a list of options for saving data. If out_layer = NULL, default = 'layerprj'.

Value

layerprj

sf object. Reprojected spatial layer.

If exportsp = TRUE, a spatial layer is written to outfolder (See note).

Note

Coordinate Reference Systems (CRS)
An ellipse is an estimated model describing the basic shape of the Earth and is the basis for all coordinate systems. There are many ellipsoids designed for local (e.g., NAD27) or global (e.g., WGS84, GRS80) use. The datum defines the reference position of the coordinate axes associated with a specific ellipsoid. Specifying the datum also defines the ellipsoid, whereas specifying the ellipsoid does not provide information of the datum.

WGS84 vs NAD83 WGS84 and NAD83 datums are often used interchangeably, and use very similar ellipsoids (WGS84 and GRS80, respectively), but have different reference points. Slight tectonic shifts through time have caused increased divergence between the two, with NAD83 datum intended to track movements more consistently.

Common Datums and associated spheroid (ellipsoid):
NAD27 - North American Datum of 1927 (Clarke 1866 spheroid)
NAD83 - North American Datum of 1983 (GRS 1980 spheroid)
WGS84 - World Geodetic System of 1984 (WGS 1984 spheroid)

From R, use projInfo for list of different projections and datums.
> projInfo(type="proj")
> projInfo(type="datum")

Common EPSG Geodetic codes in U.S.
EPSG:4326 - Longitude/Latitude (WGS84) - Common for global displays (used by Google Earth)
EPSG:4269 - Longitude/Latitude (NAD83) - Common by U.S. Federal Agencies

The sf::st_transform (GDAL) method is used for map projection conversion and datum transformation using PROJ.4 arguments. Datum transformation only occurs if the +datum tag is present in the both the from and to PROJ.4 strings. The +towgs84 tag is used when no datum transformation is needed. PROJ.4 transformations assume NAD83 and WGS84 are identical unless other transformation parameters are specified. Be aware, providing inaccurate or incomplete CRS information may lead to erroneous data shifts when reprojecting. See spTransform help documentation for more details.

ESRI Shapefile Driver
If exportsp=TRUE:
The st_write (sf) function is called. If out_fmt="shp", the ESRI Shapefile driver truncates variable names to 10 characters or less. Variable names are changed before export using an internal function (trunc10shp). If sf object has more than 1 record, it will be returned but not exported.

Author

Tracey S. Frescino

Examples

# \donttest{
# Set up `SpatialPoints` object
WYspplt <- spMakeSpatialPoints(xyplt = WYplt, 
                               xy.uniqueid = "CN", 
                               xvar = "LON_PUBLIC", 
                               yvar = "LAT_PUBLIC", 
                               xy.crs = 4326)
# Check CRS
sf::st_crs(WYspplt)
#> Coordinate Reference System:
#>   User input: EPSG:4326 
#>   wkt:
#> GEOGCRS["WGS 84",
#>     ENSEMBLE["World Geodetic System 1984 ensemble",
#>         MEMBER["World Geodetic System 1984 (Transit)"],
#>         MEMBER["World Geodetic System 1984 (G730)"],
#>         MEMBER["World Geodetic System 1984 (G873)"],
#>         MEMBER["World Geodetic System 1984 (G1150)"],
#>         MEMBER["World Geodetic System 1984 (G1674)"],
#>         MEMBER["World Geodetic System 1984 (G1762)"],
#>         MEMBER["World Geodetic System 1984 (G2139)"],
#>         ELLIPSOID["WGS 84",6378137,298.257223563,
#>             LENGTHUNIT["metre",1]],
#>         ENSEMBLEACCURACY[2.0]],
#>     PRIMEM["Greenwich",0,
#>         ANGLEUNIT["degree",0.0174532925199433]],
#>     CS[ellipsoidal,2],
#>         AXIS["geodetic latitude (Lat)",north,
#>             ORDER[1],
#>             ANGLEUNIT["degree",0.0174532925199433]],
#>         AXIS["geodetic longitude (Lon)",east,
#>             ORDER[2],
#>             ANGLEUNIT["degree",0.0174532925199433]],
#>     USAGE[
#>         SCOPE["Horizontal component of 3D system."],
#>         AREA["World."],
#>         BBOX[-90,-180,90,180]],
#>     ID["EPSG",4326]]

# Set up projection
prj <- "+proj=utm +zone=12 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"

# Use `spReprojectVector` to reproject the vector
WYspplt.utm12 <- spReprojectVector(layer = WYspplt, 
                                   crs.new = prj)
# Check results
sf::st_crs(WYspplt.utm12)
#> Coordinate Reference System:
#>   User input: +proj=utm +zone=12 +ellps=GRS80 +datum=NAD83 +units=m +no_defs 
#>   wkt:
#> PROJCRS["unknown",
#>     BASEGEOGCRS["unknown",
#>         DATUM["North American Datum 1983",
#>             ELLIPSOID["GRS 1980",6378137,298.257222101,
#>                 LENGTHUNIT["metre",1]],
#>             ID["EPSG",6269]],
#>         PRIMEM["Greenwich",0,
#>             ANGLEUNIT["degree",0.0174532925199433],
#>             ID["EPSG",8901]]],
#>     CONVERSION["UTM zone 12N",
#>         METHOD["Transverse Mercator",
#>             ID["EPSG",9807]],
#>         PARAMETER["Latitude of natural origin",0,
#>             ANGLEUNIT["degree",0.0174532925199433],
#>             ID["EPSG",8801]],
#>         PARAMETER["Longitude of natural origin",-111,
#>             ANGLEUNIT["degree",0.0174532925199433],
#>             ID["EPSG",8802]],
#>         PARAMETER["Scale factor at natural origin",0.9996,
#>             SCALEUNIT["unity",1],
#>             ID["EPSG",8805]],
#>         PARAMETER["False easting",500000,
#>             LENGTHUNIT["metre",1],
#>             ID["EPSG",8806]],
#>         PARAMETER["False northing",0,
#>             LENGTHUNIT["metre",1],
#>             ID["EPSG",8807]],
#>         ID["EPSG",16012]],
#>     CS[Cartesian,2],
#>         AXIS["(E)",east,
#>             ORDER[1],
#>             LENGTHUNIT["metre",1,
#>                 ID["EPSG",9001]]],
#>         AXIS["(N)",north,
#>             ORDER[2],
#>             LENGTHUNIT["metre",1,
#>                 ID["EPSG",9001]]]]
# }