Skip to contents

Reads a transport opportunities CSV file and efficiently generates a table containing the corresponding INSPIRE/GISCO grid cell IDs and data values.

Usage

tph_to_table(
  input_file,
  out_column_name = NULL,
  crs_src = 4326,
  crs_dst = 3035,
  x_offset = -500,
  y_offset = -500,
  resolution_m = 1000,
  add_centroid_coords = FALSE,
  add_gisco_corner_coords = FALSE
)

Arguments

input_file

Character. Path to the input CSV (gzipped) containing at least columns 'lon', 'lat', and one numeric data column.

out_column_name

Character or NULL. Name to assign to the data column in the output raster. If NULL (default), the original column name from the CSV is used.

crs_src

Integer or character. Source CRS (EPSG code or WKT); default is 4326.

crs_dst

Integer or character. Destination CRS (EPSG code or WKT); default is 3035.

x_offset

Numeric. An offset subtracted from the projected x-coordinate. This is used to convert the source point's reference (e.g., a lower-left corner) to the cell's theoretical centroid. For centroid-based data like GISCO, the default of 0 is correct.

y_offset

Numeric. An offset subtracted from the projected y-coordinate, similar to x_offset.

resolution_m

Numeric. Cell size in units of the destination CRS; default is 1000 (1 km).

add_centroid_coords

Logical. If TRUE, adds the original lon and lat as well as the projected centroid coordinates (x_centroid, y_centroid) to the output table. Defaults to FALSE.

add_gisco_corner_coords

Logical. If TRUE, adds the projected lower-left (south-west) corner coordinates (x_ll, y_ll) of the grid cell to the output table. Defaults to FALSE.

Value

A data.frame with the gisco_id, the data value, and optional coordinate columns.

Details

This function is the fastest method for converting TPH data, as it operates directly on coordinates and avoids creating any intermediate spatial objects (rasters, polygons, or sf points).

Examples

tph_file <- system.file(
  "extdata",
  "ver1_0_LU_1km_pt_ppl_within_10-20_min.csv.gz",
  package = "tphconv"
)

# Generate a table with both centroid and corner coordinates
full_table <- tph_to_table(
  tph_file,
  add_centroid_coords = TRUE,
  add_gisco_corner_coords = TRUE
)
head(full_table)
#>                          gisco_id opportunities_people      lon      lat
#> 1 CRS3035RES1000mN2934000E4033000                 2625 6.033336 49.45356
#> 2 CRS3035RES1000mN2934000E4057000                  375 6.363958 49.46471
#> 3 CRS3035RES1000mN2935000E4032000                 7463 6.018829 49.46205
#> 4 CRS3035RES1000mN2935000E4033000                10955 6.032604 49.46254
#> 5 CRS3035RES1000mN2935000E4034000                 4087 6.046380 49.46302
#> 6 CRS3035RES1000mN2935000E4037000                 4804 6.087708 49.46447
#>   x_centroid y_centroid    x_ll    y_ll
#> 1    4033500    2934500 4033000 2934000
#> 2    4057500    2934500 4057000 2934000
#> 3    4032500    2935500 4032000 2935000
#> 4    4033500    2935500 4033000 2935000
#> 5    4034500    2935500 4034000 2935000
#> 6    4037500    2935500 4037000 2935000