Skip to content

s01ipsist/open_nz_postcodes

Repository files navigation

Open NZ Postcodes

An openly licenced (unofficial) dataset of New Zealand postcodes with geospatial representation as digital boundaries.

Latest boundary shapefiles can be downloaded from "Artifacts" in the latest/top Workflow Run.

Boundary files are generated automatically using latest upstream data weekly via GitHub Actions.

process-data

Sample output for Auckland central area

Context

As of mid-2024, an open data set of NZ Postcodes was the 2nd most requested dataset on data.govt.nz but NZ Post have simply responded that the

Address post code finder ... can be accessed via our website. https://www.nzpost.co.nz/tools/address-postcode-finder

An Official Information Act request for this data has been denied. https://fyi.org.nz/request/8955-geospatial-file-of-all-nz-postcodes

Wikipedia tells us there are 1856 postcodes in New Zealand.

Approximately 700 of these are postal lobby postcodes used for PO Boxes and Private Bags. Physical postcodes are those associated with residential or street addresses.

There are various freely available NZ postcode datasets:

but these are limited to a list of places/localities, associated postcode(s) and a centroid geo point.

This project is an attempt to create a dataset of NZ physical postcodes with complex polygonal geospatial representation.

This project can/will be retired if/when NZ Post release an official version!

Relevant geodata sources

There are many great open-licenced geo datasets for New Zealand. Those that could be useful for this project to develop digital boundaries include:

Dataset Source Geo type Count Postcodes per row
regions Statistics NZ polygon 16 many
localities LINZ polygon 7000 many
roads LINZ line 77000 one or few
meshblocks Statistics NZ polygon 57000 one or few
address points LINZ point 2300000 one

Land Information New Zealand (LINZ) and Statistics NZ provide many high fidelity, open-licenced datasets but no postcodes.

  • Address points. Each address point could be assigned a single postcode.
  • Roads. Most address points on the same road share the same postcode. Very long roads may have address points in multiple postcodes
  • Localities. Most address points in the same locality share the same postcode
  • Meshblocks. A meshblock is the smallest geographic unit for which statistical data is collected and processed by Stats NZ.
  • Regions. Regional councils / ISO-3166-2)

Note that postal area digital boundaries are freely available in Australia from Australian Bureau of Statistics. 🤔

Postcodes for Roads

This project contributes a dataset of NZ roads mapped to postcodes. street-postcodes are captured in csv format split by first letter of road name (e.g. a.csv, b.csv), with all roads using a digit as first letter captured in 0.csv. Where a road is identified as crossing postcode boundaries, the postcode is set to null.

Methodology

  • Using the dataset of street-postcodes, assign postcode to each address point on roads
  • Assign a postcode to each meshblock polygon, based on most popular postcode of all address points in the meshblock
  • Take the union of all meshblocks for each postcode to form a digital boundary

Prerequisites

  1. Download open datasets from URLs identified in import-geodata.sh and unzip into data folder
  2. Install Docker
  3. For snapshots: QGIS, timeout (found on MacOS in brew install coreutils)

Build

Generate zipped shapefile boundary in release folder

docker compose run --rm app scripts/run.sh

Generate png snapshots per postcode boundary using QGIS.

Sample QGIS snapshot

cd snapshots && bash qgis_screenshots.sh && cd ..
zip -jr release/open_nz_postcode_boundaries_png.zip snapshots/*.png

The included QGIS project open_nz_post.qgz presents the road network on top of the postcode boundaries filled with a random color seeded by the postcode value

Layer Properties - Symbology - Single Symbol - Simple Fill - Fill color

color_rgb(rand(50, 255, to_int(  attribute( 'postcode') )), rand(100, 255, to_int(  attribute( 'postcode') )), rand(200, 255, to_int(   attribute( 'postcode') )))

Usage

This dataset is appropriate for non-commerical use such as educational use, or personal or private study. With current methodology, about 5% of address points end up in a boundary with a different postcode. PRs welcome.

This dataset is likely not appropriate for addressing. The Postcode Network File is the authoritative definition of the NZ Post Postcode Network and available under commercial licence from NZ Post. https://www.nzpost.co.nz/business/sending-within-nz/quality-addressing/postcode-network-file

License

This project is licensed under the Creative Commons Zero (CC0) 1.0 Universal License. This means that all assets and code in this repository are dedicated to the public domain.

You are free to:

  • Copy, modify, distribute, and use the work, even for commercial purposes, without asking permission.

For more information, see the full license text: https://creativecommons.org/publicdomain/zero/1.0/

Attribution

Uses data licensed for reuse under CC BY 4.0 license from LINZ Data Service and Stats NZ.

Contributors

Thanks to www.addressable.co.nz who developed the initial project and cultivated the street-postcode dataset.