Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Turns Dutch addresses database (BAG or Basisregistratie Adressen en Gebouwen) into a user friendly SQLite database.

License

NotificationsYou must be signed in to change notification settings

digitaldutch/BAG_parser

Repository files navigation

GitHub licenseGitHub issues

Digital Dutch BAG parser

TL;DR

Converts in a few minutes the big, complex and hard to read XML Dutch addresses database (BAG or Basisregistratie Adressenen Gebouwen) into a user-friendly, file-based, blazingly fast SQLite database by running a single Python script.No need to install any dependencies or a database server.

Another oneliner script (see below) will convert this SQLite database to CSV in 15 seconds.

Download the parsed BAG

If you don't want to run the script yourself, download the latest BAG in SQLite or CSV format fromourreleases section.

About the BAG

The Dutch public addresses and buildings database (BAG or Basisregistratie Adressen en Gebouwen) is freely downloadablefrom theDutch cadastre agency named Kadaster. Hooray 🙂.

The bad news is: The original BAG comes in a complex and hard to read XML format using thousands of zipped XML files,which will quickly reduce your initial enthusiasm.It also does not include municipalities or provinces and provides coordinates using a system that non-experts won'texpect namedRijksdriehoekscoördinaten😲.

What this parser does

This Python utility parses the BAG database and converts it into a clean, easy to read & use SQLite database.Municipalities (gemeenten) and provinces (provincies) are added. Rijksdriehoekscoördinaten coordinates are convertedto standard WGS84 latitude and longitude coordinates. Invalid (dummy) bouwjaar and oppervlakte fields are removed.Construction year, floor area and intended use of buildings are also provided.Several tables (nummers, verblijfsobjecten, panden, ligplaatsen and standplaatsen) are merged into a general 'adressen'table. The SQLite database can be used directly as a source to generate a *.csv file or to update your own addressesdatabases. There are a couple of options available in theconfig.py.

Requirements

  • Python 3.13. Older Python versions may work but are not tested and certainly slower.

Usage

  • Download or use git (recommended as updates are easier) to download the BAG parser.
    Git command for initial checkout:
    git clone https://github.com/digitaldutch/BAG_parser
    Update to the latest version:
    git pull https://github.com/digitaldutch/BAG_parser
  • Download the BAG (3 GB) fromkadaster.nlor directly frompdok.nland save the file asbag.zip in theinput folder.
  • Thegemeenten.csv file is already included in theinput folder, but you candownload the latest version from the CBS website. Save it asgemeenten.csv in the input folder.
  • Set your options inconfig.py
  • Runimport_bag.py
  • Drink a cup of coffee for a few minutes ☕😎 while watching the progress bar.
  • Open the SQLite database with your favorite tool. I likeDBeaver.Here's an example query on SQLite database to get information about postcode 2514GL, huisnummer 78 (Paleis Noordeinde):
SELECTa.postcode,a.huisnummer,a.huisletter||a.toevoegingAS toevoeging,o.naamAS straat,g.naamAS gemeente,w.naamAS woonplaats,p.naamAS provincie,a.bouwjaar,a.latitude,a.longitude,a.rd_x,a.rd_y,a.oppervlakteAS vloeroppervlakte,a.gebruiksdoel,a.hoofd_nummer_idFROM adressen aLEFT JOIN openbare_ruimten oONa.openbare_ruimte_id=o.idLEFT JOIN gemeenten gONa.gemeente_id=g.idLEFT JOIN woonplaatsen wONa.woonplaats_id=w.woonplaats_idLEFT JOIN provincies pONg.provincie_id=p.idWHERE postcode='2514GL'AND huisnummer=68;
  • When done parsing, useexport_to_csv.py to create a *.csv file. This file has several command line options (see below).These conversion functions are easy to customize.I myself use one (not on GitHub) to pump the SQLite data into a live Firebird database.

Python commands

Parses the original BAG file and transforms it into an SQLite database. Takes about 6 minutes to completeon an AMD 9900X PC, or a few minutes more if you switch on theparse_geometries option in theconfig.py.

Exports the addresses in SQLite database to a *.csv file. By default, only the addresses andpostcode data are exported (~15 seconds). Use the command options below for more output formats.

-a, --all
Export all data including year of construction, latitude, longitude, floor area and intended use of buildings.~40s

-h, --help
show the help information message

-p4, --postcode4
Export statistics of 4 character postal code groups. (e.g. 1000). ~10s

-p5, --postcode5
Export statistics of 5 character postal code groups (e.g. 1000A). ~10s

-p6, --postcode6
Export statistics of 6 character postal code groups (e.g. 1000AA). ~10s

Checks the SQLite database for info and errors.import_bag.py also performs these tests after parsing.

Reduces the SQlite database size by removing BAG tables (nummers, verblijfsobjecten, panden, ligplaatsen and standplaatsen)that are no longer needed due to the new 'adressen' table.The parser also does this as a final step ifdelete_no_longer_needed_bag_tables is set toTrue inconfig.py.

Adressen table

An adres is a nevenadres if thehoofd_nummer_id field is set. It points to thenummer_id of the hoofdadres.

Limitations and notes

  • The WGS84 coordinates are calculated usingapproximation equations by F.H. Schreutelkamp and G.L. Strang van Hees. This conversion has an error of a few decimeters. Don't use theWGS84 coordinates if you need higher accuracy.
  • verblijfsobjecten table:
    Some gebruiksdoel, pand_id and nevenadressen fields contain multiple,comma-separated, values. Be careful if you do queries with joins on those fields.
  • Adressen table:
    • Some gebruiksdoel and pand_id fields contain multiple, comma-separated, values.
    • The bouwjaar and geometry field only contain the data of one pand, even if an address has multiple panden.
  • There are probably several more things missing that I don't know about. Feel free to file aGitHub issue.

Documents

Tools

Official BAG viewer

The Kadaster has an onlineBAG viewer where you can search any address or other info in the official database.

nlextract

This tool does not parse all data. If you need more data or professional support, buy it fromnlextract,who have a more complex, but also completeparser.

bagconv

Bert hubert haswritten a parser in C++,bagconv, which is quite similar to this one.

License

This software is made available under theMIT license.

About

Turns Dutch addresses database (BAG or Basisregistratie Adressen en Gebouwen) into a user friendly SQLite database.

Topics

Resources

License

Stars

Watchers

Forks

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp