Skip to content

Instantly share code, notes, and snippets.

@kiwidamien
Created February 18, 2026 18:54
Show Gist options
  • Select an option

  • Save kiwidamien/a68ba3a32bbeb0acfb9d2ad4e0c6bb40 to your computer and use it in GitHub Desktop.

Select an option

Save kiwidamien/a68ba3a32bbeb0acfb9d2ad4e0c6bb40 to your computer and use it in GitHub Desktop.
Geocoding in NZ
import requests
import urllib.parse
def geocode(address_number, full_road_name, town_city, api_key):
base = "https://data.linz.govt.nz/services"
layer = "layer-105689"
cql = f"address_number={address_number} AND full_road_name ILIKE '%{full_road_name}%' AND town_city ILIKE '%{town_city}%'"
url = f"{base};key={api_key}/wfs"
params = {
"service": "WFS",
"version": "2.0.0",
"request": "GetFeature",
"typeNames": layer,
"outputFormat": "json",
"cql_filter": cql,
}
r = requests.get(url, params=params)
r.raise_for_status()
data = r.json()
if not data["features"]:
return None
return data["features"][0]["geometry"]["coordinates"] # lon, lat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment