Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

J535D165/cbsshape

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CBS Wijk en Buurtkaart interface

This package provides a simple interface for the CBS Wijk en Buurtkaart shapefiles. These shapefiles are available on the website of CBS.

Looking for open data from CBS? Check out cbsodataR.

Installation

Install the package directly from Github with devtools. The package requires sf for reading shapefiles.

require(devtools)
install_github("J535D165/cbsshape")

Usage

Read municipality shapefiles (gemeenten) from 2017.

library(cbsshape)

cbs_shape_read(2017)

Gemeente, Wijk en Buurt

Read data on 3 different levels.

# read CBS Wijk en Buurtkaart kaart on "gem"
cbs_shape_read(2018, level="gem")
cbs_shape_read(2018, level="buurt")
cbs_shape_read(2018, level="wijk")

By default, the Simple Features are returned in Rijksdriehoek coordinates. One can get the result in WGS84 coordinates with the following code:

# read CBS Wijk en Buurtkaart kaart on "gem"
cbs_shape_read(2018, wgs84=TRUE)

Available shapefiles

Get a list of all available shapefiles:

> cbs_shape_list()
                                                                                                              2009 
                                               "http://download.cbs.nl/regionale-kaarten/2009-buurtkaart-gn-3.zip" 
                                                                                                              2010 
                                     "http://download.cbs.nl/regionale-kaarten/2010-buurtkaart-shape-versie-3.zip" 
                                                                                                              2011 
                                     "http://download.cbs.nl/regionale-kaarten/2011-buurtkaart-shape-versie-3.zip" 
                                                                                                              2012 
                                              "http://download.cbs.nl/regionale-kaarten/shape-2012-versie-3.0.zip" 
                                                                                                              2013 
                                              "http://download.cbs.nl/regionale-kaarten/shape-2013-versie-3-0.zip" 
                                                                                                              2014 
                                                "https://www.cbs.nl/-/media/_pdf/2016/35/shape-2014-versie-30.zip" 
                                                                                                              2015 
                                                          "https://www.cbs.nl/-/media/_pdf/2017/36/buurt_2015.zip" 
                                                                                                              2016 
  "https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/wijk-en-buurtstatistieken/shape-2016-versie-30.zip" 
                                                                                                              2017 
"https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/wijk-en-buurtstatistieken/wijkbuurtkaart_2017_v3.zip" 
                                                                                                              2018 
"https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/wijk-en-buurtstatistieken/wijkbuurtkaart_2018_v3.zip" 
                                                                                                              2019 
"https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/wijk-en-buurtstatistieken/wijkbuurtkaart_2019_v2.zip" 
                                                                                                              2020 
"https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/wijk-en-buurtstatistieken/wijkbuurtkaart_2020_v1.zip" 

Download

One can use cbsshape to download shapefiles.

cbs_shape_download(2017, "wijkenbuurt2017/")

and read the local shapefile

cbs_shape_read(2017, "wijkenbuurt2017/")

Combine the download and read function to download the data only if not available.

if (!cbs_shape_exists(2017, path="wijkenbuurt2017")){
  cbs_shape_download(2017, path="wijkenbuurt2017")
}

cbs_shape_read(2017, level="gem", path="wijkenbuurt2017")

Examples

Population density

library(cbsshape)
library(ggplot2)
library(dplyr)

# download 2017 data
wijk_en_buurt_2017 <- cbs_shape_read(2017)

# plot map
wijk_en_buurt_2017 %>% 
  # remove water polygons
  filter(WATER == "NEE") %>%
  # compute the population density
  mutate(density = AANT_INW/OPP_LAND*100) %>% 
  # plot the map
  ggplot() + 
    geom_sf(aes(fill=density))

Population density

Distance to Amsterdam

Compute the distance between every municipality in The Netherlands and the city of Amsterdam.

library(cbsshape)
library(sf)
library(tidyverse)

# download 2017 data
wijk_en_buurt_2017 <- cbs_shape_read(2017) %>%     
  filter(GM_CODE != "GM9999") %>% 
  filter(WATER == "NEE")
  
# compute the centroids
df_centroids <- wijk_en_buurt_2017 %>% 
  mutate(centroid = st_centroid(geometry)) %>%
  st_drop_geometry()

# grab the centroid of Amsterdam
centroid_amsterdam <- df_centroids %>% 
  filter(GM_NAAM == "Amsterdam") %>% 
  pull(centroid)

# Compute the distance to Amsterdam
st_distance(df_centroids$centroid, centroid_amsterdam)

Releases

No releases published

Packages

No packages published

Languages