From dffa731db21afdd33ff7c5c3fed4f2892468a332 Mon Sep 17 00:00:00 2001 From: Jan Derk Date: Tue, 20 Jun 2023 21:23:13 +0200 Subject: [PATCH] V56 - Link to BAG changed as old one on Kadaster website was broken. - Openbare ruimte object are now replace instead of insert, as the BAG sometimes contains multiple openbare ruimte objects with the same id. --- config.py | 4 ++-- database_sqlite/database_sqlite.py | 9 ++++++--- readme.MD | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index d69be51..a465b55 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,7 @@ import locale -version = 55 -version_date = '7 May 2023' +version = 56 +version_date = '20 June 2023' locale.setlocale(locale.LC_ALL, 'nl_NL') diff --git a/database_sqlite/database_sqlite.py b/database_sqlite/database_sqlite.py index 0282c16..ca3e62b 100644 --- a/database_sqlite/database_sqlite.py +++ b/database_sqlite/database_sqlite.py @@ -61,21 +61,24 @@ def save_openbare_ruimte(self, data): data["naam"] = data["verkorte_naam"] if data["verkorte_naam"] != '' else data["lange_naam"] else: data["naam"] = data["lange_naam"] + # Note: Use replace, because BAG does not always contain unique id's self.connection.execute( - "INSERT INTO openbare_ruimten (id, naam, lange_naam, verkorte_naam, type, woonplaats_id) " - "VALUES(?, ?, ?, ?, ?, ?)", + """REPLACE INTO openbare_ruimten (id, naam, lange_naam, verkorte_naam, type, woonplaats_id) + VALUES(?, ?, ?, ?, ?, ?); + """, (data["id"], data["naam"], data["lange_naam"], data["verkorte_naam"], data["type"], data["woonplaats_id"])) def save_nummer(self, data): # Note: Use replace, because BAG does not always contain unique id's self.connection.execute( """REPLACE INTO nummers (id, postcode, huisnummer, huisletter, toevoeging, woonplaats_id, openbareruimte_id, - status) VALUES(?, ?, ?, ?, ?, ?, ?, ?) + status) VALUES(?, ?, ?, ?, ?, ?, ?, ?); """, (data["id"], data["postcode"], data["huisnummer"], data["huisletter"], data["toevoeging"], data["woonplaats_id"], data["openbareruimte_id"], data["status"]) ) + def save_pand(self, data): # Note: Use replace, because BAG does not always contain unique id's self.connection.execute( diff --git a/readme.MD b/readme.MD index 979eeb0..d988752 100644 --- a/readme.MD +++ b/readme.MD @@ -41,7 +41,7 @@ databases. There are a couple of options available in the [config.py](config.py) `git clone https://github.com/digitaldutch/BAG_parser` Update parser: `git pull https://github.com/digitaldutch/BAG_parser` -* [Download the BAG (2.8 GB)](https://www.kadaster.nl/-/kosteloze-download-bag-2.0-extract) and save the file as `bag.zip` in the `input` folder. +* [Download the BAG (2.8 GB)](https://service.pdok.nl/kadaster/adressen/atom/v1_0/downloads/lvbag-extract-nl.zip) and save the file as `bag.zip` in the `input` folder. * The [gemeenten.csv](input/gemeenten.csv) file is already included in the `input` folder, but you can [download the latest version from the CBS website](https://www.cbs.nl/nl-nl/onze-diensten/methoden/classificaties/overig/gemeentelijke-indelingen-per-jaar). Save it as `gemeenten.csv` in the input folder. * Set your options in [config.py](config.py) * Run `import_bag.py`