Skip to contents

transform_xy() transforms geospatial x/y coordinates to a new projection.

Usage

transform_xy(pts, srs_from, srs_to)

Arguments

pts

A two-column data frame or numeric matrix containing geospatial x/y coordinates.

srs_from

Character string in OGC WKT format specifying the spatial reference system for pts.

srs_to

Character string in OGC WKT format specifying the output spatial reference system.

Value

Numeric array of geospatial x/y coordinates in the projection specified by srs_to.

Examples

pt_file <- system.file("extdata/storml_pts.csv", package="gdalraster")
pts <- read.csv(pt_file)
print(pts)
#>    id   xcoord  ycoord
#> 1   1 324650.9 5103344
#> 2   2 324171.0 5103034
#> 3   3 323533.4 5103329
#> 4   4 325220.0 5103508
#> 5   5 325703.1 5102377
#> 6   6 326297.8 5103924
#> 7   7 325520.4 5104146
#> 8   8 326247.7 5102506
#> 9   9 327711.7 5104476
#> 10 10 324181.7 5103901
## id, x, y in NAD83 / UTM zone 12N
## transform to NAD83 / CONUS Albers
transform_xy(pts = pts[,-1],
             srs_from = epsg_to_wkt(26912),
             srs_to = epsg_to_wkt(5070))
#>           [,1]    [,2]
#>  [1,] -1330885 2684892
#>  [2,] -1331408 2684660
#>  [3,] -1331994 2685048
#>  [4,] -1330297 2684967
#>  [5,] -1329991 2683777
#>  [6,] -1329167 2685212
#>  [7,] -1329903 2685550
#>  [8,] -1329432 2683821
#>  [9,] -1327683 2685541
#> [10,] -1331265 2685514