Accessing Spatial and Population Data from Statistics Finland OGC api

Markus Kainu

2025-04-28

Introduction

The geofi package provides tools to access spatial data from Statistics Finland’s OGC API, including administrative boundaries, population data by administrative units, and population data by statistical grid cells. This vignette demonstrates how to use the package’s core functions to:

Unlike some other spatial data APIs, no API key is required to access Statistics Finland’s OGC API, making it straightforward to get started. The package handles pagination, spatial filtering, and coordinate reference system (CRS) transformations, delivering data as sf objects compatible with the sf package for spatial analysis and visualization.

Package Overview

The geofi package includes the following key functions for accessing Statistics Finland data:

All functions return spatial data as sf objects, making it easy to integrate with spatial analysis workflows in R.

Step 1: Retrieving Administrative Area Polygons

The ogc_get_statfi_area() function retrieves polygons for Finnish administrative units, such as municipalities (kunta), wellbeing areas (hyvinvointialue), or regions (maakunta). You can customize the output with parameters like:

Example: Downloading Municipalities

Fetch all municipalities for 2022 at the 1:4,500,000 scale:

munis <- ogc_get_statfi_area(year = 2022, scale = 4500, tessellation = "kunta")
print(munis)

Visualize the municipalities using ggplot2:

ggplot(munis) +
  geom_sf() +
  theme_minimal() +
  labs(title = "Finnish Municipalities (2022)")

Example: Spatial Filtering with a Bounding Box

To retrieve municipalities within a specific area (e.g., southern Finland), use the bbox parameter. Coordinates should match the specified crs.

bbox <- "200000,6600000,500000,6900000"  # In EPSG:3067
munis_south <- ogc_get_statfi_area(
  year = 2022,
  scale = 4500,
  tessellation = "kunta",
  bbox = bbox,
  crs = 3067
)

Visualize the filtered results:

ggplot(munis_south) +
  geom_sf() +
  theme_minimal() +
  labs(title = "Municipalities in Southern Finland (2022)")

Example: Fetching Wellbeing Areas

Retrieve wellbeing areas (hyvinvointialue) for 2022:

wellbeing <- ogc_get_statfi_area(
  year = 2022,
  tessellation = "hyvinvointialue",
  scale = 4500
)

Step 2: Retrieving Population Data by Administrative Area

The ogc_get_statfi_area_pop() function fetches administrative area polygons with associated population data, pivoted into a wide format where each population variable is a column. Parameters include:

Example: Fetching Population Data

Retrieve population data for 2021:

pop_data <- ogc_get_statfi_area_pop(year = 2021, crs = 3067)
print(pop_data)

Visualize population density (assuming a variable like population_total exists):

ggplot(pop_data) +
  geom_sf(aes(fill = population_total)) +
  scale_fill_viridis_c(option = "plasma") +
  theme_minimal() +
  labs(title = "Population by Administrative Area (2021)", fill = "Population")

Example: Population Data with Bounding Box

Fetch population data within a bounding box:

bbox <- "200000,6600000,500000,6900000"
pop_south <- ogc_get_statfi_area_pop(year = 2021, bbox = bbox, crs = 3067)

Step 3: Retrieving Population Data by Statistical Grid

The ogc_get_statfi_statistical_grid() function retrieves population data for statistical grid cells at 1km or 5km resolution. Data is returned in EPSG:3067 (ETRS89 / TM35FIN). Parameters include:

Example: Fetching 5km Grid Data

Retrieve population data for a 5km grid in 2021:

grid_data <- ogc_get_statfi_statistical_grid(year = 2021, resolution = 5000)
print(grid_data)

Visualize the grid data:

ggplot(grid_data) +
  geom_sf(aes(fill = population_total), color = NA) +
  scale_fill_viridis_c(option = "magma") +
  theme_minimal() +
  labs(title = "Population by 5km Grid Cells (2021)", fill = "Population")

Example: 1km Grid with Bounding Box

Fetch 1km grid data within a bounding box:

bbox <- "200000,6600000,500000,6900000"
grid_south <- ogc_get_statfi_statistical_grid(
  year = 2021,
  resolution = 1000,
  bbox = bbox
)

Advanced Features

Error Handling

The package includes robust error handling:

Coordinate Reference Systems

The functions support two CRS options:

Note that ogc_get_statfi_statistical_grid() is fixed to EPSG:3067, as per the API’s design.

Bounding Box Filtering

The bbox parameter allows spatial filtering to focus on specific regions. Ensure coordinates match the specified crs (e.g., EPSG:3067 for grid data). Example format: “200000,6600000,500000,6900000”.

Best Practices

Additional Resources

Conclusion

The geofi package simplifies access to Statistics Finland’s spatial and population data, enabling analyses of administrative boundaries, population distributions, and grid-based statistics. With no API key required, users can quickly retrieve and visualize data using sf and ggplot2. Try the examples above to explore Finland’s spatial and demographic datasets!