Coder Social home page Coder Social logo

trondhusby / cbsshape Goto Github PK

View Code? Open in Web Editor NEW

This project forked from j535d165/cbsshape

0.0 1.0 0.0 1.41 MB

Simple interface for CBS Wijk en Buurtkaart.

Home Page: https://www.cbs.nl/nl-nl/dossier/nederland-regionaal/geografische-data

License: MIT License

R 100.00%

cbsshape's Introduction

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%202014%20versie%2030.zip" 
                                                                                                                         2015 
                                                                     "https://www.cbs.nl/-/media/_pdf/2017/36/buurt_2015.zip" 
                                                                                                                         2016 
"https://www.cbs.nl/-/media/cbs/dossiers/nederland%20regionaal/wijk-en-buurtstatistieken/shape%202016%20versie%2030.zip"
                                                                                                                         2017 
"https://www.cbs.nl/-/media/cbs/dossiers/nederland%20regionaal/wijk-en-buurtstatistieken/wijkbuurtkaart_2017_v3.zip"
                                                                                                                         2018 
"https://www.cbs.nl/-/media/cbs/dossiers/nederland%20regionaal/wijk-en-buurtstatistieken/wijkbuurtkaart_2018_v2.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)

cbsshape's People

Contributors

j535d165 avatar trondhusby avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.