| 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 |
| 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 |
Details
Refer to INE website to access the indicator online.
Value
A data.frame containing the aggregated Census OD records with columns:
-
geocod: Home location code -
geodsg: Home location designation -
dim_3: Sex category code -
dim_3_t: Sex category designation (H, M, HM) -
dim_4: Employment status code -
dim_4_t: Employment status designation (Empregada, Estudante, Total) -
dim_5: Working location code -
dim_5_t: Working location designation -
ind_string: Count / resident population value in string format -
valor: Count / resident population value in numeric format -
Periodo: Reference period (2011, 2021)
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., |
cntr_id |
Two-letter country code to filter by (default |
year |
Release year of the dataset. Allowed values are |
crs |
Coordinate Reference System (EPSG code) of the dataset. Allowed values are |
download_dir |
Directory where downloaded GeoPackage files are stored. Defaults to the
|
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 |
year |
Release year of the dataset. Allowed values are |
crs |
Coordinate Reference System (EPSG code) of the dataset. Allowed values are |
download_dir |
Directory where downloaded GeoPackage files are stored. Defaults to the
|
Value
An sf object containing spatial postal code boundaries/points.
Returned columns include:
-
POSTCODE: Postal code identifier (e.g. "1000-001") -
CNTR_ID: Country identifier (e.g. "PT") -
LAU_NAME: Local Administrative Unit name ("freguesia" for Portugal) -
NUTS3_2024: NUTS level 3 region code -
Shape: Point of postal code location.
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 |
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)