Skip to content

Instantly share code, notes, and snippets.

@dkapitan
Created June 17, 2024 11:03
Show Gist options
  • Save dkapitan/c0bd741082cb7a6fe49fa354976b4ba6 to your computer and use it in GitHub Desktop.
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
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