Package {MobilityDataPT}


Title: Get Mobility Related Data for Portugal
Version: 1.0
Description: A collection of methods to get mobility related data for Portugal.
License: GPL-2 | GPL-3 [expanded from: GPL]
URL: https://github.com/U-Shift/MobilityDataPT, https://u-shift.github.io/MobilityDataPT/
Depends: R (≥ 4.1.0)
Imports: dplyr, tidyselect, httr, jsonlite, sf
Suggests: curl, spelling, testthat, withr
Encoding: UTF-8
Language: en-US
Config/roxygen2/version: 8.1.0
NeedsCompilation: no
Packaged: 2026-09-02 15:20:25 UTC; goncalo
Author: Gonçalo F. Matos ORCID iD [aut, cre]
Maintainer: Gonçalo F. Matos <goncaloafmatos@tecnico.pt>
Repository: CRAN
Date/Publication: 2026-09-12 13:20:02 UTC

Fetch Census Origin-Destination Data

Description

Retrieves Census Origin-Destination (Home/Work & Study) data from INE for a given home location.

Usage

census_od(id = "PT")

Arguments

id

Region category filter ID (default "PT"). See MobilityDataPT::census_od_regions() for available IDs.

Details

Refer to INE website to access the indicator online.

Value

A data.frame containing the aggregated Census OD records with columns:

Note

Data source: Instituto Nacional de Estatística (INE) (https://www.ine.pt/xportal/xmain?xpgid=ine_main&xpid=INE).

See Also

MobilityDataPT::census_od_regions()

Examples



od_data <- MobilityDataPT::census_od(id = "PT")
od_data |> dplyr::sample_n(5)






Fetch Census Origin-Destination available regions

Description

Queries the INE metadata API for the available regional filtering options available for MobilityDataPT::census_od().

Usage

census_od_regions()

Value

A data.frame with columns id and name.

Note

Data source: Instituto Nacional de Estatística (INE) (https://www.ine.pt/xportal/xmain?xpgid=ine_main&xpid=INE).

See Also

MobilityDataPT::census_od()

Examples



regions <- MobilityDataPT::census_od_regions()
head(regions)



Get Postal Code coordinates

Description

Retrieves spatial coordinates and geometry for specific postal code(s) from the Eurostat GISCO postal code database.

Usage

get_postal_code_coordinates(
  postal_codes = NULL,
  cntr_id = "PT",
  year = 2024,
  crs = 4326,
  download_dir = NULL
)

Arguments

postal_codes

Character vector of postal code identifiers (e.g., "1000-001" or c("1000-001", "2800-001")). If NULL, returns coordinates for all postal codes in the dataset.

cntr_id

Two-letter country code to filter by (default "PT"). Pass NA or NULL to return all countries.

year

Release year of the dataset. Allowed values are 2020 or 2024 (default 2024).

crs

Coordinate Reference System (EPSG code) of the dataset. Allowed values are 3857, 3035, or 4326 (default 4326).

download_dir

Directory where downloaded GeoPackage files are stored. Defaults to the MOBILITYDATAPT_DOWNLOAD_DIRECTORY environment variable or ~/.local/share/R/MobilityDataPT.

Value

An sf object containing matching postal code records and geometries.

Note

Data source: Eurostat GISCO Postal Codes (https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units/postal-codes).

See Also

MobilityDataPT::postal_code_database()

Examples


MobilityDataPT::get_postal_code_coordinates(c("1000-001", "2800-001"))



Access Eurostat GISCO Postal Code database

Description

Downloads and reads the GISCO Postal Codes dataset provided by Eurostat. Files are cached locally in the directory specified by the MOBILITYDATAPT_DOWNLOAD_DIRECTORY environment variable, defaulting to ~/.local/share/R/MobilityDataPT.

Usage

postal_code_database(
  cntr_id = "PT",
  year = 2024,
  crs = 4326,
  download_dir = NULL
)

Arguments

cntr_id

Two-letter country code to filter by (default "PT"). Pass NA or NULL to return all countries present in the dataset.

year

Release year of the dataset. Allowed values are 2020 or 2024 (default 2024).

crs

Coordinate Reference System (EPSG code) of the dataset. Allowed values are 3857, 3035, or 4326 (default 4326).

download_dir

Directory where downloaded GeoPackage files are stored. Defaults to the MOBILITYDATAPT_DOWNLOAD_DIRECTORY environment variable or ~/.local/share/R/MobilityDataPT.

Value

An sf object containing spatial postal code boundaries/points. Returned columns include:

Note

Data source: Eurostat GISCO Postal Codes (https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units/postal-codes).

Examples


db <- MobilityDataPT::postal_code_database()

db |> dplyr::select(POSTCODE, LAU_NAME, Shape) |> dplyr::sample_n(5)



Compute toll costs for an itinerary

Description

Encapsulates the calculation functionality of the web service provided by Infraestruturas de Portugal. Queries IP API to calculate expected toll costs across vehicle classes (C1, C2, C3, C4) for a given spatial itinerary.

Usage

tools_for_itinerary(sf_itinerary)

Arguments

sf_itinerary

An sf object containing route geometry (LINESTRING coordinates).

Value

A named list containing toll costs in Euros for each vehicle class (C1, C2, C3, C4).

Note

Data source: Infraestruturas de Portugal (https://portagens.infraestruturasdeportugal.pt/). Terms of service apply.

Examples

sf_itinerary <- sf::st_read(system.file("extdata/samples",
    "tool_itinerary_25AbrilBridge.gpkg",
    package = "MobilityDataPT"
), quiet = TRUE)

MobilityDataPT::tools_for_itinerary(sf_itinerary)