MRGfromDF {MRG}R Documentation

Function to create a gridded (usually multi-resolution grid) from a data.frame or csv file with information about the corners and resolution, as typically can be downloaded from Eurostat. The function can also save the grid as a geo-object.

Description

Function to create a gridded (usually multi-resolution grid) from a data.frame or csv file with information about the corners and resolution, as typically can be downloaded from Eurostat. The function can also save the grid as a geo-object.

Usage

MRGfromDF(
  df,
  coords = c("x", "y"),
  coordscale,
  crs = NA,
  res = "res",
  Estat = TRUE,
  cignore = FALSE,
  dsn,
  layer,
  ...
)

Arguments

df

A data.frame or name of a csv file with multi-resolution data, only specifying the lower left corner of the grid cells

coords

Names of the numeric columns holding coordinates

coordscale

Multiplication scaling factor for coordinates

crs

The coordinate reference system (CRS) into which all data should be projected before plotting. If not specified, will use the CRS defined in the first sf layer of the plot.

res

A resolution or a vector with the different resolutions

Estat

Indicate if Eurostat is the source of the data set. This is currently the default, but this might be changed in the future if other providers will follow the same conventions

cignore

Logical; Should the function ignore if parameters appear to be neither lat-lon or projected

dsn

Source name to be used by st_write. Interpretation varies by driver: can be a filename, a folder, a database name, or a Database Connection.

layer

Layer name to be used by st_write. Varies by driver, may be a file name without extension; for database connection, it is the name of the table. If layer is missing, the basename of dsn is taken.

...

Additional parameters to read.csv if csv is a file name

Details

This function is mainly for handling csv files downloaded from Eurostat, but can also be used for data from other sources, which adapt the same csv-convention as Eurostat.

The Eurostat-files have x- and y-coordinates that have been projected in the epsg:3035 projection. However, the coordinates show kilometers, not meters, so they have to be multiplied with 1000. Similar data sets might also be offered by other providers. The multiplication can be done with coordscale, or with Estat = TRUE (which also sets crs = 3035)

The function will also check the coordinates, if the range of both x- and y-coordinates are between 360 and 20000, it would often indicate that the coordinates should be multiplied. The function will suggest to correct this. If the coordinates are actually correct, the check can be overrun with cignore = TRUE

If writing to file, it is necessary to add the dsn and potentially layer to the input.

Value

The function produces a multiresolution grid, which is a sf-object with polygons.

Examples

library(MRG)
library(dplyr)
library(tidyr)
# C19.csv is an example file from Eurostat, including Utilized Agricultural Area 
# (UAAXK0000) and organic UAA (UAAXK0000_ORG) 
csvFile = system.file("ex/C19.csv", package="MRG")
C19 = MRGfromDF(csvFile, crs = 3035)  %>% mutate(orgShare = UAAXK0000_ORG/UAAXK0000)
MRGplot(C19, var = orgShare, xlim = c(2600000, 5800000), ylim = c(1500000, 5200000))


[Package MRG version 0.3.10 Index]