Adds projected coordinates X and Y to a data frame with longitude and
latitude, or the reverse: longitude and latitude to a data frame with
projected X and Y, e.g. a prediction grid built in kilometres with
make_survey_grid(). Spatial models and distance-based grid operations
need projected coordinates, in which a distance is the same in all
directions.
Arguments
- d
A data frame, or a
datras_rawobject, in which case the coordinates are added toHH.- crs
Coordinate reference system of
XandY, as accepted bysf::st_crs(). Default 3035, the ETRS89 Lambert azimuthal equal-area projection for Europe.- units
Units of
XandY:"km"(default) or"m".- lon, lat
Names of the longitude and latitude columns (decimal degrees, WGS84).
- xy
Names of the projected coordinate columns. Default
c("X", "Y"), as in the output ofmake_survey_grid().- inverse
Logical. If
FALSE(default),XandYare computed from longitude and latitude. IfTRUE, longitude and latitude are computed fromXandY.
Examples
if (requireNamespace("sf", quietly = TRUE)) {
x <- add_xy(dab)
head(x[["HH"]][, c("lon", "lat", "X", "Y")])
## A 10 km grid, with longitude and latitude for each node
grid <- make_survey_grid(x[["HH"]]$X, x[["HH"]]$Y, resolution = 10)
grid <- add_xy(grid, inverse = TRUE)
head(grid)
}
#> X Y lon lat
#> 1 3510 2980 -1.2151146 49.37472
#> 2 3520 2980 -1.0787174 49.38832
#> 3 3530 2980 -0.9422514 49.40175
#> 4 3540 2980 -0.8057172 49.41501
#> 5 3550 2980 -0.6691157 49.42811
#> 6 3560 2980 -0.5324476 49.44104
