Created
January 16, 2018 20:59
-
-
Save dkapitan/3a2018577c82516b1d15e307cdff60ff to your computer and use it in GitHub Desktop.
Load CBS data into PostgreSQL database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # download file from https://www.cbs.nl/nl-nl/dossier/nederland-regionaal/geografische%20data/wijk-en-buurtkaart-2017 | |
| import shapefile | |
| import pandas as pd | |
| from sqlalchemy import create_engine | |
| db = create_engine('postgresql://localhost:5432/opendata') | |
| sf = shapefile.Reader("/Users/dkapitan/opendata/CBS_PC4_2017/CBS_PC4_2017_v1.shp") | |
| shapes = sf.shapes() | |
| records = sf.records() | |
| cols = [field[0] for field in sf.fields][1:] | |
| df = pd.DataFrame.from_records(records, columns=cols) | |
| df.to_sql('pc4', db, schema='cbs', if_exists='replace', index=False, ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment