Skip to contents

Reproject from or to lat-lon coordinates

Usage

geo_reproject(
  x,
  proj,
  x_col = "lon",
  y_col = "lat",
  crop = FALSE,
  inverse = FALSE
)

Arguments

x

A data frame

proj

The projection. Can be a geodomain, a geofield, a geolist, a projection string or a meteogrid projection list. When inverse = FALSE, this is the projection to which locations in lat-lon coordinates are reprojected, and when inverse = TRUE, this the projection from which locations in projected coordinates are reprojected to lat-lon coordinates.

x_col, y_col

The names of the columns containing the x and y coordinates to be reprojected. For inverse = FALSE, these should be longitude and latitude in decimal degrees. For inverse = TRUE, these should be eastings and northings in metres.

crop

When proj is a geodomain, geofield or geolist, set to TRUE to crop the reprojected locations to only those locations within the domain.

inverse

Set to TRUE to reprojected from projected coordinates to lat-lon coordinates. The default is FALSE

Value

The input data frame with new columns for the reprojected coordinates. The projection is added as an attribute. If the data are cropped, the domain is also added.

Examples

geo_reproject(station_list, det_grid_df$fcst)
#> # A tibble: 13,417 × 7
#>      SID   lat   lon  elev name                 x         y
#>    <int> <dbl> <dbl> <dbl> <chr>            <dbl>     <dbl>
#>  1  1001  70.9 -8.67   9.4 JAN MAYEN     -709968.  9153322.
#>  2  1002  80.1 16.2    8   VERLEGENHUKEN  115581. 10120270.
#>  3  1003  77   15.5   11.1 HORNSUND       126171.  9753893.
#>  4  1004  78.9 11.9    8   NY-ALESUND II   27542.  9977634.
#>  5  1006  78.3 22.8   14   EDGEOYA        291855.  9924366.
#>  6  1007  78.9 11.9    7.7 NY-ALESUND      27529.  9978366.
#>  7  1008  78.2 15.5   26.8 SVALBARD AP    114718.  9901691.
#>  8  1009  80.7 25.0    5   KARL XII OYA   281826. 10218418.
#>  9  1010  69.3 16.1   13.1 ANDOYA         214818.  8873169.
#> 10  1011  80.1 31.5   10   KVITOYA        428382. 10184745.
#> # ℹ 13,407 more rows

# Crop to domain
geo_reproject(station_list, det_grid_df$fcst, crop = TRUE)
#> # A tibble: 38 × 7
#>      SID   lat   lon  elev name                    x        y
#>    <int> <dbl> <dbl> <dbl> <chr>               <dbl>    <dbl>
#>  1  1372  60.6  9.13  167  "---"             -87965. 7888798.
#>  2  1373  60.6  9.13  167. "NESBYEN-TODOKK"  -87777. 7888449.
#>  3  1376  60.4  9.60  142  "GULSVIK II"      -62373. 7867446.
#>  4  1381  60.7 10.9   264  "APELSVOLL"         6983. 7902226.
#>  5  1382  60.8 10.8   128  "KISE"              3562. 7910339.
#>  6  1384  60.2 11.1   208. "OSLO/GARDERMOEN"  18786. 7847343.
#>  7  1386  60.8 11.1   132  "HAMAR II"         19396. 7913448.
#>  8  1392  60.6 12.0   185. "FLISA II"         69418. 7893277.
#>  9  1460  59.4 10.6    14  ""                 -9155. 7761560.
#> 10  1462  59.1  9.66   90  ""                -61700. 7723341.
#> # ℹ 28 more rows

# inverse projection
projected <- geo_reproject(station_list, det_grid_df$fcst)
geo_reproject(
  projected, det_grid_df$fcst, x_col = x, y_col = y, inverse = TRUE
)
#> # A tibble: 13,417 × 9
#>      SID   lat   lon  elev name                 x         y   lon   lat
#>    <int> <dbl> <dbl> <dbl> <chr>            <dbl>     <dbl> <dbl> <dbl>
#>  1  1001  70.9 -8.67   9.4 JAN MAYEN     -709968.  9153322. -8.67  70.9
#>  2  1002  80.1 16.2    8   VERLEGENHUKEN  115581. 10120270. 16.2   80.1
#>  3  1003  77   15.5   11.1 HORNSUND       126171.  9753893. 15.5   77  
#>  4  1004  78.9 11.9    8   NY-ALESUND II   27542.  9977634. 11.9   78.9
#>  5  1006  78.3 22.8   14   EDGEOYA        291855.  9924366. 22.8   78.3
#>  6  1007  78.9 11.9    7.7 NY-ALESUND      27529.  9978366. 11.9   78.9
#>  7  1008  78.2 15.5   26.8 SVALBARD AP    114718.  9901691. 15.5   78.2
#>  8  1009  80.7 25.0    5   KARL XII OYA   281826. 10218418. 25.0   80.7
#>  9  1010  69.3 16.1   13.1 ANDOYA         214818.  8873169. 16.1   69.3
#> 10  1011  80.1 31.5   10   KVITOYA        428382. 10184745. 31.5   80.1
#> # ℹ 13,407 more rows