| Title: | Reapportion Data from One Geography to Another |
|---|---|
| Description: | A port of the 'spReapportion' package, using Simple Features in order to lose the dependencies to the retired 'maptools' and 'rgeos' packages. |
| Authors: | François Briatte [aut, cre] (ORCID: <https://orcid.org/0000-0001-6494-9774>), Joël Gombin [aut] (ORCID: <https://orcid.org/0000-0002-9459-4473>) |
| Maintainer: | François Briatte <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.1 |
| Built: | 2026-05-26 14:57:14 UTC |
| Source: | https://github.com/briatte/sfreapportion |
All voter addresses located in the 20th arrondissement of Paris, according to
the Répertoire électoral unique (REU). We first extracted polling stations
from table-bv-reu.parquet, and then extracted addresses located within
them from table-adresses-reu.parquet. Addresses were converted into
spatial points of class sf. The weight variable is nb_adresses,
although that variable does not count voters per se: it measures the number
of voter addresses at that particular location, which is probably the best
publicly available proxy at that level of precision.
Paris20eAddressesParis20eAddresses
An object of class sf (inherits from grouped_df, tbl_df, tbl, data.frame) with 5820 rows and 3 columns.
INSEE: https://www.data.gouv.fr/datasets/bureaux-de-vote-et-adresses-de-leurs-electeurs
A shapefile of the IRIS (French census tract) of Paris in 2013.
ParisIrisParisIris
An object of class SpatialPolygonsDataFrame with 992 rows and 7 columns.
IGN: https://cartes.gouv.fr/rechercher-une-donnee/dataset/IGNF_CONTOURS-IRIS
A shapefile of the polling stations in Paris in 2012.
ParisPollingStations2012ParisPollingStations2012
An object of class SpatialPolygonsDataFrame with 867 rows and 5 columns.
Ville de Paris: https://opendata.paris.fr/explore/dataset/zones-de-rattachement-des-bureaux-de-vote-en-2012/table/
A dataset containing the number of inhabitants by socio-professional category in 2011 in Paris, by IRIS (the French census tract).
RP_2011_CS8_ParisRP_2011_CS8_Paris
An object of class data.frame with 992 rows and 10 columns.
C11_POP15P: nombre de personnes de 15 ans ou plus
C11_POP15P_CS1: Agriculteurs exploitants
C11_POP15P_CS2: Artisans, Commerçants, Chefs d'entreprise
C11_POP15P_CS3: Cadres et Professions intellectuelles supérieures
C11_POP15P_CS4: Professions intermédiaires
C11_POP15P_CS5: Employés
C11_POP15P_CS6: Ouvriers
C11_POP15P_CS7: Retraités
C11_POP15P_CS8: Autres sans activité professionnelle
INSEE: https://www.insee.fr/fr/statistiques/2028584
A replacement for rgeos::unaryUnion.
sfAggregate(sp, id)sfAggregate(sp, id)
sp |
an |
id |
a grouping vector, as required by |
a SpatialPolygonsDataFrame object with unique and
valid feature IDs
Source: https://github.com/r-spatial/sf/issues/2563
Roger Bivand (thanks)
This function allows to reapportion data from one geography to another, for example in the context of working with different administrative units.
sfReapportion( old_geom, new_geom, data, old_ID, new_ID, data_ID, variables = names(data)[-which(names(data) %in% data_ID)], mode = "count", weights = NULL, weight_matrix = NULL, weight_matrix_var = NULL )sfReapportion( old_geom, new_geom, data, old_ID, new_ID, data_ID, variables = names(data)[-which(names(data) %in% data_ID)], mode = "count", weights = NULL, weight_matrix = NULL, weight_matrix_var = NULL )
old_geom |
a 'SpatialPolygonsDataFrame' or 'sf' object representing the initial geometry. |
new_geom |
a 'SpatialPolygonsDataFrame' or 'sf' object representing the geometry you want to reapportion data to. |
data |
a 'data.frame' containing the data to reapportion, and an ID allowing to match it to the 'old_geom'. |
old_ID |
a string, the name of the ID variable in the 'old_geom'. |
new_ID |
a string, the name of the ID variable in the 'new_geom'. |
data_ID |
a string, the name of the ID variable in the 'data'. |
variables |
a character vector, representing the names of the variables in the 'data' set to reapportion. By default, all data variables except for the ID. |
mode |
either |
weights |
(optional, lightly tested only) In case the variables are proportions, the name of the variable containing weights (i.e. the total number of observations per unit in the 'old_geom'). |
weight_matrix |
(optional, lightly tested only) a 'SpatialPointsDataFrame' or 'sf' object indicating the spatial coordinates of the observations (inhabitants, voters, etc.). |
weight_matrix_var |
(optional, lightly tested only) the name of
the (numeric) variable containing the weights in |
a 'data.frame' containing new_ID and the reapportioned
variables from data
Inspiration from https://stackoverflow.com/a/17703903 and
https://rpubs.com/PaulWilliamson/6577.
Original sp version available at https://github.com/joelgombin/spReapportion.
All mistakes are mine, obviously. More details appear in the README file.
Joël Gombin (initial sp version),
François Briatte (sf port)