~jomco/straatnaam

BAG Extract data postcode opzoek dingen
Expose version information through API endpoints
Very basic test page

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~jomco/straatnaam
read/write
git@git.sr.ht:~jomco/straatnaam

You can also use your local clone with git send-email.

#straatnaam

Expose BAG Extract data to do postcode/number completion for addresses in the Netherlands.

BAG stands for: "Basisregistratie Adressen en Gebouwen".

See also (all in Dutch):

#Address types

The BAG dataset contains the following addressable locations:

  • "verblijfsobject"

    Buildings.

  • "ligplaats"

    Floating buildings at a fixed location on the water.

  • "standplaats"

    Static buildings without a durable connection to their location.

A location can also have an alternative address like access from a different street. This is called a "nevenadres".

#Setup database

Install PostgreSQL with PostGIS and create database a superuser (to allow automatic postgis schema installation). By default to current user is used to connect to a database named "straatnaam", this can be overridden with environment variables PGDATABASE, PGUSER, etc.

Here's an example using docker:

docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust \
  --name straatnaam-pg postgis/postgis:13-master
createuser -U postgres -h localhost --superuser $USER
createdb -U $USER -h localhost straatnaam

#Running the test suite

To run the test suite run:

lein test

By default the tests requiring database access are skipped. To run them:

lein test :database

or to run all tests:

lein test :all

The database used is a local PostgreSQL named "straatnaam_test" owned by the current user. This can be overridden with environment variables PGTESTDATABASE, PGTESTUSER etc.

#Certificate problems?

The dataset is hosted at geodata.nationaalgeoregister.nl which uses certificates from "PKIoverheid" provided by Logius (see also https://www.pkioverheid.nl/) but the needed root CA certificate is not bundled with all JVM distributions in which case attempted imports will fail with:

synchronization failed #error {
 :cause unable to find valid certification path to requested target
 :via
 [{:type javax.net.ssl.SSLHandshakeException
   :message PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
   ...

This problem can be mitigated by getting the root CA certificate from https://www.pkioverheid.nl/ and creating a trust store for the JVM as follows:

# get default trust store
JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(which java)")")")"
cp "$JAVA_HOME/lib/security/cacerts" .cacerts
chmod +w .cacerts

# fetch pkioverheid CA
curl http://cert.pkioverheid.nl/QuoVadis_PKIoverheid_Server_CA_2020.cer \
> /tmp/cer.$$

# add to trust store
yes yes | keytool -import \
  -alias QuoVadis_PKIoverheid_Server_CA_2020.cer \
  -keystore .cacerts -storepass changeit \
  -file /tmp/cer.$$

# cleanup
rm -f /tmp/cer.$$
chmod -w .cacerts

Now set the following environment variable before starting the JVM:

export JDK_JAVA_OPTIONS="-Djavax.net.ssl.trustStore=$(pwd)/.cacerts -Djavax.net.ssl.trustStorePassword=changeit"

#Copying

Copyright (C) 2021, 2022 Remco van 't Veer

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.