Created
June 17, 2024 11:03
-
-
Save dkapitan/c0bd741082cb7a6fe49fa354976b4ba6 to your computer and use it in GitHub Desktop.
Python script for Google Sheets Neptyne plugin to find lat-lon with pdok
This file contains 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
import re | |
import requests | |
import urllib | |
PDOK = "https://api.pdok.nl/bzk/locatieserver/search/v3_1/free" | |
def query_pdok(query): | |
query_params = { | |
"fl": "id nummeraanduiding_id centroide_ll huisnummer postcode", | |
"fq": "type:adres", | |
"df": "tekst", | |
"start": 0, | |
"rows": 1, | |
"sort": "score desc,sortering asc,weergavenaam asc", | |
"wt": "json", | |
} | |
params = urllib.parse.urlencode( | |
{**{"q": query}, **query_params}, quote_via=urllib.parse.quote | |
) | |
return [ | |
re.findall( | |
"\d+\.\d+", | |
requests.get(PDOK, params) | |
.json() | |
.get("response") | |
.get("docs")[0] | |
.get("centroide_ll"), | |
) | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment