Phase 2: Geographic Datasets¶

These outputs will provide information on local areas, 2013 area units, and statistical area 2 units, and 2018 Meshblocks.

Note that all longitudes and latitudes should be in WGS1984 format

Outputs¶

Four csv files:

  • Local Area dataset
  • 2018 Meshblock dataset
  • 2018 SA2 dataset
  • 2013 AU dataset

Note: only geographic areas within Auckland region are necessary.

In [1]:
#pragma nodebook off
#Use nodebook for better reproducibility https://github.com/uoa-eResearch/nodebook
%reload_ext nodebook.ipython
%nodebook disk phase2

Local area dataset¶

  1. Name (string is fine) Name
In [ ]:
# load libraries
import geopandas as gpd # vector data
import pandas as pd # tabular data, loading CSVs
import numpy as np # numeric data
from util import *
import matplotlib # plotting
import seaborn as sns # plotting
from matplotlib_scalebar.scalebar import ScaleBar # scalebar for plot
import matplotlib.pyplot as plt # plotting
from tqdm.auto import tqdm # progress bars
tqdm.pandas()
import json
from shapely.geometry import Point, shape # creating points
import requests # web requests
plt.rcParams['figure.figsize'] = (20, 20)
/usr/local/lib/python3.10/dist-packages/geopandas/_compat.py:123: UserWarning: The Shapely GEOS version (3.11.1-CAPI-1.17.1) is incompatible with the GEOS version PyGEOS was compiled with (3.10.4-CAPI-1.16.2). Conversions between both will be slow.
  warnings.warn(
<string>:2: UserWarning: Shapely 2.0 is installed, but because PyGEOS is also installed, GeoPandas will still use PyGEOS by default for now. To force to use and test Shapely 2.0, you have to set the environment variable USE_PYGEOS=0. You can do this before starting the Python process, or in your code before importing geopandas:

import os
os.environ['USE_PYGEOS'] = '0'
import geopandas

In a future release, GeoPandas will switch to using Shapely by default. If you are using PyGEOS directly (calling PyGEOS functions on geometries from GeoPandas), this will then stop working and you are encouraged to migrate from PyGEOS to Shapely 2.0 (https://shapely.readthedocs.io/en/latest/migration_pygeos.html).
In [ ]:
ls()
name filesize (MB) last modified
0 2013-mb-dataset-Total-New-Zealand-Household.csv 37.12 2023-04-26 09:36:11.702367
1 2013-mb-dataset-Total-New-Zealand-Individual-Part-1.csv 31.66 2023-04-26 09:36:17.892367
2 2013_census_mean_income_by_AU2013.xlsx 0.59 2023-04-26 09:36:20.982367
3 2016_aup.zip 1192.41 2023-04-26 09:36:43.692368
4 2018-census-electoral-population-meshblock-2020-data.csv 5.60 2023-04-26 09:36:19.952367
5 2018_census_dwellings_by_SA2.xlsx 0.43 2023-04-26 09:36:20.982367
6 AC_Special_Housing_Area.zip 0.29 2023-04-26 09:36:21.012367
7 AUP_viewshafts.zip 0.21 2023-04-26 09:36:21.182367
8 AucklandArea.gpkg 0.09 2023-04-26 09:36:21.072367
9 Geocoordinates_Direct_Transit_stops_AKL.xlsx 0.01 2023-04-26 09:36:21.272367
10 Individual_part1_totalNZ-wide_format_updated_16-7-20.csv 36.58 2023-04-26 09:36:14.252367
11 MASTER_UP_BaseZone_SHP.zip 66.92 2023-04-26 09:36:11.212367
12 Modified_Community_Boards_SHP.zip 1.30 2023-04-26 09:36:20.962367
13 NZ_Primary_Parcels_Nov_2016.zip 1027.26 2023-04-26 09:36:41.572368
14 Primary_Parcels_2016_prepared.gpkg 235.79 2023-04-26 09:36:18.662367
15 Transmission_Lines_exTRANSPOWER.zip 0.50 2023-04-26 09:36:20.982367
16 area-unit-2013.gdb.zip 14.21 2023-04-26 09:36:18.892367
17 kx-nz-state-highway-on-ramps-off-ramps-SHP.zip 0.14 2023-04-26 09:36:21.212367
18 lds-nz-addresses-pilot-FGDB.zip 36.43 2023-04-26 09:36:14.652367
19 lds-nz-coastline-mean-high-water-FGDB.zip 4.88 2023-04-26 09:36:20.962367
20 lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip 4.25 2023-04-26 09:36:20.972367
21 lds-nz-primary-parcels-CLIPPED-4326.gpkg 273.35 2023-04-26 09:36:20.902367
22 lds-nz-primary-parcels-FGDB.zip 78.05 2023-04-26 09:36:05.642367
23 lds-nz-railway-centrelines-topo-150k-SHP.zip 0.87 2023-04-26 09:36:20.972367
24 lds-nz-road-centrelines-topo-150k-FGDB.zip 36.06 2023-04-26 09:36:15.032367
25 lds-nz-street-address-FGDB.zip 30.48 2023-04-26 09:36:20.952367
26 meshblock-2013.gdb.zip 106.57 2023-04-26 09:36:08.102367
27 meshblock-2018-clipped-generalised.gdb.zip 32.83 2023-04-26 09:36:17.712367
28 nz-primary-parcels.gdb.zip 55.00 2023-04-26 09:36:10.802367
29 statsnzarea-unit-2013-FGDB.zip 13.79 2023-04-26 09:36:19.132367
30 statsnzmeshblock-higher-geographies-2018-generalised-FGDB.zip 34.54 2023-04-26 09:36:17.482367
31 statsnzpopulation-by-meshblock-2013-census-FGDB.zip 82.11 2023-04-26 09:36:06.092367
32 statsnzstatistical-area-2-higher-geographies-2018-clipped-generalis-FGDB.zip 10.72 2023-04-26 09:36:19.912367
Total: 3451.0MB
In [ ]:
df = gpd.read_file("input/Modified_Community_Boards_SHP.zip")
df.OBJECTID = df.OBJECTID.astype(int)
df = df.set_index("OBJECTID", drop=True)
df = df.sort_index()
display(df)
Local_Area geometry
OBJECTID
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443...
2 Beach Haven-Birkenhead-Northcote POLYGON ((1757287.966 5925962.738, 1757211.333...
3 Botany POLYGON ((1770748.846 5912611.168, 1770889.893...
4 Devonport-Takapuna POLYGON ((1755276.581 5932026.336, 1755278.305...
5 East Coast Bays POLYGON ((1756125.006 5940268.048, 1756139.852...
6 Franklin-Beachlands-Hunua MULTIPOLYGON (((1804302.354 5890738.079, 17905...
7 Franklin-Pukekohe POLYGON ((1765085.620 5897344.807, 1765096.229...
8 Franklin-Waiuku POLYGON ((1744829.308 5899882.633, 1744835.760...
9 Henderson-Massey POLYGON ((1745963.138 5923457.510, 1745945.884...
10 Hibiscus Coast MULTIPOLYGON (((1752023.352 5954803.281, 17520...
11 Howick POLYGON ((1771447.460 5916900.636, 1771474.703...
12 Mangere-Otahuhu MULTIPOLYGON (((1766142.746 5910838.845, 17661...
13 Manurewa POLYGON ((1769432.488 5904664.673, 1769471.312...
14 Maungakiekie POLYGON ((1759418.674 5915517.660, 1759596.351...
15 Mt Albert POLYGON ((1756291.061 5918265.104, 1756266.530...
16 Mt Eden POLYGON ((1751910.995 5920299.659, 1751917.632...
17 Orakei POLYGON ((1759833.395 5920429.502, 1759837.143...
18 Otara MULTIPOLYGON (((1765765.640 5909501.655, 17657...
19 Pakuranga POLYGON ((1769523.742 5920466.582, 1769527.337...
20 Papakura POLYGON ((1772188.699 5902202.011, 1772192.566...
21 Papatoetoe POLYGON ((1765105.421 5908611.893, 1765113.661...
22 Puketapapa POLYGON ((1753132.892 5915040.177, 1753141.101...
23 Rodney-Dairy Flat POLYGON ((1746055.938 5948651.765, 1746067.112...
24 Rodney-Helensville MULTIPOLYGON (((1710567.626 5967865.416, 17106...
25 Rodney-Kumeu-Riverhead POLYGON ((1742532.808 5931237.574, 1742490.377...
26 Rodney-Warkworth MULTIPOLYGON (((1761692.564 5984690.018, 17617...
27 Rodney-Wellsford MULTIPOLYGON (((1746318.204 6000215.757, 17464...
28 Tamaki POLYGON ((1765594.677 5917986.938, 1765609.808...
29 Titirangi POLYGON ((1749038.038 5910572.842, 1749034.230...
30 Upper Harbour Local Board Area MULTIPOLYGON (((1743880.554 5928979.708, 17438...
31 Waiheke MULTIPOLYGON (((1793981.864 5931917.843, 17940...
32 Waitakere MULTIPOLYGON (((1743890.310 5905057.188, 17438...
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481...
In [ ]:
df = df.rename(columns={"Local_Area": "Name"})
  1. Centroid longitude Centroid_lon
  2. Centroid latitude Centroid_lat
  3. Area (land only) Area
In [ ]:
df["Centroid_lon"] = df.centroid.to_crs(epsg=4326).x
df["Centroid_lat"] = df.centroid.to_crs(epsg=4326).y
df["Area"] = df.area
  1. Area zoned Residential under AUP Residential_area
  2. Area zoned Residential - Single House under AUP SH_area
  3. Area zoned Residential - Mixed Housing Suburban under AUP MHS_area
  4. Area zoned Residential - Mixed Housing Urban under AUP MHU_area
  5. Area zoned Residential - Terrace Housing and Apartments under AUP THA_area
  6. Area zoned Residential – Large Lot under AUP LL_area
  7. Area zoned Future Urban under AUP FU_area
  8. Area zones Hauraki Gulf Islands under AUP HGI_area
  9. Area zoned Business under AUP Business_area
  10. Area zoned Rural under AUP Rural Rural_area
  11. Area zoned as Open Space under AUP maps Open_area
  12. Area zoned as Roads under the Unitary Plan Roads_area
  13. Area zoned as Strategic Infrastructure Corridor InfraCorr_area
  14. Area zoned as Green Infrastructure Corridor under the Unitary Plan GrInfraCorr_area
In [ ]:
%%time
zones = gpd.read_file("input/MASTER_UP_BaseZone_SHP.zip")
zones
CPU times: user 48.8 s, sys: 2.26 s, total: 51 s
Wall time: 50.8 s
Out[ ]:
OBJECTID CONTOUR created_da DocumentUR GlobalID GROUPZONE GROUPZONE_ last_edite NAME PARCEL_BAS ... TYPE TYPE_resol VERSIONSTA VERSIONS_1 ZONE ZONE_resol ZONEHEIGHT SHAPE_Leng SHAPE_Area geometry
0 1.0 NaN 20160718211 NaN {4C8F9436-7EA6-417E-B64F-15FCD44459F6} 2 Residential 20161111010 NaN NaN ... NaN NaN 4 Operative 60 Residential - Mixed Housing Urban Zone NaN 285.664016 2.050275e+03 POLYGON ((1768030.306 5901206.846, 1768033.070...
1 2.0 NaN 20160718211 NaN {604AAD87-8ED4-4111-8276-47CEE7E81F92} 1 Public Open Space 20161111010 NaN NaN ... NaN NaN 4 Operative 33 Open Space - Sport and Active Recreation Zone NaN 1246.837757 1.684599e+04 POLYGON ((1764267.286 5919989.370, 1764218.153...
2 3.0 NaN 20160718211 NaN {8D827DA8-BC5B-437A-B17A-532354F7D037} 4 Rural 20161111010 NaN NaN ... NaN NaN 4 Operative 11 Rural - Mixed Rural Zone NaN 3582.113246 6.841744e+05 POLYGON ((1740091.195 5928308.839, 1740089.844...
3 4.0 NaN 20160718211 NaN {96C9E266-3341-4C71-94F1-325F2EE45732} 2 Residential 20161111010 NaN NaN ... NaN NaN 4 Operative 23 Residential - Large Lot Zone NaN 317.098469 6.024226e+03 POLYGON ((1750502.125 5928677.635, 1750456.131...
4 5.0 NaN 20160718211 NaN {90B50FEE-45A3-4E88-819A-370751ACDE3D} 1 Public Open Space 20161111010 NaN NaN ... NaN NaN 4 Operative 31 Open Space - Conservation Zone NaN 230.836636 5.639794e+02 POLYGON ((1741460.217 5918191.600, 1741476.745...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
130295 130296.0 NaN 20161115151 NaN {B2F0FB45-80F6-41ED-AA57-A914B195B31E} 1 Public Open Space 20161115151 NaN NaN ... NaN NaN 4 Operative 31 Open Space - Conservation Zone NaN 179382.307787 9.040193e+07 POLYGON ((1738072.631 5902593.421, 1738095.386...
130296 130297.0 NaN 20161115151 NaN {A3F4EF61-9162-43C3-90BD-DC84D93C6A64} 2 Residential 20161115151 NaN NaN ... NaN NaN 4 Operative 18 Residential - Mixed Housing Suburban Zone NaN 2769.292040 2.920602e+05 POLYGON ((1770189.642 5905789.775, 1770199.407...
130297 130298.0 NaN 20161115151 NaN {A5FC7EB5-76E5-414C-96DD-715C671764B4} 4 Rural 20161115151 Kaipara South Head and Harbour coastal area NaN ... NaN NaN 4 Operative 46 Rural - Rural Coastal Zone NaN 27168.762393 6.344938e+06 POLYGON ((1730253.401 5955767.484, 1730254.399...
130298 130299.0 NaN 20161115151 NaN {C371B83C-35CE-46A1-B94F-F1E592F271F7} 2 Residential 20161115151 NaN NaN ... NaN NaN 4 Operative 8 Residential - Terrace Housing and Apartment Bu... NaN 1812.109533 1.536829e+05 POLYGON ((1743032.759 5924130.564, 1742996.886...
130299 130300.0 NaN 20161115151 NaN {31281924-C74D-4038-8260-FE6D886F4C94} 2 Residential 20161115151 NaN NaN ... NaN NaN 4 Operative 18 Residential - Mixed Housing Suburban Zone NaN 2511.267945 3.539606e+05 POLYGON ((1748979.767 5925771.895, 1748986.615...

130300 rows × 31 columns

In [ ]:
zones[pd.isna(zones.ZONE_resol)]
Out[ ]:
OBJECTID CONTOUR created_da DocumentUR GlobalID GROUPZONE GROUPZONE_ last_edite NAME PARCEL_BAS ... TYPE TYPE_resol VERSIONSTA VERSIONS_1 ZONE ZONE_resol ZONEHEIGHT SHAPE_Leng SHAPE_Area geometry
20853 20854.0 NaN 20160718211 NaN {2D83F680-9587-4D57-AF0B-CB7CA27C3D2C} 6 Special purpose zone 20161111011 NaN NaN ... NaN NaN 4 Operative 58 NaN NaN 72.629617 22.286945 POLYGON ((1767684.860 5903714.023, 1767691.955...
121765 121766.0 NaN 20160718211 NaN {FD3E8BB4-1979-42B5-9A77-5D04AE5190AF} 6 Special purpose zone 20161111010 NaN NaN ... NaN NaN 4 Operative 58 NaN NaN 86.135341 4.114962 POLYGON ((1767684.083 5903713.690, 1767666.954...

2 rows × 31 columns

In [ ]:
zones.ZONE_resol = zones.ZONE_resol.fillna("Special")
In [ ]:
zones.GROUPZONE_.value_counts()
Out[ ]:
General                 52461
Coastal                 42200
Residential             22398
Public Open Space        6667
Business                 3237
Rural                    2750
Special purpose zone      299
New growth                288
Name: GROUPZONE_, dtype: int64
In [ ]:
zones.ZONE_resol.value_counts()
Out[ ]:
Road                                                         47012
Coastal - General Coastal Marine Zone                        26326
Coastal - Coastal Transition Zone                            15703
Residential - Mixed Housing Suburban Zone                     9775
Residential - Mixed Housing Urban Zone                        5864
Strategic Transport Corridor Zone                             4215
Residential - Single House Zone                               3766
Open Space - Conservation Zone                                3063
Open Space - Informal Recreation Zone                         2926
Residential - Terrace Housing and Apartment Building Zone     2134
Rural - Rural Production Zone                                 1025
Water                                                         1013
Business - Mixed Use Zone                                      782
Rural - Rural Coastal Zone                                     768
Business - Light Industry Zone                                 593
Business - Neighbourhood Centre Zone                           564
Residential - Rural and Coastal Settlement Zone                480
Open Space - Sport and Active Recreation Zone                  477
Business - Town Centre Zone                                    432
Residential - Large Lot Zone                                   379
Rural - Mixed Rural Zone                                       344
Rural - Countryside Living Zone                                326
Future Urban Zone                                              282
Business - Local Centre Zone                                   266
Hauraki Gulf Islands                                           221
Business - City Centre Zone                                    191
Open Space - Community Zone                                    183
Rural - Waitakere Ranges Zone                                  172
Business - Metropolitan Centre Zone                            160
Business - Heavy Industry Zone                                 130
Special Purpose - School Zone                                  126
Coastal - Mooring Zone                                         124
Business - General Business Zone                               103
Rural - Rural Conservation Zone                                 71
Rural - Waitakere Foothills Zone                                44
Special Purpose - Cemetery Zone                                 41
Special Purpose - Quarry Zone                                   34
Special Purpose - Maori Purpose Zone                            32
Special Purpose - Major Recreation Facility Zone                28
Special Purpose - Healthcare Facility and Hospital Zone         23
Coastal - Marina Zone                                           20
Coastal - Ferry Terminal Zone                                   20
Open Space - Civic Spaces Zone                                  18
Business - Business Park Zone                                   16
Special Purpose - Airports and Airfields Zone                    9
Green Infrastructure Corridor                                    6
Special Purpose - Tertiary Education Zone                        4
Coastal - Minor Port Zone                                        4
Coastal - Defence Zone                                           3
Special                                                          2
Name: ZONE_resol, dtype: int64
In [ ]:
# Create a dictionary mapping the first n character of the zone description to the desired variable name
zones_of_interest = {
    "Residential": "Residential_area",
    "Residential - Single House Zone": "SH_area",
    "Residential - Mixed Housing Suburban Zone": "MHS_area",
    "Residential - Mixed Housing Urban Zone": "MHU_area",
    "Residential - Terrace Housing and Apartment Building Zone": "THA_area",
    "Residential - Large Lot Zone": "LL_area",
    "Residential - Rural and Coastal Settlement Zone": "RCS_area",
    "Rural - Waitakere Ranges Zone": "WR_area",
    "Future Urban Zone": "FU_area",
    "Hauraki Gulf Islands":  "HGI_area",
    "Business": "Business_area",
    "Rural": "Rural_area",
    "Open Space": "Open_area",
    "Road": "Roads_area",
    "Strategic Transport Corridor Zone": "InfraCorr_area",
    "Green Infrastructure Corridor": "GrInfraCorr_area",
    "Rural - Waitakere Ranges": "RWR_area",
    "Rural - Waitakere Foothills": "RWF_area",
    "Rural - Rural Coastal": "RC_area",
    "Rural - Rural Production": "RP_area",
    "Rural - Rural Conservation": "RCZ_area",
    "Rural - Mixed Rural": "RMU_area",
    "Rural - Countryside Living": "RCL_area"
}
for k in zones_of_interest.keys():
    if not any(zones.ZONE_resol.str.startswith(k)):
        print(f"Don't know {k}")
In [ ]:
%%time
for k,v in tqdm(zones_of_interest.items()):
    subset = zones[zones.ZONE_resol.str.startswith(k)] # Just the matched zones (residential, business, rural etc)
    print(k, len(subset))
    clipped = gpd.clip(df, subset) # Clip the local areas to the matched zones
    df[v] = clipped.area # Store the resulting area. Unit is m²
  0%|          | 0/23 [00:00<?, ?it/s]
Residential 22398
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Single House Zone 3766
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Suburban Zone 9775
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Urban Zone 5864
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Terrace Housing and Apartment Building Zone 2134
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Large Lot Zone 379
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Rural and Coastal Settlement Zone 480
Rural - Waitakere Ranges Zone 172
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Future Urban Zone 282
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Hauraki Gulf Islands 221
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Business 3237
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural 2750
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Open Space 6667
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Road 47012
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Strategic Transport Corridor Zone 4215
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Green Infrastructure Corridor 6
Rural - Waitakere Ranges 172
Rural - Waitakere Foothills 44
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Coastal 768
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Production 1025
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Conservation 71
Rural - Mixed Rural 344
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Countryside Living 326
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
CPU times: user 53.5 s, sys: 1.37 s, total: 54.9 s
Wall time: 54.9 s
In [ ]:
df = df.fillna(0)
  1. Haversine distance to Skytower from centroid Hdist_skytower
In [ ]:
skytower = Point(1757109.809, 5920500.841) # in NZGD2000 projection
In [ ]:
df["Hdist_skytower"] = df.centroid.distance(skytower) # Unit is meters
In [ ]:
df.plot(column="Hdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Indicator (0 or 1) for whether local area is on coastline Coast_indicator
In [ ]:
coastline = df.dissolve().boundary.iloc[0]
In [ ]:
df["Coast_indicator"] = df.intersects(coastline)
df[["Name", "Coast_indicator"]]
Out[ ]:
Name Coast_indicator
OBJECTID
1 Auckland Central True
2 Beach Haven-Birkenhead-Northcote True
3 Botany True
4 Devonport-Takapuna True
5 East Coast Bays True
6 Franklin-Beachlands-Hunua True
7 Franklin-Pukekohe True
8 Franklin-Waiuku True
9 Henderson-Massey True
10 Hibiscus Coast True
11 Howick True
12 Mangere-Otahuhu True
13 Manurewa True
14 Maungakiekie True
15 Mt Albert False
16 Mt Eden True
17 Orakei True
18 Otara True
19 Pakuranga True
20 Papakura True
21 Papatoetoe True
22 Puketapapa True
23 Rodney-Dairy Flat True
24 Rodney-Helensville True
25 Rodney-Kumeu-Riverhead True
26 Rodney-Warkworth True
27 Rodney-Wellsford True
28 Tamaki True
29 Titirangi True
30 Upper Harbour Local Board Area True
31 Waiheke True
32 Waitakere True
33 Whau True
  1. Total population from 2013 census (sum of constituent meshblocks) Census2013_population
In [ ]:
households = pd.read_csv("input/2013-mb-dataset-Total-New-Zealand-Household.csv", encoding='unicode_escape')
households
<string>:1: DtypeWarning: Columns (1,2) have mixed types. Specify dtype option on import or set low_memory=False.
Out[ ]:
Area_Code_and_Description Code Description 2001_Census_total_households_in_occupied_private_dwellings 2006_Census_total_households_in_occupied_private_dwellings 2013_Census_total_households_in_occupied_private_dwellings 2001_Census_household_composition_for_households_in_occupied_private_dwellings_One-family_household_(with_or_without_other_people) 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Two-family_household_(with_or_without_other_people) 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Three_or_more_family_household_(with_or_without_other_people) 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Other_multi-person_household ... 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings
0 MB 0000100 100 NaN 3.0 3.0 3.0 ..C ..C ..C ..C ... ..C 3.0 ..C ..C ..C ..C ..C ..C ..C 3.0
1 MB 0000200 200 NaN 27.0 27.0 30.0 15 3 0 0 ... 3 24.0 3 9 24 6 15 30 3 30.0
2 MB 0000300 300 NaN 21.0 24.0 21.0 18 3 0 0 ... 0 24.0 0 6 12 3 9 18 3 18.0
3 MB 0000400 400 NaN 9.0 9.0 9.0 6 ..C ..C ..C ... ..C 12.0 ..C ..C 9 ..C 6 9 ..C 9.0
4 MB 0000501 501 NaN 0.0 0.0 0.0 ..C ..C ..C ..C ... ..C 0.0 ..C ..C ..C ..C ..C ..C ..C 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
49038 Footnotes for specific variables or categories 23 Median total household income is rounded to th... NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49039 Symbols ..C Confidential NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49040 Symbols .. not available NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49041 Symbols * not able to be calculated NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49042 Source Statistics New Zealand NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

49043 rows × 258 columns

In [ ]:
key = "2013_Census_total_household_income_(grouped)(2)(3)(4)_for_households_in_occupied_private_dwellings_Median_household_income_($)(18)(23)"
households_with_income = households[households.Area_Code_and_Description.str.startswith("MB") & (households[key] != "..C") & (households[key] != "*")].copy()
print(len(households_with_income))
households_with_income[key] = households_with_income[key].astype(int)
households_with_income[key].plot(kind="hist", bins=20, figsize=(10,10))
40300
Out[ ]:
<AxesSubplot: ylabel='Frequency'>
In [ ]:
meshblocks = gpd.read_file("input/statsnzpopulation-by-meshblock-2013-census-FGDB.zip!population-by-meshblock-2013-census.gdb")
meshblocks
Out[ ]:
Meshblock MeshblockNumber Population_Count_Usual_Resident_2013 Population_Count_Census_Night_2013 geometry
0 MB 0352700 0352700 0 0 MULTIPOLYGON (((1753237.550 5923918.395, 17532...
1 MB 0728500 0728500 9 6 MULTIPOLYGON (((1761011.438 5905840.848, 17610...
2 MB 0829300 0829300 93 99 MULTIPOLYGON (((1739739.656 5899165.556, 17397...
3 MB 1280801 1280801 0 0 MULTIPOLYGON (((1869852.595 5695096.558, 18714...
4 MB 2360001 2360001 0 0 MULTIPOLYGON (((1623601.773 5423210.098, 16235...
... ... ... ... ... ...
46616 MB 0074002 0074002 0 0 MULTIPOLYGON (((1741178.600 6046572.236, 17414...
46617 MB 3208002 3208002 78 81 MULTIPOLYGON (((1770892.430 5911519.906, 17708...
46618 MB 3208003 3208003 36 36 MULTIPOLYGON (((1771025.156 5911674.629, 17709...
46619 MB 3209001 3209001 84 87 MULTIPOLYGON (((1771731.425 5912665.799, 17717...
46620 MB 3209002 3209002 75 81 MULTIPOLYGON (((1771758.103 5912422.760, 17717...

46621 rows × 5 columns

In [ ]:
meshblocks.geometry = meshblocks.representative_point()
In [ ]:
meshblocks = meshblocks.merge(households, left_on="Meshblock", right_on="Area_Code_and_Description")
In [ ]:
meshblocks = gpd.sjoin(df, meshblocks, predicate="intersects")
meshblocks
Out[ ]:
Name geometry Centroid_lon Centroid_lat Area Residential_area SH_area MHS_area MHU_area THA_area ... 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings
OBJECTID
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... ..C 0.0 ..C ..C ..C ..C ..C ..C ..C 0.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... ..C 0.0 ..C ..C ..C ..C ..C ..C ..C 0.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... ..C 0.0 ..C ..C ..C ..C ..C ..C ..C 0.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... ..C 6.0 0 15 6 0 18 18 6 24.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... ..C 9.0 ..C 6 6 ..C 9 6 ..C 9.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... ..C 0.0 ..C ..C ..C ..C ..C ..C ..C 0.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... 3 42.0 3 39 33 0 30 45 0 45.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... 3 27.0 0 9 12 3 9 12 6 18.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... ..C 3.0 ..C ..C ..C ..C ..C ..C ..C 3.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... ..C 0.0 ..C ..C ..C ..C ..C ..C ..C 0.0

11527 rows × 293 columns

In [ ]:
group = meshblocks.groupby("OBJECTID")
In [ ]:
df["Census2013_population"] = group["Population_Count_Usual_Resident_2013"].sum()
  1. Number of dwellings from 2013 census (sum of constituent meshblocks) Census2013_dwellings
In [ ]:
df["Census2013_dwellings"] = group["2013_Census_total_households_in_occupied_private_dwellings"].sum()
  1. Average Household Income (weighted average of constituent meshblock household incomes from 2013 census, where the weights are given by the number of households in each of the constituent meshblocks in the local area) Census2013_avg_HH_income
In [ ]:
meshblocks_with_income = meshblocks[(meshblocks[key] != "..C") & (meshblocks[key] != "*")].copy()
meshblocks_with_income[key] = meshblocks_with_income[key].astype(int)
meshblocks_with_income
Out[ ]:
Name geometry Centroid_lon Centroid_lat Area Residential_area SH_area MHS_area MHU_area THA_area ... 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings
OBJECTID
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... ..C 6.0 0 15 6 0 18 18 6 24.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... ..C 9.0 ..C 6 6 ..C 9 6 ..C 9.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... 3 51.0 0 45 36 6 45 51 0 51.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... 0 48.0 3 45 36 6 39 48 0 48.0
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 137047.237209 2.942080e+06 2.939136e+05 ... 0 36.0 0 27 24 6 27 27 0 30.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... 0 54.0 3 39 45 6 42 51 3 54.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... 6 66.0 3 48 51 6 45 66 6 69.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... 3 54.0 0 48 42 3 45 54 6 60.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... 3 42.0 3 39 33 0 30 45 0 45.0
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 471066.237562 3.332548e+06 2.009848e+06 ... 3 27.0 0 9 12 3 9 12 6 18.0

10830 rows × 293 columns

In [ ]:
meshblocks_with_income["income*dwellings"] = meshblocks_with_income[key] * meshblocks_with_income["2013_Census_total_households_in_occupied_private_dwellings"]
meshblocks_with_income["income*dwellings"]
In [ ]:
group = meshblocks_with_income.groupby("OBJECTID")
df["Census2013_avg_HH_income"] = group["income*dwellings"].sum() / group["2013_Census_total_households_in_occupied_private_dwellings"].sum()
In [ ]:
df[["Name", "Census2013_population", "Census2013_dwellings", "Census2013_avg_HH_income"]].sort_values(by="Census2013_population", ascending=False)
In [ ]:
df
Out[ ]:
Name geometry Centroid_lon Centroid_lat Area Residential_area SH_area MHS_area MHU_area THA_area ... RC_area RP_area RCZ_area RMU_area RCL_area Hdist_skytower Coast_indicator Census2013_population Census2013_dwellings Census2013_avg_HH_income
OBJECTID
1 Auckland Central POLYGON ((1755802.315 5921956.091, 1755861.443... 174.753763 -36.855194 1.942334e+07 1.108573e+07 7.062543e+05 1.370472e+05 2.942080e+06 2.939136e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1067.517983 True 77058 31506.0 86499.398108
2 Beach Haven-Birkenhead-Northcote POLYGON ((1757287.966 5925962.738, 1757211.333... 174.721897 -36.794764 3.406603e+07 1.476243e+07 1.672204e+06 2.379868e+06 1.039881e+06 1.402369e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 6948.094501 True 82431 28344.0 80154.552207
3 Botany POLYGON ((1770748.846 5912611.168, 1770889.893... 174.917904 -36.957505 3.978830e+07 1.240583e+07 2.595033e+06 1.210010e+07 2.528557e+06 9.609651e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 1.019299e+06 1.261118e+07 18420.075506 True 46878 13893.0 93325.464764
4 Devonport-Takapuna POLYGON ((1755276.581 5932026.336, 1755278.305... 174.769923 -36.789009 2.111121e+07 1.437879e+07 4.003298e+05 1.887588e+06 2.665899e+06 5.945951e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 6621.239572 True 55398 20307.0 89560.517751
5 East Coast Bays POLYGON ((1756125.006 5940268.048, 1756139.852... 174.733122 -36.701804 3.038568e+07 1.691256e+07 1.083351e+06 3.296486e+04 2.890852e+06 2.219014e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 3.124826e+05 16467.095662 True 44634 15354.0 96602.171362
6 Franklin-Beachlands-Hunua MULTIPOLYGON (((1804302.354 5890738.079, 17905... 175.101754 -37.043410 7.778987e+08 2.928810e+06 4.415845e+05 8.490284e+06 0.000000e+00 4.426904e+05 ... 2.404916e+07 3.006035e+08 3.077544e+04 1.060471e+08 3.312952e+07 37193.822526 True 21111 7332.0 97416.701031
7 Franklin-Pukekohe POLYGON ((1765085.620 5897344.807, 1765096.229... 174.864884 -37.151426 2.717220e+08 1.622679e+07 6.467033e+06 5.660850e+06 3.079772e+06 3.792095e+05 ... 3.318708e+07 9.112082e+07 0.000000e+00 7.168090e+07 1.518285e+07 34851.656145 True 31176 10863.0 78094.119279
8 Franklin-Waiuku POLYGON ((1744829.308 5899882.633, 1744835.760... 174.666624 -37.164727 2.997611e+08 8.372005e+06 1.763932e+04 1.007797e+07 2.703557e+06 0.000000e+00 ... 9.149757e+07 4.023886e+07 0.000000e+00 1.386627e+08 6.572328e+05 36121.662648 True 13581 5046.0 68150.358852
9 Henderson-Massey POLYGON ((1745963.138 5923457.510, 1745945.884... 174.621864 -36.853375 5.321961e+07 3.686649e+06 4.685951e+05 2.303941e+06 2.243794e+05 1.096004e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 6.921767e+04 12525.129414 True 107658 34461.0 68347.842761
10 Hibiscus Coast MULTIPOLYGON (((1752023.352 5954803.281, 17520... 174.720160 -36.618022 7.969308e+07 5.101724e+06 1.985154e+04 6.294665e+06 2.723733e+06 3.034730e+04 ... 5.061610e+06 9.811656e+01 7.936355e+06 0.000000e+00 5.208255e+04 25832.060623 True 45141 17397.0 70786.765722
11 Howick POLYGON ((1771447.460 5916900.636, 1771474.703... 174.926939 -36.902134 1.461575e+07 9.096320e+06 3.916487e+04 3.137190e+06 1.552850e+06 8.686144e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1.121832e+07 15854.353763 True 40299 13836.0 85281.267636
12 Mangere-Otahuhu MULTIPOLYGON (((1766142.746 5910838.845, 17661... 174.794437 -36.972479 5.250979e+07 4.569329e+06 3.637463e+06 1.601068e+06 4.024164e+04 4.937933e+05 ... 0.000000e+00 2.710565e+06 0.000000e+00 0.000000e+00 1.217632e+07 14070.305771 True 70998 17427.0 61855.553636
13 Manurewa POLYGON ((1769432.488 5904664.673, 1769471.312... 174.886011 -37.018487 3.711616e+07 1.402263e+07 2.429714e+06 7.750997e+06 9.649423e+05 5.216074e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 7.860819e+06 21865.784349 True 82230 22584.0 69202.861326
14 Maungakiekie POLYGON ((1759418.674 5915517.660, 1759596.351... 174.799976 -36.915243 1.740899e+07 1.873652e+07 1.811262e+06 7.010512e+06 3.663284e+06 4.167398e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 8151.195589 True 27780 10368.0 76915.212333
15 Mt Albert POLYGON ((1756291.061 5918265.104, 1756266.530... 174.765299 -36.884922 1.385353e+07 8.308876e+06 3.715019e+06 2.058002e+06 1.566702e+06 1.360481e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 4067.283622 False 47913 15630.0 97670.686671
16 Mt Eden POLYGON ((1751910.995 5920299.659, 1751917.632... 174.718360 -36.879882 1.448821e+07 1.602986e+07 9.520285e+05 6.066849e+06 6.248986e+06 9.614689e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 5244.560531 True 46752 16155.0 83313.629602
17 Orakei POLYGON ((1759833.395 5920429.502, 1759837.143... 174.830542 -36.870391 3.234712e+07 5.002987e+06 3.103315e+05 9.023214e+06 1.117549e+06 4.997783e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 6567.770945 True 79581 29001.0 110143.425140
18 Otara MULTIPOLYGON (((1765765.640 5909501.655, 17657... 174.883562 -36.963798 1.213648e+07 2.547122e+07 1.531569e+07 6.760630e+06 1.640568e+06 2.513619e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 16766.406523 True 30033 6693.0 58229.733394
19 Pakuranga POLYGON ((1769523.742 5920466.582, 1769527.337... 174.891901 -36.898057 1.527965e+07 1.060461e+07 3.809348e+06 2.479102e+06 1.340626e+06 1.366092e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 12812.703793 True 39924 13206.0 82096.046353
20 Papakura POLYGON ((1772188.699 5902202.011, 1772192.566... 174.940390 -37.059940 4.022528e+07 5.122441e+06 2.915926e+06 1.082742e+06 7.851764e+05 3.947975e+05 ... 0.000000e+00 6.405900e+00 0.000000e+00 3.953037e+05 3.637283e+07 28340.533206 True 45687 14919.0 68043.070707
21 Papatoetoe POLYGON ((1765105.421 5908611.893, 1765113.661... 174.849291 -36.987020 2.497254e+07 2.098467e+07 4.506156e+06 8.916239e+05 3.291655e+06 1.161878e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 17234.007915 True 45633 13272.0 65055.631090
22 Puketapapa POLYGON ((1753132.892 5915040.177, 1753141.101... 174.741502 -36.916029 1.871805e+07 6.114247e+06 3.264382e+06 2.464966e+06 9.761411e+05 9.691525e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 7732.493593 True 52959 16695.0 75460.348858
23 Rodney-Dairy Flat POLYGON ((1746055.938 5948651.765, 1746067.112... 174.636168 -36.672259 1.132876e+08 7.835879e+06 6.069391e+06 1.187048e+07 4.001187e+06 1.177736e+05 ... 0.000000e+00 2.450833e+07 0.000000e+00 1.832241e+07 6.414765e+07 22546.984200 True 6564 2130.0 106361.971831
24 Rodney-Helensville MULTIPOLYGON (((1710567.626 5967865.416, 17106... 174.425342 -36.646179 7.974650e+08 1.808030e+07 1.423108e+06 6.562767e+06 8.037448e+04 0.000000e+00 ... 2.941202e+08 3.795723e+08 9.270628e+05 1.086005e+07 2.243177e+06 37521.293694 True 17832 6381.0 78202.750119
25 Rodney-Kumeu-Riverhead POLYGON ((1742532.808 5931237.574, 1742490.377... 174.538408 -36.780645 5.536146e+07 1.304669e+07 1.231326e+06 6.202250e+06 3.943621e+06 0.000000e+00 ... 0.000000e+00 1.278216e+07 1.490339e+01 1.147058e+07 8.818457e+06 21330.923764 True 7257 2472.0 86943.048780
26 Rodney-Warkworth MULTIPOLYGON (((1761692.564 5984690.018, 17617... 174.613063 -36.444991 6.684679e+08 1.681370e+07 5.952212e+06 1.799798e+05 6.208502e+04 0.000000e+00 ... 1.413502e+08 3.579461e+08 1.421499e+07 3.244393e+07 1.297497e+03 46699.922300 True 17637 6912.0 62686.367596
27 Rodney-Wellsford MULTIPOLYGON (((1746318.204 6000215.757, 17464... 174.538530 -36.291690 6.404974e+08 1.680348e+06 1.152092e+06 0.000000e+00 0.000000e+00 0.000000e+00 ... 1.386196e+08 4.322863e+08 1.141594e+05 1.738165e+04 3.800007e+06 64927.125388 True 5595 2115.0 51240.028490
28 Tamaki POLYGON ((1765594.677 5917986.938, 1765609.808... 174.848247 -36.901670 1.896657e+07 7.599913e+06 4.391057e+05 5.160719e+06 1.111391e+05 4.705511e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 9688.801624 True 42189 13551.0 64390.277469
29 Titirangi POLYGON ((1749038.038 5910572.842, 1749034.230... 174.629790 -36.939520 4.058868e+07 1.989760e+07 5.073543e+06 6.196787e+06 3.677952e+06 1.380604e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 8.173086e+06 15542.090769 True 35958 12192.0 80713.729357
30 Upper Harbour Local Board Area MULTIPOLYGON (((1743880.554 5928979.708, 17438... 174.672015 -36.760234 6.973017e+07 9.380759e+06 1.026630e+06 1.234376e+07 1.652101e+06 2.503432e+05 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1.221011e+03 12662.494326 True 53571 17079.0 92354.882984
31 Waiheke MULTIPOLYGON (((1793981.864 5931917.843, 17940... 175.055216 -36.799894 1.547768e+08 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 26689.652804 True 8310 3597.0 55066.946309
32 Waitakere MULTIPOLYGON (((1743890.310 5905057.188, 17438... 174.527874 -36.931281 2.651435e+08 3.041467e+07 5.403257e+06 1.005111e+06 1.438878e+07 0.000000e+00 ... 5.398078e+06 1.009224e+07 7.682505e+06 0.000000e+00 9.088142e+06 22820.718458 True 12477 4449.0 84773.121192
33 Whau MULTIPOLYGON (((1748168.244 5916597.058, 17481... 174.684472 -36.906902 2.682152e+07 8.270683e+06 1.092566e+06 4.710662e+05 3.332548e+06 2.009848e+06 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 9497.105591 True 72585 23928.0 65948.529781

33 rows × 33 columns

In [ ]:
df.drop(columns="geometry").to_csv("output/Local_Area.csv")

Meshblock 2018 dataset:¶

  1. Meshblock numeric code Code
  2. Centroid longitude Centroid_lon
  3. Centroid latitude Centroid_lat
In [ ]:
mb = gpd.read_file("input/statsnzmeshblock-higher-geographies-2018-generalised-FGDB.zip!meshblock-higher-geographies-2018-generalised.gdb")
In [ ]:
mb = mb[
    ((mb.TA2018_V1_00_NAME == "Auckland") | (mb.SA22018_V1_00_NAME.isin(["Mangatangi", "Miranda-Pukorokoro"]))) &
    mb.LANDWATER_NAME.isin(["Mainland", "Island"])]
In [ ]:
mb = mb.rename(columns={"MB2018_V1_00": "Code"})
mb["Centroid_lon"] = mb.centroid.to_crs(epsg=4326).x
mb["Centroid_lat"] = mb.centroid.to_crs(epsg=4326).y
mb
Out[ ]:
Code SA12018_V1_00 SA22018_V1_00 SA22018_V1_00_NAME UR2018_V1_00 UR2018_V1_00_NAME IUR2018_V1_00 IUR2018_V1_00_NAME CB2018_V1_00 CB2018_V1_00_NAME ... WARD2018_V1_00 WARD2018_V1_00_NAME LANDWATER LANDWATER_NAME LAND_AREA_SQ_KM AREA_SQ_KM Shape_Length geometry Centroid_lon Centroid_lat
543 0137200 7001157 110400 Cape Rodney 1098 Other rural Auckland 22 Rural other 07601 Rodney Local Board Area ... 07601 Rodney Ward 11 Island 0.097567 0.097567 1356.404986 MULTIPOLYGON (((1761489.925 5985285.678, 17614... 174.797456 -36.265557
544 0170700 7001317 114300 Gulf Islands 1098 Other rural Auckland 22 Rural other 07602 Hibiscus and Bays Local Board Area ... 07602 Albany Ward 11 Island 0.005545 0.005545 321.185380 MULTIPOLYGON (((1753753.763 5954256.206, 17537... 174.718386 -36.545155
545 0438700 7001130 111800 Barrier Islands 1098 Other rural Auckland 22 Rural other 07608 Great Barrier Local Board Area ... 07605 Waitemata and Gulf Ward 11 Island 70.725594 70.725594 100201.649851 MULTIPOLYGON (((1815954.125 6007877.906, 18159... 175.382085 -36.108549
546 0439306 7001135 111800 Barrier Islands 1109 Tryphena 21 Rural settlement 07608 Great Barrier Local Board Area ... 07605 Waitemata and Gulf Ward 11 Island 0.078233 0.078233 1494.370224 MULTIPOLYGON (((1823569.424 5979782.392, 18235... 175.489541 -36.302663
547 0439307 7001135 111800 Barrier Islands 1109 Tryphena 21 Rural settlement 07608 Great Barrier Local Board Area ... 07605 Waitemata and Gulf Ward 11 Island 0.475337 0.475337 3408.621475 MULTIPOLYGON (((1824128.365 5979223.530, 18242... 175.494343 -36.309033
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
53301 4011883 7001154 110400 Cape Rodney 1098 Other rural Auckland 22 Rural other 07601 Rodney Local Board Area ... 07601 Rodney Ward 12 Mainland 7.680889 7.680889 17076.458542 MULTIPOLYGON (((1756196.931 5982761.262, 17562... 174.752390 -36.303185
53333 4011925 7009199 156900 Baverstock 1108 Auckland 11 Major urban area 07616 Howick Local Board Area ... 07610 Howick Ward 12 Mainland 0.242189 0.242189 2352.598074 MULTIPOLYGON (((1770681.901 5909197.803, 17711... 174.920613 -36.949951
53358 4011969 7010810 168600 Miranda-Pukorokoro 1152 Other rural Hauraki District 22 Rural other 01299 Area Outside Community ... 01201 Plains Ward 12 Mainland 12.056901 12.056901 16956.858556 MULTIPOLYGON (((1803340.448 5889954.878, 18033... 175.282719 -37.140292
53359 4011971 7009313 158600 Ormiston East 1108 Auckland 11 Major urban area 07616 Howick Local Board Area ... 07610 Howick Ward 12 Mainland 0.487587 0.487587 3692.342983 MULTIPOLYGON (((1771223.196 5906518.069, 17715... 174.930444 -36.975090
53360 4011972 7009335 158900 Tuscany Heights 1108 Auckland 11 Major urban area 07616 Howick Local Board Area ... 07610 Howick Ward 12 Mainland 0.178460 0.178460 1798.203501 MULTIPOLYGON (((1772642.183 5906246.394, 17726... 174.940243 -36.976625

13473 rows × 30 columns

In [ ]:
mb = mb.set_index("Code")
  1. Haversine distance from centroid to Skytower Hdist_skytower
In [ ]:
skytower = Point(1757109.809, 5920500.841)
mb["Hdist_skytower"] = mb.centroid.distance(skytower) # meters
mb
Out[ ]:
SA12018_V1_00 SA22018_V1_00 SA22018_V1_00_NAME UR2018_V1_00 UR2018_V1_00_NAME IUR2018_V1_00 IUR2018_V1_00_NAME CB2018_V1_00 CB2018_V1_00_NAME CON2018_V1_00 ... WARD2018_V1_00_NAME LANDWATER LANDWATER_NAME LAND_AREA_SQ_KM AREA_SQ_KM Shape_Length geometry Centroid_lon Centroid_lat Hdist_skytower
Code
0137200 7001157 110400 Cape Rodney 1098 Other rural Auckland 22 Rural other 07601 Rodney Local Board Area 0299 ... Rodney Ward 11 Island 0.097567 0.097567 1356.404986 MULTIPOLYGON (((1761489.925 5985285.678, 17614... 174.797456 -36.265557 64744.057618
0170700 7001317 114300 Gulf Islands 1098 Other rural Auckland 22 Rural other 07602 Hibiscus and Bays Local Board Area 0299 ... Albany Ward 11 Island 0.005545 0.005545 321.185380 MULTIPOLYGON (((1753753.763 5954256.206, 17537... 174.718386 -36.545155 33870.034882
0438700 7001130 111800 Barrier Islands 1098 Other rural Auckland 22 Rural other 07608 Great Barrier Local Board Area 0299 ... Waitemata and Gulf Ward 11 Island 70.725594 70.725594 100201.649851 MULTIPOLYGON (((1815954.125 6007877.906, 18159... 175.382085 -36.108549 99126.852773
0439306 7001135 111800 Barrier Islands 1109 Tryphena 21 Rural settlement 07608 Great Barrier Local Board Area 0299 ... Waitemata and Gulf Ward 11 Island 0.078233 0.078233 1494.370224 MULTIPOLYGON (((1823569.424 5979782.392, 18235... 175.489541 -36.302663 88914.804842
0439307 7001135 111800 Barrier Islands 1109 Tryphena 21 Rural settlement 07608 Great Barrier Local Board Area 0299 ... Waitemata and Gulf Ward 11 Island 0.475337 0.475337 3408.621475 MULTIPOLYGON (((1824128.365 5979223.530, 18242... 175.494343 -36.309033 88749.923755
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4011883 7001154 110400 Cape Rodney 1098 Other rural Auckland 22 Rural other 07601 Rodney Local Board Area 0299 ... Rodney Ward 12 Mainland 7.680889 7.680889 17076.458542 MULTIPOLYGON (((1756196.931 5982761.262, 17562... 174.752390 -36.303185 60497.860816
4011925 7009199 156900 Baverstock 1108 Auckland 11 Major urban area 07616 Howick Local Board Area 0299 ... Howick Ward 12 Mainland 0.242189 0.242189 2352.598074 MULTIPOLYGON (((1770681.901 5909197.803, 17711... 174.920613 -36.949951 18068.596395
4011969 7010810 168600 Miranda-Pukorokoro 1152 Other rural Hauraki District 22 Rural other 01299 Area Outside Community 0303 ... Plains Ward 12 Mainland 12.056901 12.056901 16956.858556 MULTIPOLYGON (((1803340.448 5889954.878, 18033... 175.282719 -37.140292 56540.330975
4011971 7009313 158600 Ormiston East 1108 Auckland 11 Major urban area 07616 Howick Local Board Area 0299 ... Howick Ward 12 Mainland 0.487587 0.487587 3692.342983 MULTIPOLYGON (((1771223.196 5906518.069, 17715... 174.930444 -36.975090 20557.150466
4011972 7009335 158900 Tuscany Heights 1108 Auckland 11 Major urban area 07616 Howick Local Board Area 0299 ... Howick Ward 12 Mainland 0.178460 0.178460 1798.203501 MULTIPOLYGON (((1772642.183 5906246.394, 17726... 174.940243 -36.976625 21315.702128

13473 rows × 30 columns

In [ ]:
mb[mb.Hdist_skytower < 5000].plot(column="Hdist_skytower", legend=True)
plt.title("Meshblocks <5KM from the Skytower")
Out[ ]:
Text(0.5, 1.0, 'Meshblocks <5KM from the Skytower')
  1. Minimum Haversine distance from centroid to coast Hdist_coast
In [ ]:
coastline = gpd.read_file("input/lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip!nz-coastlines-and-islands-polygons-topo-150k.gdb")
In [ ]:
%%time
coastline_shape = coastline.dissolve().boundary.iloc[0]
In [ ]:
%%time
mb["Hdist_coast"] = mb.centroid.distance(coastline_shape)
In [ ]:
mb["Hdist_coast"].describe() # meters
Out[ ]:
count    13473.000000
mean      1610.580308
std       1850.149374
min          0.488582
25%        444.468176
50%       1077.328825
75%       2121.651872
max      23873.710662
Name: Hdist_coast, dtype: float64
In [ ]:
ax = mb.plot(column="Hdist_coast", legend=True)
gpd.clip(coastline, mb.dissolve().envelope).boundary.plot(ax=ax)
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Out[ ]:
<AxesSubplot: >
  1. Manhattan distance from centroid to Skytower Mdist_skytower

OSRM API docs - http://project-osrm.org/docs/v5.24.0/api/#table-service

In [ ]:
len(mb)
Out[ ]:
13473
In [ ]:
BASE_URL = "http://osrm.auckland-cer.cloud.edu.au"
def drive(points, to):
    points = [f"{point.x},{point.y}" for point in points]
    points = ";".join(points)
    result = requests.get(f"{BASE_URL}/table/v1/driving/{to};{points}?destinations=0&annotations=duration,distance")
    return result.json()
In [ ]:
skytower = "174.76218883819053,-36.848429166610735"
In [ ]:
# Make sure OSRM is working
drive(points=mb.centroid.head(1).to_crs(epsg=4326), to=skytower)
Out[ ]:
{'code': 'Ok',
 'sources': [{'hint': 'KDEIgCwxCIALAAAA1AAAANQAAAAdAAAAvNMTQL-rMEIpsi9C9IbCQAUAAABrAAAAaQAAAA8AAAB7AQAAJahqCoW8zf3NqGoK07zN_QYAXwkFi_8F',
   'distance': 17.308342,
   'name': '',
   'location': [174.762021, -36.848507]},
  {'hint': 'H3cJgCF3CYAAAAAALwAAAAAAAAAAAAAAAAAAAC-bnUEAAAAAAAAAAAAAAAAvAAAAAAAAAAAAAAB7AQAAUDdrCnWT1v2QMmsKq6HW_QAA3wkFi_8F',
   'distance': 418.202302,
   'name': '',
   'location': [174.798672, -36.269195]}],
 'destinations': [{'hint': 'KDEIgCwxCIALAAAA1AAAANQAAAAdAAAAvNMTQL-rMEIpsi9C9IbCQAUAAABrAAAAaQAAAA8AAAB7AQAAJahqCoW8zf3NqGoK07zN_QYAXwkFi_8F',
   'distance': 17.308342,
   'name': '',
   'location': [174.762021, -36.848507]}],
 'durations': [[0], [4741.4]],
 'distances': [[0], [83585.9]]}
In [ ]:
%%time
result = drive(points=mb.centroid.to_crs(epsg=4326), to=skytower)
CPU times: user 1.4 s, sys: 27.2 ms, total: 1.43 s
Wall time: 1min 12s
In [ ]:
result.keys()
Out[ ]:
dict_keys(['code', 'sources', 'destinations', 'durations', 'distances'])
In [ ]:
mb["Mdist_skytower"] = [r[0] for r in result["distances"][1:]]
mb["Mdist_skytower"].describe() # Units are meters
Out[ ]:
count     13473.000000
mean      21210.377540
std       15885.697753
min          59.500000
25%       11533.800000
50%       17220.600000
75%       24347.100000
max      136633.200000
Name: Mdist_skytower, dtype: float64
In [ ]:
mb.plot(column="Mdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
mb[mb.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("Meshblocks <5KM driving from the Skytower")
Out[ ]:
Text(0.5, 1.0, 'Meshblocks <5KM driving from the Skytower')
In [ ]:
# Some strange gaps there - let's investigate
points = mb[(mb.Hdist_skytower < 1000) & (mb.Mdist_skytower > 5000)]
points = [f"{point.x},{point.y}" for point in points.centroid.to_crs(epsg=4326)]
points
Out[ ]:
['174.75624867471396,-36.85383185528419',
 '174.75345762242358,-36.85050348371209',
 '174.75551843174853,-36.8526249602678',
 '174.75734772557055,-36.855642008978414']
In [ ]:
routes = []
for point in points:
    route_result = requests.get(f"{BASE_URL}/route/v1/driving/{skytower};{point}?geometries=geojson")
    routes.extend(route_result.json()["routes"])
routes
Out[ ]:
[{'geometry': {'coordinates': [[174.762021, -36.848507],
    [174.762081, -36.848111],
    [174.761663, -36.847994],
    [174.760279, -36.851092],
    [174.756401, -36.856918],
    [174.756298, -36.858244],
    [174.757545, -36.859416],
    [174.761092, -36.859842],
    [174.763064, -36.860822],
    [174.764566, -36.862759],
    [174.766927, -36.864565],
    [174.768415, -36.867436],
    [174.774277, -36.87211],
    [174.774115, -36.872578],
    [174.773385, -36.872143],
    [174.771509, -36.870028],
    [174.768209, -36.867454],
    [174.766746, -36.864588],
    [174.764693, -36.863068],
    [174.76298, -36.861326],
    [174.761243, -36.860494],
    [174.758161, -36.860144],
    [174.756868, -36.859449],
    [174.755729, -36.85724],
    [174.756435, -36.854967],
    [174.756232, -36.853838]],
   'type': 'LineString'},
  'legs': [{'steps': [],
    'distance': 6623.4,
    'duration': 471.2,
    'summary': '',
    'weight': 482.5}],
  'distance': 6623.4,
  'duration': 471.2,
  'weight_name': 'routability',
  'weight': 482.5},
 {'geometry': {'coordinates': [[174.762021, -36.848507],
    [174.761973, -36.848406],
    [174.762081, -36.848111],
    [174.761663, -36.847994],
    [174.760403, -36.850878],
    [174.75828, -36.854101],
    [174.758023, -36.853973],
    [174.756934, -36.853677],
    [174.756692, -36.853485],
    [174.756478, -36.853123],
    [174.756232, -36.85299],
    [174.755149, -36.853046],
    [174.75503, -36.853003],
    [174.754968, -36.852487],
    [174.754131, -36.851451],
    [174.753566, -36.85047]],
   'type': 'LineString'},
  'legs': [{'steps': [],
    'distance': 1487.9,
    'duration': 201.1,
    'summary': '',
    'weight': 212.4}],
  'distance': 1487.9,
  'duration': 201.1,
  'weight_name': 'routability',
  'weight': 212.4},
 {'geometry': {'coordinates': [[174.762021, -36.848507],
    [174.762081, -36.848111],
    [174.760362, -36.847639],
    [174.756384, -36.84814],
    [174.75646, -36.846119],
    [174.751793, -36.844936],
    [174.749101, -36.843285],
    [174.746338, -36.842436],
    [174.744751, -36.840654],
    [174.742077, -36.838893],
    [174.741435, -36.837888],
    [174.74165, -36.836424],
    [174.749967, -36.823771],
    [174.750195, -36.822768],
    [174.749701, -36.81919],
    [174.751533, -36.813923],
    [174.750898, -36.812294],
    [174.753046, -36.811822],
    [174.753968, -36.812071],
    [174.754297, -36.812877],
    [174.753791, -36.813549],
    [174.75206, -36.814361],
    [174.751215, -36.815353],
    [174.750131, -36.819403],
    [174.750332, -36.822928],
    [174.750102, -36.823818],
    [174.741981, -36.836162],
    [174.74164, -36.837484],
    [174.742147, -36.838632],
    [174.744931, -36.840513],
    [174.746304, -36.842152],
    [174.749683, -36.843296],
    [174.752518, -36.845063],
    [174.752984, -36.845821],
    [174.753572, -36.850065],
    [174.755481, -36.852645]],
   'type': 'LineString'},
  'legs': [{'steps': [],
    'distance': 11247.2,
    'duration': 783.1,
    'summary': '',
    'weight': 794.4}],
  'distance': 11247.2,
  'duration': 783.1,
  'weight_name': 'routability',
  'weight': 794.4},
 {'geometry': {'coordinates': [[174.762021, -36.848507],
    [174.761973, -36.848406],
    [174.762081, -36.848111],
    [174.761663, -36.847994],
    [174.760403, -36.850878],
    [174.758622, -36.85365],
    [174.757737, -36.854764],
    [174.757261, -36.855607]],
   'type': 'LineString'},
  'legs': [{'steps': [],
    'distance': 1022.2,
    'duration': 135,
    'summary': '',
    'weight': 146.3}],
  'distance': 1022.2,
  'duration': 135,
  'weight_name': 'routability',
  'weight': 146.3}]
In [ ]:
route_df = pd.read_json(json.dumps(routes))
route_df["geometry"] = route_df['geometry'].apply(shape)
route_df = gpd.GeoDataFrame(route_df)
route_df
Out[ ]:
geometry legs distance duration weight_name weight
0 LINESTRING (174.76202 -36.84851, 174.76208 -36... [{'steps': [], 'distance': 6623.4, 'duration':... 6623.4 471.2 routability 482.5
1 LINESTRING (174.76202 -36.84851, 174.76197 -36... [{'steps': [], 'distance': 1487.9, 'duration':... 1487.9 201.1 routability 212.4
2 LINESTRING (174.76202 -36.84851, 174.76208 -36... [{'steps': [], 'distance': 11247.2, 'duration'... 11247.2 783.1 routability 794.4
3 LINESTRING (174.76202 -36.84851, 174.76197 -36... [{'steps': [], 'distance': 1022.2, 'duration':... 1022.2 135.0 routability 146.3
In [ ]:
ax = mb[mb.Mdist_skytower < 5000].to_crs(epsg=4326).plot(column="Mdist_skytower", legend=True)
route_df[route_df["distance"]>10000].plot(column="distance", legend=True, ax=ax, linewidth=3, cmap="plasma")
Out[ ]:
<AxesSubplot: >
In [ ]:
points = mb[(mb.Hdist_skytower < 1000) & (mb.Mdist_skytower > 5000)]
points = [f"{point.y},{point.x}" for point in points.centroid.to_crs(epsg=4326)]
for point in points:
    print(f"https://map.project-osrm.org/?loc={point}&loc=-36.848429166610735,174.76218883819053&srv=0")
https://map.project-osrm.org/?loc=-36.85383185528419,174.75624867471396&loc=-36.848429166610735,174.76218883819053&srv=0
https://map.project-osrm.org/?loc=-36.85050348371209,174.75345762242358&loc=-36.848429166610735,174.76218883819053&srv=0
https://map.project-osrm.org/?loc=-36.8526249602678,174.75551843174853&loc=-36.848429166610735,174.76218883819053&srv=0
https://map.project-osrm.org/?loc=-36.855642008978414,174.75734772557055&loc=-36.848429166610735,174.76218883819053&srv=0
In [ ]:
%%time
north = drive(points=mb.centroid.translate(yoff=-100).to_crs(epsg=4326), to=skytower)
west = drive(points=mb.centroid.translate(xoff=-100).to_crs(epsg=4326), to=skytower)
east = drive(points=mb.centroid.translate(xoff=100).to_crs(epsg=4326), to=skytower)
south = drive(points=mb.centroid.translate(yoff=100).to_crs(epsg=4326), to=skytower)
CPU times: user 8.78 s, sys: 21.6 ms, total: 8.8 s
Wall time: 4min 48s
In [ ]:
mb["Mdist_skytower_center"] = [r[0] for r in result["distances"][1:]]
mb["Mdist_skytower_north"] = [r[0] for r in north["distances"][1:]]
mb["Mdist_skytower_west"] = [r[0] for r in west["distances"][1:]]
mb["Mdist_skytower_east"] = [r[0] for r in east["distances"][1:]]
mb["Mdist_skytower_south"] = [r[0] for r in south["distances"][1:]]
mb[["Mdist_skytower_center",
    "Mdist_skytower_north",
    "Mdist_skytower_west",
    "Mdist_skytower_east",
    "Mdist_skytower_south"]].describe()
Out[ ]:
Mdist_skytower_center Mdist_skytower_north Mdist_skytower_west Mdist_skytower_east Mdist_skytower_south
count 13473.000000 13473.000000 13473.000000 13473.000000 13473.000000
mean 21210.377540 21231.831062 21204.024983 21208.543769 21172.238098
std 15885.697753 15877.057240 15883.868212 15888.923830 15897.410854
min 59.500000 29.900000 110.700000 155.200000 109.600000
25% 11533.800000 11530.200000 11494.100000 11531.700000 11480.400000
50% 17220.600000 17205.400000 17221.400000 17180.600000 17173.500000
75% 24347.100000 24427.000000 24379.100000 24391.400000 24381.600000
max 136633.200000 136633.200000 136633.200000 136633.200000 136633.200000
In [ ]:
mb["Mdist_skytower"] = mb[[
    "Mdist_skytower_center",
    "Mdist_skytower_north",
    "Mdist_skytower_west",
    "Mdist_skytower_east",
    "Mdist_skytower_south"
]].min(axis=1)
(mb["Mdist_skytower_center"] - mb["Mdist_skytower"]).describe()
Out[ ]:
count    13473.000000
mean       270.188904
std        506.155787
min          0.000000
25%         81.200000
50%        131.500000
75%        260.900000
max      12976.900000
dtype: float64
In [ ]:
mb[mb.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("Meshblocks <5KM driving from the Skytower")
Out[ ]:
Text(0.5, 1.0, 'Meshblocks <5KM driving from the Skytower')
In [ ]:
mb["Mtime_skytower_center"] = [r[0] for r in result["durations"][1:]]
mb["Mtime_skytower_north"] = [r[0] for r in north["durations"][1:]]
mb["Mtime_skytower_west"] = [r[0] for r in west["durations"][1:]]
mb["Mtime_skytower_east"] = [r[0] for r in east["durations"][1:]]
mb["Mtime_skytower_south"] = [r[0] for r in south["durations"][1:]]
display(mb[[
    "Mtime_skytower_center",
    "Mtime_skytower_north",
    "Mtime_skytower_west",
    "Mtime_skytower_east",
    "Mtime_skytower_south"
]].describe())
mb["Mtime_skytower"] = mb[[
    "Mtime_skytower_center",
    "Mtime_skytower_north",
    "Mtime_skytower_west",
    "Mtime_skytower_east",
    "Mtime_skytower_south"
]].min(axis=1)
mb["Mtime_skytower"].describe() # Units are seconds
Mtime_skytower_center Mtime_skytower_north Mtime_skytower_west Mtime_skytower_east Mtime_skytower_south
count 13473.000000 13473.000000 13473.000000 13473.000000 13473.000000
mean 1601.251763 1600.538974 1599.116611 1599.186566 1597.301700
std 3357.815639 3357.480155 3357.857065 3356.292671 3357.474225
min 15.100000 7.200000 26.700000 38.900000 37.900000
25% 867.800000 864.300000 865.700000 863.300000 863.000000
50% 1164.100000 1162.300000 1161.900000 1161.600000 1160.600000
75% 1519.000000 1516.900000 1515.400000 1516.800000 1513.700000
max 70521.800000 70521.800000 70521.800000 70521.800000 70521.800000
Out[ ]:
count    13473.000000
mean      1575.136428
std       3356.504241
min          7.200000
25%        842.000000
50%       1139.700000
75%       1490.000000
max      70521.800000
Name: Mtime_skytower, dtype: float64
In [ ]:
mb[mb.Mtime_skytower < 60*20].plot(column="Mtime_skytower", legend=True)
plt.title("Meshblocks < 20 minutes drive from the Skytower")
Out[ ]:
Text(0.5, 1.0, 'Meshblocks < 20 minutes drive from the Skytower')
  1. Minimum Manhattan distance from centroid to nearest rapid transit stop (Northern busway, rail or ferry terminal). Mdist_rapid_transit
  2. Name of rapid transit stop identified above Mdist_rapid_transit_name
In [ ]:
transit = pd.read_excel("input/Geocoordinates_Direct_Transit_stops_AKL.xlsx")
transit = gpd.GeoDataFrame(transit, geometry=gpd.points_from_xy(transit.Longitude, transit.Latitude), crs="EPSG:4326")
transit
Out[ ]:
Location Latitude Longitude geometry
0 West Harbour -36.810902 174.645571 POINT (174.64557 -36.81090)
1 Hobsonville -36.787563 174.672260 POINT (174.67226 -36.78756)
2 Beach Haven -36.789800 174.678317 POINT (174.67832 -36.78980)
3 Birkenhead -36.822961 174.733882 POINT (174.73388 -36.82296)
4 Northcote -36.826891 174.746329 POINT (174.74633 -36.82689)
5 Bayswater -36.821697 174.766296 POINT (174.76630 -36.82170)
6 Stanley Bay -36.828009 174.781236 POINT (174.78124 -36.82801)
7 Downtown -36.842912 174.766930 POINT (174.76693 -36.84291)
8 Devonport -36.833343 174.795631 POINT (174.79563 -36.83334)
9 Matiatia -36.780617 174.991460 POINT (174.99146 -36.78062)
10 Pine Harbour -36.889582 174.989955 POINT (174.98996 -36.88958)
11 Half Moon Bay -36.879913 174.897656 POINT (174.89766 -36.87991)
12 Gulf Harbour -36.624279 174.787779 POINT (174.78778 -36.62428)
13 Avondale -36.897302 174.699092 POINT (174.69909 -36.89730)
14 Baldwin Avenue -36.877694 174.720462 POINT (174.72046 -36.87769)
15 Britomart -36.844177 174.767766 POINT (174.76777 -36.84418)
16 Ellerslie -36.898225 174.808085 POINT (174.80809 -36.89822)
17 Fruitvale Road -36.910636 174.667006 POINT (174.66701 -36.91064)
18 Glen Eden -36.910149 174.652854 POINT (174.65285 -36.91015)
19 Glen Innes -36.878788 174.854118 POINT (174.85412 -36.87879)
20 Grafton -36.865501 174.770008 POINT (174.77001 -36.86550)
21 Greenlane -36.889649 174.797444 POINT (174.79744 -36.88965)
22 Henderson -36.880903 174.630923 POINT (174.63092 -36.88090)
23 Homai -37.013442 174.874655 POINT (174.87465 -37.01344)
24 Kingsland -36.872443 174.744520 POINT (174.74452 -36.87244)
25 Manukau -36.993769 174.877389 POINT (174.87739 -36.99377)
26 Manurewa -37.023261 174.896139 POINT (174.89614 -37.02326)
27 Meadowbank -36.866298 174.820777 POINT (174.82078 -36.86630)
28 Middlemore -36.963044 174.838964 POINT (174.83896 -36.96304)
29 Morningside -36.874913 174.735210 POINT (174.73521 -36.87491)
30 Mt Eden -36.867955 174.758970 POINT (174.75897 -36.86796)
31 Mt. Albert -36.884793 174.714007 POINT (174.71401 -36.88479)
32 New Lynn -36.909357 174.684020 POINT (174.68402 -36.90936)
33 Newmarket -36.869622 174.778879 POINT (174.77888 -36.86962)
34 Onehunga -36.925383 174.786012 POINT (174.78601 -36.92538)
35 Orakei -36.862352 174.809466 POINT (174.80947 -36.86235)
36 Otahuhu -36.946888 174.833261 POINT (174.83326 -36.94689)
37 Panmure -36.898136 174.849269 POINT (174.84927 -36.89814)
38 Papatoetoe -36.977583 174.849376 POINT (174.84938 -36.97758)
39 Papakura -37.064926 174.946311 POINT (174.94631 -37.06493)
40 Parnell -36.854689 174.777457 POINT (174.77746 -36.85469)
41 Penrose -36.910093 174.815687 POINT (174.81569 -36.91009)
42 Puhinui -36.989788 174.856028 POINT (174.85603 -36.98979)
43 Pukekohe -37.203246 174.910155 POINT (174.91016 -37.20325)
44 Ranui -36.867874 174.603303 POINT (174.60330 -36.86787)
45 Remuera -36.881313 174.785404 POINT (174.78540 -36.88131)
46 Sturges Road -36.873433 174.620874 POINT (174.62087 -36.87343)
47 Sunnyvale -36.896779 174.631982 POINT (174.63198 -36.89678)
48 Swanson -36.866032 174.576258 POINT (174.57626 -36.86603)
49 Sylvia Park -36.914619 174.842589 POINT (174.84259 -36.91462)
50 Takanini -37.041127 174.919446 POINT (174.91945 -37.04113)
51 Te Mahia -37.031118 174.906152 POINT (174.90615 -37.03112)
52 Te Papapa -36.920079 174.801432 POINT (174.80143 -36.92008)
53 Hibiscus Coast Bus Station -36.624647 174.667158 POINT (174.66716 -36.62465)
54 Constellation Bus Station -36.752014 174.728166 POINT (174.72817 -36.75201)
55 Sunnynook Bus Station -36.761481 174.737999 POINT (174.73800 -36.76148)
56 Smales Farm Bus Station -36.784523 174.751077 POINT (174.75108 -36.78452)
57 Akoranga Bus Station -36.797232 174.760938 POINT (174.76094 -36.79723)
In [ ]:
len(mb)
Out[ ]:
13473
In [ ]:
%%time
def drive(from_points, to_points):
    # Drive distance and time these meshblock centroids to all 58 rapid transit stops
    from_points_s = ";".join([f"{point.x},{point.y}" for point in from_points])
    from_indices = ";".join([str(i) for i in range(len(from_points))])
    to_points_s = ";".join([f"{point.x},{point.y}" for point in to_points])
    to_indices = ";".join([str(i + len(from_points)) for i in range(len(to_points))])
    result = requests.get(f"{BASE_URL}/table/v1/driving/{from_points_s};{to_points_s}?sources={from_indices}&destinations={to_indices}&annotations=duration,distance")
    return result.json()
result = drive(from_points=mb.centroid.to_crs(epsg=4326), to_points=transit.geometry.to_crs(epsg=4326))
CPU times: user 3.78 s, sys: 79.2 ms, total: 3.86 s
Wall time: 33.8 s
In [ ]:
min_indices = np.argmin(result["distances"], axis=1)
mb["Mdist_rapid_transit"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mtime_rapid_transit"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mdist_rapid_transit_name"] = list(transit.Location[min_indices])
In [ ]:
mb.Mdist_rapid_transit_name.value_counts()
Out[ ]:
Constellation Bus Station     1006
Hibiscus Coast Bus Station     862
Half Moon Bay                  718
Pukekohe                       538
Papakura                       508
Manukau                        503
Glen Innes                     424
Onehunga                       420
Manurewa                       378
Kingsland                      371
Mt. Albert                     346
West Harbour                   332
Glen Eden                      326
Middlemore                     314
Avondale                       304
Henderson                      288
Papatoetoe                     286
Fruitvale Road                 248
Britomart                      246
Otahuhu                        246
Morningside                    227
Beach Haven                    223
Akoranga Bus Station           223
Sunnyvale                      219
Sylvia Park                    218
Mt Eden                        216
Smales Farm Bus Station        214
Ranui                          208
New Lynn                       202
Gulf Harbour                   193
Newmarket                      185
Orakei                         182
Sturges Road                   177
Homai                          154
Birkenhead                     147
Matiatia                       144
Takanini                       128
Ellerslie                      125
Panmure                        122
Swanson                        121
Meadowbank                     118
Devonport                      115
Grafton                        101
Te Papapa                       96
Bayswater                       95
Remuera                         91
Pine Harbour                    90
Parnell                         90
Puhinui                         83
Penrose                         81
Baldwin Avenue                  68
Northcote                       68
Hobsonville                     56
Stanley Bay                     15
Te Mahia                        11
Sunnynook Bus Station            2
Downtown                         1
Name: Mdist_rapid_transit_name, dtype: int64
In [ ]:
ax = mb.to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
In [ ]:
ax = mb[mb.Mdist_rapid_transit < 5000].to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
  1. Manhattan distance from centroid to nearest motorway on-ramp Mdist_onramp
  2. Name or other identifier of motorway onramp identified above Mdist_onramp_name
In [ ]:
onramps = gpd.read_file("input/kx-nz-state-highway-on-ramps-off-ramps-SHP.zip")
onramps = gpd.clip(onramps.to_crs(mb.crs), mb)
onramps
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Out[ ]:
ID ROADID SH INTERCHANG DISPLACEME RAMPNO LENGTH DESCRIPTIO geometry
110 2577.0 2577 016 0004 0.00 1 120.0 016-0000/07.98-X8-R5-OFF LINESTRING Z (1752063.871 5917928.917 0.000, 1...
64 243.0 243 016 0021 0.00 1 434.0 016-0000/08.66-X8-R2-ON LINESTRING Z (1756258.136 5918885.543 0.000, 1...
66 242.0 242 016 0020 0.00 1 548.0 016-0000/08.53-X8-R4-ON LINESTRING Z (1757391.210 5918772.795 0.000, 1...
103 2612.0 2612 016 0006 0.00 1 57.0 016-0000/08.95-X8-R6-OFF LINESTRING Z (1756746.516 5919867.854 0.000, 1...
59 244.0 244 016 0022 0.00 1 748.0 016-0000/08.95-X8-R3-OFF LINESTRING Z (1756301.521 5918962.985 0.000, 1...
... ... ... ... ... ... ... ... ... ...
377 6297638.0 3167 01N 0389 NaN 3 256.0 01N-0389-R3 LINESTRING Z (1759980.354 5916071.625 0.000, 1...
383 6297630.0 3165 01N 0389 NaN 1 244.0 01N-0389-R1 LINESTRING Z (1758616.127 5917564.314 0.000, 1...
376 6297639.0 3168 01N 0389 NaN 4 290.0 01N-0389-R4 LINESTRING Z (1758109.827 5917758.328 0.000, 1...
381 6297613.0 3163 01N 0381 NaN 1 676.0 01N-0381-R1 LINESTRING Z (1763894.661 5912486.002 0.000, 1...
378 6297619.0 3164 01N 0381 NaN 2 933.0 01N-0381-R2 LINESTRING Z (1750801.737 5955470.851 0.000, 1...

258 rows × 9 columns

In [ ]:
# Filter out offramps
onramps = onramps[~onramps.DESCRIPTIO.str.contains("OFF")]
onramps
Out[ ]:
ID ROADID SH INTERCHANG DISPLACEME RAMPNO LENGTH DESCRIPTIO geometry
64 243.0 243 016 0021 0.00 1 434.0 016-0000/08.66-X8-R2-ON LINESTRING Z (1756258.136 5918885.543 0.000, 1...
66 242.0 242 016 0020 0.00 1 548.0 016-0000/08.53-X8-R4-ON LINESTRING Z (1757391.210 5918772.795 0.000, 1...
51 250.0 250 016 0026 0.00 1 437.0 016-0007/01.45-D-ON LINESTRING Z (1756469.230 5920115.190 0.000, 1...
55 248.0 248 016 0024 0.00 1 218.0 016-0007/02.68-I-ON LINESTRING Z (1757759.896 5919696.446 0.000, 1...
211 260.0 260 016 0036 0.00 1 201.0 016-0007/08.30-D-ON LINESTRING Z (1757541.951 5919501.822 0.000, 1...
... ... ... ... ... ... ... ... ... ...
377 6297638.0 3167 01N 0389 NaN 3 256.0 01N-0389-R3 LINESTRING Z (1759980.354 5916071.625 0.000, 1...
383 6297630.0 3165 01N 0389 NaN 1 244.0 01N-0389-R1 LINESTRING Z (1758616.127 5917564.314 0.000, 1...
376 6297639.0 3168 01N 0389 NaN 4 290.0 01N-0389-R4 LINESTRING Z (1758109.827 5917758.328 0.000, 1...
381 6297613.0 3163 01N 0381 NaN 1 676.0 01N-0381-R1 LINESTRING Z (1763894.661 5912486.002 0.000, 1...
378 6297619.0 3164 01N 0381 NaN 2 933.0 01N-0381-R2 LINESTRING Z (1750801.737 5955470.851 0.000, 1...

175 rows × 9 columns

In [ ]:
onramps["has_on"] = onramps.DESCRIPTIO.str.contains("ON").astype(str)
onramps.plot(column="has_on", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
# Include Maioro road onramps for 2018 datasets
maioro = gpd.GeoDataFrame({
    "DESCRIPTIO": ["Maioro street southbound", "Maioro street northbound"]
}, geometry=gpd.GeoSeries([
    Point(174.723958, -36.903573),
    Point(174.722877,-36.903690)
], crs=4326).to_crs(onramps.crs))
maioro
Out[ ]:
DESCRIPTIO geometry
0 Maioro street southbound POINT (1753591.008 5914436.768)
1 Maioro street northbound POINT (1753494.457 5914425.528)
In [ ]:
onramps2018 = onramps.append(maioro)
onramps2018
<string>:1: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
Out[ ]:
ID ROADID SH INTERCHANG DISPLACEME RAMPNO LENGTH DESCRIPTIO geometry has_on
64 243.0 243 016 0021 0.00 1 434.0 016-0000/08.66-X8-R2-ON LINESTRING Z (1756258.136 5918885.543 0.000, 1... True
66 242.0 242 016 0020 0.00 1 548.0 016-0000/08.53-X8-R4-ON LINESTRING Z (1757391.210 5918772.795 0.000, 1... True
51 250.0 250 016 0026 0.00 1 437.0 016-0007/01.45-D-ON LINESTRING Z (1756469.230 5920115.190 0.000, 1... True
55 248.0 248 016 0024 0.00 1 218.0 016-0007/02.68-I-ON LINESTRING Z (1757759.896 5919696.446 0.000, 1... True
211 260.0 260 016 0036 0.00 1 201.0 016-0007/08.30-D-ON LINESTRING Z (1757541.951 5919501.822 0.000, 1... True
... ... ... ... ... ... ... ... ... ... ...
376 6297639.0 3168 01N 0389 NaN 4 290.0 01N-0389-R4 LINESTRING Z (1758109.827 5917758.328 0.000, 1... False
381 6297613.0 3163 01N 0381 NaN 1 676.0 01N-0381-R1 LINESTRING Z (1763894.661 5912486.002 0.000, 1... False
378 6297619.0 3164 01N 0381 NaN 2 933.0 01N-0381-R2 LINESTRING Z (1750801.737 5955470.851 0.000, 1... False
0 NaN NaN NaN NaN NaN NaN NaN Maioro street southbound POINT (1753591.008 5914436.768) NaN
1 NaN NaN NaN NaN NaN NaN NaN Maioro street northbound POINT (1753494.457 5914425.528) NaN

177 rows × 10 columns

In [ ]:
%%time
result = drive(from_points=mb.centroid.to_crs(epsg=4326), to_points=onramps2018.centroid.to_crs(epsg=4326))
CPU times: user 8.79 s, sys: 166 ms, total: 8.96 s
Wall time: 1min 2s
In [ ]:
len(result["distances"]), len(result["distances"][0])
Out[ ]:
(13473, 177)
In [ ]:
min_indices = np.argmin(result["distances"], axis=1)
mb["Mdist_onramp"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mtime_onramp"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mdist_onramp_name"] = list(onramps2018.DESCRIPTIO.iloc[min_indices])
In [ ]:
mb.Mdist_onramp_name.value_counts()
Out[ ]:
Maioro street northbound     795
01N-0381-R1                  777
01N-2398/00.07-X398-R1-ON    548
01N-2414/12.16-X426-R2-ON    517
01N-2461/00.17-X462-R2-ON    512
                            ... 
01N-2414/02.55-X417-R4-ON      1
002-0009-R3                    1
01N-0441-R4                    1
016-0007/04.31-D-ON            1
01N-2431/07.81-X438-R2-ON      1
Name: Mdist_onramp_name, Length: 119, dtype: int64
In [ ]:
ax = mb.plot(column="Mdist_onramp", legend=True)
onramps2018.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
In [ ]:
ax = mb[mb.Mdist_onramp < 5000].plot(column="Mdist_onramp", legend=True)
onramps.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
  1. Area of Meshblock 2018 (land only) Area
  2. Area zoned Residential under AUP Residential_area
  3. Area zoned Residential - Single House under AUP SH_area
  4. Area zoned Residential - Mixed Housing Suburban under AUP MHS_area
  5. Area zoned Residential - Mixed Housing Urban under AUP MHU_area
  6. Area zoned Residential - Terrace Housing and Apartments under AUP THA_area
  7. Area zoned Residential – Large Lot under AUP LL_area
  8. Area zoned Residential – Rural and Coastal Settlement under AUP RCS_area
  9. Area zoned Rural - Waitakere Ranges under AUP WR_area.
  10. Area zoned Future Urban under AUP FU_area
  11. Area zones Hauraki Gulf Islands under AUP HGI_area
  12. Area zoned Business under AUP Business_area
  13. Area zoned Rural under AUP Rural Rural_area
  14. Area zoned as Open Space under AUP maps Open_area
  15. Area zoned as Roads under the Unitary Plan Roads_area
  16. Area zoned as Strategic Infrastructure Corridor InfraCorr_area
  17. Area zoned as Green Infrastructure Corridor under the Unitary Plan GrInfraCorr_area
In [ ]:
all(mb.LAND_AREA_SQ_KM == mb.AREA_SQ_KM)
Out[ ]:
True
In [ ]:
mb = mb.rename(columns={"LAND_AREA_SQ_KM": "Area"})
In [ ]:
%%time
for k,v in tqdm(zones_of_interest.items()):
    subset = zones[zones.ZONE_resol.str.startswith(k)] # Just the matched zones (residential, business, rural etc)
    print(k, len(subset))
    clipped = gpd.clip(mb, subset) # Clip the local areas to the matched zones
    mb[v] = clipped.area # Store the resulting area. Unit is m²
  0%|          | 0/23 [00:00<?, ?it/s]
Residential 22398
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Single House Zone 3766
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Suburban Zone 9775
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Urban Zone 5864
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Terrace Housing and Apartment Building Zone 2134
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Large Lot Zone 379
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Rural and Coastal Settlement Zone 480
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Waitakere Ranges Zone 172
Future Urban Zone 282
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Hauraki Gulf Islands 221
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Business 3237
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural 2750
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Open Space 6667
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Road 47012
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Strategic Transport Corridor Zone 4215
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Green Infrastructure Corridor 6
Rural - Waitakere Ranges 172
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Waitakere Foothills 44
Rural - Rural Coastal 768
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Production 1025
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Conservation 71
Rural - Mixed Rural 344
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Countryside Living 326
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
CPU times: user 32min 12s, sys: 24.6 s, total: 32min 37s
Wall time: 32min 41s
In [ ]:
mb = mb.fillna(0)
  1. Indicator (0 or 1) for whether the meshblock is on coastline Coast_indicator
In [ ]:
coastline = gpd.read_file("input/lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip!nz-coastlines-and-islands-polygons-topo-150k.gdb")
In [ ]:
%%time
coastline = gpd.clip(coastline, mb.dissolve().envelope)
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
CPU times: user 2.5 s, sys: 80 ms, total: 2.58 s
Wall time: 2.58 s
In [ ]:
%%time
coastline = coastline.dissolve().boundary.buffer(100)
coastline.plot()
CPU times: user 15.3 s, sys: 220 ms, total: 15.5 s
Wall time: 15.4 s
Out[ ]:
<AxesSubplot: >
In [ ]:
coastline = coastline.iloc[0]
In [ ]:
%%time
mb["Coast_indicator"] = mb.geometry.progress_apply(lambda poly: coastline.intersects(poly))
  0%|          | 0/13473 [00:00<?, ?it/s]
CPU times: user 12min 46s, sys: 1.51 s, total: 12min 47s
Wall time: 12min 43s
In [ ]:
mb.plot(column="Coast_indicator", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Total population from 2018 census Census2018_population
In [ ]:
# Note that this is meshblock 2020, which is not ideal, but there doesn't seem to be any changes in the Auckland region between 2018 and 2020, so it's probably fine
pop = pd.read_csv("input/2018-census-electoral-population-meshblock-2020-data.csv", index_col=0)
pop
Out[ ]:
General_Electoral_Population Maori_Electoral_Population GED2020_V1_00 GED2020_V1_00_NAME GED2020_V1_00_NAME_ASCII MED2020_V1_00 MED2020_V1_00_NAME MED2020_V1_00_NAME_ASCII LAND_AREA_SQ_KM AREA_SQ_KM
MB2020_V2_00
100 -999 9 32 Northland Northland 5 Te Tai Tokerau Te Tai Tokerau 157.497825 157.497825
200 9 66 32 Northland Northland 5 Te Tai Tokerau Te Tai Tokerau 120.503770 120.503770
300 12 48 32 Northland Northland 5 Te Tai Tokerau Te Tai Tokerau 7.481859 7.481859
400 6 9 32 Northland Northland 5 Te Tai Tokerau Te Tai Tokerau 83.342952 83.342952
501 -999 -999 32 Northland Northland 5 Te Tai Tokerau Te Tai Tokerau 0.000000 63.825713
... ... ... ... ... ... ... ... ... ... ...
4012026 24 -999 60 Wellington Central Wellington Central 6 Te Tai Tonga Te Tai Tonga 8.301605 8.301605
4012027 108 6 56 Waikato Waikato 1 Hauraki-Waikato Hauraki-Waikato 5.064385 5.064385
4012028 57 -999 51 Taupō Taupo 1 Hauraki-Waikato Hauraki-Waikato 2.612804 2.612804
4012029 -999 -999 47 Taieri Taieri 6 Te Tai Tonga Te Tai Tonga 0.000000 143.908480
4012030 -999 -999 8 Dunedin Dunedin 6 Te Tai Tonga Te Tai Tonga 0.000000 1016.346178

53582 rows × 10 columns

In [ ]:
pop.General_Electoral_Population = pop.General_Electoral_Population.replace(-999, np.nan)
In [ ]:
mb["Census2018_population"] = list(pop.General_Electoral_Population[mb.index.astype(int)])
display(mb["Census2018_population"].describe())
mb.plot(column="Census2018_population", legend=True)
count    12914.000000
mean       113.633886
std         63.165389
min          6.000000
25%         72.000000
50%        108.000000
75%        147.000000
max       1029.000000
Name: Census2018_population, dtype: float64
Out[ ]:
<AxesSubplot: >
  1. Number of dwellings from 2018 census Census2018_dwellings
  2. Average Household Income from 2018 census Census2018_avg_HH_income
  3. Median Household Income from 2018 census Census2018_med_HH_income
In [ ]:
# Can't do this one due to missing data
In [ ]:
 
In [ ]:
mb
Out[ ]:
SA12018_V1_00 SA22018_V1_00 SA22018_V1_00_NAME UR2018_V1_00 UR2018_V1_00_NAME IUR2018_V1_00 IUR2018_V1_00_NAME CB2018_V1_00 CB2018_V1_00_NAME CON2018_V1_00 ... GrInfraCorr_area RWR_area RWF_area RC_area RP_area RCZ_area RMU_area RCL_area Coast_indicator Census2018_population
Code
0137200 7001157 110400 Cape Rodney 1098 Other rural Auckland 22 Rural other 07601 Rodney Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 0.000000 True NaN
0170700 7001317 114300 Gulf Islands 1098 Other rural Auckland 22 Rural other 07602 Hibiscus and Bays Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 0.000000 True NaN
0438700 7001130 111800 Barrier Islands 1098 Other rural Auckland 22 Rural other 07608 Great Barrier Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 0.000000 True 51.0
0439306 7001135 111800 Barrier Islands 1109 Tryphena 21 Rural settlement 07608 Great Barrier Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 0.000000 True 18.0
0439307 7001135 111800 Barrier Islands 1109 Tryphena 21 Rural settlement 07608 Great Barrier Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 0.000000 True 48.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4011883 7001154 110400 Cape Rodney 1098 Other rural Auckland 22 Rural other 07601 Rodney Local Board Area 0299 ... 0.0 0.0 0.0 1.361935e+06 0.0 0.0 0.0 0.000000 True 102.0
4011925 7009199 156900 Baverstock 1108 Auckland 11 Major urban area 07616 Howick Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 0.000000 False 132.0
4011969 7010810 168600 Miranda-Pukorokoro 1152 Other rural Hauraki District 22 Rural other 01299 Area Outside Community 0303 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 0.000000 True 33.0
4011971 7009313 158600 Ormiston East 1108 Auckland 11 Major urban area 07616 Howick Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 655086.180072 False 81.0
4011972 7009335 158900 Tuscany Heights 1108 Auckland 11 Major urban area 07616 Howick Local Board Area 0299 ... 0.0 0.0 0.0 0.000000e+00 0.0 0.0 0.0 284257.208095 False 66.0

13473 rows × 74 columns

In [ ]:
mb.drop(columns="geometry").to_csv("output/2018_Meshblocks.csv")

Statistical Area 2 2018 dataset¶

  1. Name (string is fine) Name
  2. Numeric code Code
  3. Centroid longitude Centroid_lon
  4. Centroid latitude Centroid_lat
In [ ]:
sa2 = gpd.read_file("input/statsnzstatistical-area-2-higher-geographies-2018-clipped-generalis-FGDB.zip!statistical-area-2-higher-geographies-2018-clipped-generalis.gdb")
sa2 = sa2[(sa2.TA2018_V1_00_NAME == "Auckland") | sa2.SA22018_V1_00_NAME.isin(["Mangatangi", "Miranda-Pukorokoro"])]
sa2
Out[ ]:
SA22018_V1_00 SA22018_V1_00_NAME REGC2018_V1_00 REGC2018_V1_00_NAME TA2018_V1_00 TA2018_V1_00_NAME LAND_AREA_SQ_KM AREA_SQ_KM Shape_Length geometry
33 110900 Dome Valley-Matakana 02 Auckland Region 076 Auckland 84.749966 84.749966 70031.926112 MULTIPOLYGON (((1749212.212 5981874.734, 17492...
34 111100 Warkworth West 02 Auckland Region 076 Auckland 11.359752 11.359752 22629.664017 MULTIPOLYGON (((1748589.106 5974509.939, 17485...
35 111200 Puhoi Valley 02 Auckland Region 076 Auckland 236.529965 236.529965 142134.544465 MULTIPOLYGON (((1740248.959 5974374.891, 17402...
36 112600 Waikoukou Valley 02 Auckland Region 076 Auckland 52.854583 52.854583 42565.729322 MULTIPOLYGON (((1735693.112 5942203.564, 17359...
37 112800 Hatfields Beach 02 Auckland Region 076 Auckland 0.923255 0.923255 4314.440531 MULTIPOLYGON (((1750981.811 5952164.661, 17512...
... ... ... ... ... ... ... ... ... ... ...
1061 165800 Rooseville Park 02 Auckland Region 076 Auckland 1.345809 1.345809 6010.945714 MULTIPOLYGON (((1770089.518 5882192.248, 17701...
1062 166000 Pukekohe Central 02 Auckland Region 076 Auckland 2.939129 2.939129 9211.796424 MULTIPOLYGON (((1769469.158 5881504.407, 17694...
1063 166300 Bombay Hills 02 Auckland Region 076 Auckland 31.682020 31.682020 37482.345738 MULTIPOLYGON (((1777896.083 5888522.045, 17779...
1064 166400 Ararimu 02 Auckland Region 076 Auckland 91.308241 91.308241 57552.107386 MULTIPOLYGON (((1786544.313 5891035.131, 17865...
1079 168600 Miranda-Pukorokoro 03 Waikato Region 012 Hauraki District 81.340404 81.340404 59717.399740 MULTIPOLYGON (((1803927.880 5898880.697, 18039...

558 rows × 10 columns

In [ ]:
sa2 = sa2.rename(columns={"SA22018_V1_00_NAME": "Name", "SA22018_V1_00": "Code"})
sa2["Centroid_lon"] = sa2.centroid.to_crs(epsg=4326).x
sa2["Centroid_lat"] = sa2.centroid.to_crs(epsg=4326).y
sa2
Out[ ]:
Code Name REGC2018_V1_00 REGC2018_V1_00_NAME TA2018_V1_00 TA2018_V1_00_NAME LAND_AREA_SQ_KM AREA_SQ_KM Shape_Length geometry Centroid_lon Centroid_lat
33 110900 Dome Valley-Matakana 02 Auckland Region 076 Auckland 84.749966 84.749966 70031.926112 MULTIPOLYGON (((1749212.212 5981874.734, 17492... 174.654164 -36.346613
34 111100 Warkworth West 02 Auckland Region 076 Auckland 11.359752 11.359752 22629.664017 MULTIPOLYGON (((1748589.106 5974509.939, 17485... 174.651601 -36.388932
35 111200 Puhoi Valley 02 Auckland Region 076 Auckland 236.529965 236.529965 142134.544465 MULTIPOLYGON (((1740248.959 5974374.891, 17402... 174.624752 -36.468509
36 112600 Waikoukou Valley 02 Auckland Region 076 Auckland 52.854583 52.854583 42565.729322 MULTIPOLYGON (((1735693.112 5942203.564, 17359... 174.515741 -36.709892
37 112800 Hatfields Beach 02 Auckland Region 076 Auckland 0.923255 0.923255 4314.440531 MULTIPOLYGON (((1750981.811 5952164.661, 17512... 174.689356 -36.570019
... ... ... ... ... ... ... ... ... ... ... ... ...
1061 165800 Rooseville Park 02 Auckland Region 076 Auckland 1.345809 1.345809 6010.945714 MULTIPOLYGON (((1770089.518 5882192.248, 17701... 174.913076 -37.196977
1062 166000 Pukekohe Central 02 Auckland Region 076 Auckland 2.939129 2.939129 9211.796424 MULTIPOLYGON (((1769469.158 5881504.407, 17694... 174.913325 -37.208920
1063 166300 Bombay Hills 02 Auckland Region 076 Auckland 31.682020 31.682020 37482.345738 MULTIPOLYGON (((1777896.083 5888522.045, 17779... 175.002256 -37.175368
1064 166400 Ararimu 02 Auckland Region 076 Auckland 91.308241 91.308241 57552.107386 MULTIPOLYGON (((1786544.313 5891035.131, 17865... 175.082470 -37.146862
1079 168600 Miranda-Pukorokoro 03 Waikato Region 012 Hauraki District 81.340404 81.340404 59717.399740 MULTIPOLYGON (((1803927.880 5898880.697, 18039... 175.276113 -37.113549

558 rows × 12 columns

  1. Local Area in which the centroid is located Centroid_local_area
In [ ]:
sa2["Centroid_local_area"] = sa2.representative_point().apply(lambda point: df.Name[df.contains(point)].iloc[0] if any(df.contains(point)) else np.nan)
sa2["Centroid_local_area"].value_counts()
Out[ ]:
Henderson-Massey                    37
Auckland Central                    32
Beach Haven-Birkenhead-Northcote    28
Manurewa                            28
Orakei                              27
Mangere-Otahuhu                     26
Whau                                26
Botany                              23
Upper Harbour Local Board Area      22
Papakura                            22
Hibiscus Coast                      22
Puketapapa                          20
Devonport-Takapuna                  19
Franklin-Pukekohe                   17
Mt Albert                           16
Tamaki                              16
Papatoetoe                          16
Mt Eden                             15
East Coast Bays                     15
Pakuranga                           14
Rodney-Helensville                  13
Titirangi                           12
Howick                              12
Franklin-Beachlands-Hunua           12
Maungakiekie                        11
Otara                               10
Rodney-Warkworth                     9
Waitakere                            9
Franklin-Waiuku                      7
Waiheke                              7
Rodney-Kumeu-Riverhead               5
Rodney-Dairy Flat                    4
Rodney-Wellsford                     4
Name: Centroid_local_area, dtype: int64
In [ ]:
sa2[pd.isna(sa2.Centroid_local_area)]
Out[ ]:
Code Name REGC2018_V1_00 REGC2018_V1_00_NAME TA2018_V1_00 TA2018_V1_00_NAME LAND_AREA_SQ_KM AREA_SQ_KM Shape_Length geometry Centroid_lon Centroid_lat Centroid_local_area
168 169800 Mangatangi 03 Waikato Region 013 Waikato District 257.805407 257.805407 136907.044348 MULTIPOLYGON (((1792445.658 5901172.505, 17925... 175.175802 -37.155006 NaN
629 111800 Barrier Islands 02 Auckland Region 076 Auckland 320.414101 320.414101 371260.805871 MULTIPOLYGON (((1815954.125 6007877.906, 18159... 175.387745 -36.198250 NaN
  1. Haversine distance to Skytower from centroid Hdist_skytower
In [ ]:
skytower = Point(1757109.809, 5920500.841) # in NZGD2000 projection
In [ ]:
sa2["Hdist_skytower"] = sa2.centroid.distance(skytower)
In [ ]:
sa2.plot(column="Hdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Minimum Haversine distance from centroid to motorway Hdist_motorway
In [ ]:
mway = gpd.read_file("input/lds-nz-road-centrelines-topo-150k-FGDB.zip!nz-road-centrelines-topo-150k.gdb")
mway = mway[~pd.isna(mway.hway_num)]
mway
Out[ ]:
t50_fid name_ascii macronated name hway_num rna_sufi lane_count way_count status surface geometry
46 100120164 OHURA ROAD N OHURA ROAD 43 3063799 2 NaN NaN sealed MULTILINESTRING ((1726407.913 5648240.420, 172...
56 100047464 STATE HIGHWAY 27 N STATE HIGHWAY 27 27 3031731 2 NaN NaN sealed MULTILINESTRING ((1844110.982 5802925.948, 184...
62 100047472 STATE HIGHWAY 29A N STATE HIGHWAY 29A 29A 3025693 2 NaN NaN sealed MULTILINESTRING ((1876759.340 5818523.003, 187...
68 100047481 STATE HIGHWAY 2 N STATE HIGHWAY 2 2 3045160 2 NaN NaN sealed MULTILINESTRING ((1875605.931 5823398.039, 187...
77 100089761 WEST COAST ROAD N WEST COAST ROAD 73 3072232 2 NaN NaN sealed MULTILINESTRING ((1490507.178 5234796.972, 149...
... ... ... ... ... ... ... ... ... ... ... ...
138626 100121061 STATE HIGHWAY 5 N STATE HIGHWAY 5 5 3068040 2 NaN NaN sealed MULTILINESTRING ((1884714.508 5730000.000, 188...
138635 100121070 CHRISTCHURCH SOUTHERN MOTORWAY N CHRISTCHURCH SOUTHERN MOTORWAY 76 3061191 4 NaN NaN sealed MULTILINESTRING ((1555118.439 5176036.767, 155...
138636 100121071 WESTERN BELFAST BYPASS N WESTERN BELFAST BYPASS 1 3079158 4 NaN NaN sealed MULTILINESTRING ((1567931.555 5188634.481, 156...
138637 100121072 CHRISTCHURCH NORTHERN MOTORWAY N CHRISTCHURCH NORTHERN MOTORWAY 74 0 4 NaN NaN sealed MULTILINESTRING ((1571390.312 5190959.558, 157...
138646 100121096 RUSSLEY ROAD N RUSSLEY ROAD 1 3071341 4 NaN NaN sealed MULTILINESTRING ((1563395.550 5183811.195, 156...

2633 rows × 11 columns

In [ ]:
%%time
sa2["Hdist_motorway"] = sa2.centroid.distance(mway.dissolve().geometry[0])
ax = sa2.plot(column="Hdist_motorway", legend=True)
gpd.clip(mway, sa2.envelope).plot(ax=ax, color="red")
CPU times: user 877 ms, sys: 140 ms, total: 1.02 s
Wall time: 872 ms
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Out[ ]:
<AxesSubplot: >
  1. Minimum Haversine distance from centroid to rail line Hdist_rail
In [ ]:
rail = gpd.read_file("input/lds-nz-railway-centrelines-topo-150k-SHP.zip")
rail
Out[ ]:
t50_fid name_ascii macronated name status track_type rway_use veh_type geometry
0 100120519 PALMERSTON NORTH - GISBORNE LINE N PALMERSTON NORTH - GISBORNE LINE disused single NaN NaN LINESTRING (2026018.548 5694000.000, 2026005.7...
1 7927728 NaN N NaN disused single NaN NaN LINESTRING (1845787.041 5784240.726, 1845749.1...
2 2462744 PALMERSTON NORTH - GISBORNE LINE N PALMERSTON NORTH - GISBORNE LINE disused single NaN NaN LINESTRING (1972000.000 5666908.227, 1971949.1...
3 2462838 TANEATUA BRANCH Y TĀNEATUA BRANCH disused single NaN NaN LINESTRING (1948000.000 5782634.539, 1947964.5...
4 6225482 KINGSTON BRANCH N KINGSTON BRANCH disused single NaN NaN LINESTRING (1261528.423 4961310.584, 1261546.2...
... ... ... ... ... ... ... ... ... ...
527 100118890 STRATFORD - OKAHUKURA LINE N STRATFORD - OKAHUKURA LINE NaN single NaN NaN LINESTRING (1732000.000 5657175.250, 1732026.9...
528 100118892 NORTH ISLAND MAIN TRUNK N NORTH ISLAND MAIN TRUNK NaN single NaN NaN LINESTRING (1794254.935 5696679.903, 1794254.8...
529 100121048 STILLWATER - NGAKAWAU LINE Y STILLWATER - NGĀKAWAU LINE NaN single NaN NaN LINESTRING (1492000.000 5319908.176, 1491999.4...
530 100121049 STILLWATER - NGAKAWAU LINE Y STILLWATER - NGĀKAWAU LINE NaN single NaN NaN LINESTRING (1484276.055 5375189.782, 1484283.2...
531 100121050 MURUPARA LINE N MURUPARA LINE NaN single NaN NaN LINESTRING (1932349.458 5766011.454, 1932334.6...

532 rows × 9 columns

In [ ]:
%%time
sa2["Hdist_rail"] = sa2.centroid.distance(rail.dissolve().geometry[0])
ax = sa2.plot(column="Hdist_rail", legend=True)
gpd.clip(rail, sa2.envelope).plot(ax=ax, color="red")
CPU times: user 612 ms, sys: 120 ms, total: 732 ms
Wall time: 589 ms
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Out[ ]:
<AxesSubplot: >
  1. Minimum Manhattan distance to Skytower from centroid Mdist_skytower
In [ ]:
skytower = gpd.GeoSeries(skytower, crs="EPSG:2193")
skytower
Out[ ]:
0    POINT (1757109.809 5920500.841)
dtype: geometry
In [ ]:
%%time
result = drive(sa2.centroid.to_crs(epsg=4326), skytower.to_crs(epsg=4326))
CPU times: user 792 ms, sys: 29.9 ms, total: 822 ms
Wall time: 2.38 s
In [ ]:
sa2["Mdist_skytower"] = [r[0] for r in result["distances"]]
sa2["Mtime_skytower"] = [r[0] for r in result["durations"]]
In [ ]:
sa2.plot(column="Mdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
sa2[sa2.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
%%time
north = drive(sa2.centroid.translate(yoff=-100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
west = drive(sa2.centroid.translate(xoff=-100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
east = drive(sa2.centroid.translate(xoff=100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
south = drive(sa2.centroid.translate(yoff=100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
CPU times: user 609 ms, sys: 111 µs, total: 609 ms
Wall time: 6.48 s
In [ ]:
sa2["Mdist_skytower_center"] = [r[0] for r in result["distances"]]
sa2["Mdist_skytower_north"] = [r[0] for r in north["distances"]]
sa2["Mdist_skytower_west"] = [r[0] for r in west["distances"]]
sa2["Mdist_skytower_east"] = [r[0] for r in east["distances"]]
sa2["Mdist_skytower_south"] = [r[0] for r in south["distances"]]
sa2[["Mdist_skytower_center",
    "Mdist_skytower_north",
    "Mdist_skytower_west",
    "Mdist_skytower_east",
    "Mdist_skytower_south"]].describe()
Out[ ]:
Mdist_skytower_center Mdist_skytower_north Mdist_skytower_west Mdist_skytower_east Mdist_skytower_south
count 558.000000 558.000000 558.000000 558.000000 558.000000
mean 21911.780108 21955.061470 21906.781900 21905.859498 21886.108781
std 15934.400881 15952.867723 15940.149558 15930.945196 15952.271608
min 393.900000 487.300000 213.100000 401.800000 286.000000
25% 12005.425000 12202.525000 12124.725000 12033.725000 12054.425000
50% 18320.850000 18210.300000 18232.750000 18121.850000 18231.950000
75% 26917.775000 26952.325000 27317.075000 26914.500000 27079.075000
max 136328.400000 136328.400000 136328.400000 136328.400000 136328.400000
In [ ]:
sa2["Mdist_skytower"] = sa2[[
    "Mdist_skytower_center",
    "Mdist_skytower_north",
    "Mdist_skytower_west",
    "Mdist_skytower_east",
    "Mdist_skytower_south"
]].min(axis=1)
(sa2["Mdist_skytower_center"] - sa2["Mdist_skytower"]).describe()
Out[ ]:
count     558.000000
mean      241.676882
std       435.008947
min         0.000000
25%        85.250000
50%       118.050000
75%       229.500000
max      5626.500000
dtype: float64
In [ ]:
sa2[sa2.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("SA2 <5KM driving from the Skytower")
Out[ ]:
Text(0.5, 1.0, 'SA2 <5KM driving from the Skytower')
In [ ]:
sa2["Mtime_skytower_center"] = [r[0] for r in result["durations"]]
sa2["Mtime_skytower_north"] = [r[0] for r in north["durations"]]
sa2["Mtime_skytower_west"] = [r[0] for r in west["durations"]]
sa2["Mtime_skytower_east"] = [r[0] for r in east["durations"]]
sa2["Mtime_skytower_south"] = [r[0] for r in south["durations"]]
display(sa2[[
    "Mtime_skytower_center",
    "Mtime_skytower_north",
    "Mtime_skytower_west",
    "Mtime_skytower_east",
    "Mtime_skytower_south"
]].describe())
sa2["Mtime_skytower"] = sa2[[
    "Mtime_skytower_center",
    "Mtime_skytower_north",
    "Mtime_skytower_west",
    "Mtime_skytower_east",
    "Mtime_skytower_south"
]].min(axis=1)
sa2["Mtime_skytower"].describe() # Units are seconds
Mtime_skytower_center Mtime_skytower_north Mtime_skytower_west Mtime_skytower_east Mtime_skytower_south
count 558.000000 558.000000 558.000000 558.000000 558.000000
mean 1620.210932 1620.446416 1619.073656 1620.528674 1616.845161
std 3312.904959 3310.753538 3313.626872 3312.360261 3313.581325
min 78.300000 92.400000 46.600000 74.200000 50.100000
25% 888.825000 878.550000 881.425000 885.900000 882.900000
50% 1207.550000 1204.500000 1207.650000 1192.500000 1197.950000
75% 1597.725000 1603.775000 1592.525000 1594.475000 1576.300000
max 70470.600000 70470.600000 70470.600000 70470.600000 70470.600000
Out[ ]:
count      558.000000
mean      1595.834588
std       3312.276911
min         46.600000
25%        863.500000
50%       1176.350000
75%       1560.475000
max      70470.600000
Name: Mtime_skytower, dtype: float64
In [ ]:
sa2[sa2.Mtime_skytower < 60*20].plot(column="Mtime_skytower", legend=True)
plt.title("SA2s < 20 minutes drive from the Skytower")
Out[ ]:
Text(0.5, 1.0, 'SA2s < 20 minutes drive from the Skytower')
  1. Minimum Manhattan distance from centroid to rapid transit station (rail station, Northern busway stop, or Ferry terminal) Mdist_rapid_transit
In [ ]:
%%time
result = drive(from_points=sa2.centroid.to_crs(epsg=4326), to_points=transit.geometry.to_crs(epsg=4326))
CPU times: user 190 ms, sys: 29.8 ms, total: 220 ms
Wall time: 1.26 s
In [ ]:
min_indices = np.argmin(result["distances"], axis=1)
sa2["Mdist_rapid_transit"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
sa2["Mtime_rapid_transit"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
sa2["Mdist_rapid_transit_name"] = list(transit.Location[min_indices])
In [ ]:
sa2.Mdist_rapid_transit_name.value_counts()
Out[ ]:
Constellation Bus Station     41
Hibiscus Coast Bus Station    36
Half Moon Bay                 30
Manukau                       27
Papakura                      24
Pukekohe                      24
West Harbour                  18
Onehunga                      17
Britomart                     15
Middlemore                    15
Glen Innes                    14
Manurewa                      14
Mt. Albert                    13
Avondale                      12
Kingsland                     12
Otahuhu                       12
Sunnyvale                     11
Papatoetoe                    11
Henderson                     11
Homai                         10
Sylvia Park                   10
Smales Farm Bus Station        9
Fruitvale Road                 9
New Lynn                       9
Morningside                    9
Glen Eden                      9
Ranui                          9
Swanson                        8
Gulf Harbour                   8
Sturges Road                   8
Beach Haven                    7
Mt Eden                        7
Akoranga Bus Station           7
Takanini                       7
Grafton                        6
Newmarket                      6
Ellerslie                      6
Matiatia                       6
Birkenhead                     5
Orakei                         5
Meadowbank                     4
Panmure                        4
Puhinui                        4
Pine Harbour                   4
Bayswater                      4
Parnell                        3
Remuera                        3
Northcote                      3
Devonport                      3
Baldwin Avenue                 2
Hobsonville                    2
Te Papapa                      2
Stanley Bay                    1
Penrose                        1
Te Mahia                       1
Name: Mdist_rapid_transit_name, dtype: int64
In [ ]:
ax = sa2.to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
In [ ]:
ax = sa2[sa2.Mdist_rapid_transit < 5000].to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
  1. Minimum Manhattan distance from centroid to motorway onramp Mdist_onramp
In [ ]:
%%time
result = drive(from_points=sa2.centroid.to_crs(epsg=4326), to_points=onramps2018.centroid.to_crs(epsg=4326))
CPU times: user 440 ms, sys: 66 µs, total: 440 ms
Wall time: 2.22 s
In [ ]:
min_indices = np.argmin(result["distances"], axis=1)
sa2["Mdist_onramp"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
sa2["Mtime_onramp"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
sa2["Mdist_onramp_name"] = list(onramps2018.DESCRIPTIO.iloc[min_indices])
In [ ]:
ax = sa2.plot(column="Mdist_onramp", legend=True)
onramps2018.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
In [ ]:
ax = sa2[sa2.Mdist_onramp < 5000].plot(column="Mdist_onramp", legend=True)
onramps.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
  1. Area of SA2 2018 (land only) Area
In [ ]:
sa2 = sa2.rename(columns={"LAND_AREA_SQ_KM": "Area"})
  1. Area zoned Residential under AUP Residential_area
  2. Area zoned Residential - Single House under AUP SH_area
  3. Area zoned Residential - Mixed Housing Suburban under AUP MHS_area
  4. Area zoned Residential - Mixed Housing Urban under AUP MHU_area
  5. Area zoned Residential - Terrace Housing and Apartments under AUP THA_area
  6. Area zoned Residential – Large Lot under AUP LL_area
  7. Area zoned Future Urban under AUP FU_area
  8. Area zones Hauraki Gulf Islands under AUP HGI_area
  9. Area zoned Business under AUP Business_area
  10. Area zoned Rural under AUP Rural Rural_area
  11. Area zoned as Open Space under AUP maps Open_area
  12. Area zoned as Roads under the Unitary Plan Roads_area
  13. Area zoned as Strategic Infrastructure Corridor InfraCorr_area
  14. Area zoned as Green Infrastructure Corridor under the Unitary Plan GrInfraCorr_area
In [ ]:
%%time
for k,v in tqdm(zones_of_interest.items()):
    subset = zones[zones.ZONE_resol.str.startswith(k)] # Just the matched zones (residential, business, rural etc)
    print(k, len(subset))
    clipped = gpd.clip(sa2, subset) # Clip the local areas to the matched zones
    sa2[v] = clipped.area # Store the resulting area. Unit is m²
  0%|          | 0/23 [00:00<?, ?it/s]
Residential 22398
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Single House Zone 3766
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Suburban Zone 9775
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Urban Zone 5864
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Terrace Housing and Apartment Building Zone 2134
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Large Lot Zone 379
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Rural and Coastal Settlement Zone 480
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Waitakere Ranges Zone 172
Future Urban Zone 282
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Hauraki Gulf Islands 221
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Business 3237
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural 2750
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Open Space 6667
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Road 47012
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Strategic Transport Corridor Zone 4215
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Green Infrastructure Corridor 6
Rural - Waitakere Ranges 172
Rural - Waitakere Foothills 44
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Coastal 768
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Production 1025
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Conservation 71
Rural - Mixed Rural 344
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Countryside Living 326
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
CPU times: user 2min 39s, sys: 2.41 s, total: 2min 41s
Wall time: 2min 41s
In [ ]:
cols = list(zones_of_interest.values())
sa2[cols] = sa2[cols].fillna(0)
  1. Indicator for coastline Coast_indicator
In [ ]:
%%time
sa2["Coast_indicator"] = sa2.geometry.progress_apply(lambda poly: coastline.intersects(poly))
  0%|          | 0/558 [00:00<?, ?it/s]
CPU times: user 33.8 s, sys: 69.9 ms, total: 33.9 s
Wall time: 33.7 s
In [ ]:
sa2.plot(column="Coast_indicator", legend=True, edgecolor="red")
Out[ ]:
<AxesSubplot: >
  1. Total population from 2018 census Census2018_population
In [ ]:
pop = pd.read_csv("input/Individual_part1_totalNZ-wide_format_updated_16-7-20.csv")
<string>:1: DtypeWarning: Columns (1,2,300,312,324) have mixed types. Specify dtype option on import or set low_memory=False.
In [ ]:
pop = pop.set_index("Area_code")
pop
Out[ ]:
Area_code_and_description Area_description Census_2006_usually_resident_population_count Census_2013_usually_resident_population_count Census_2018_usually_resident_population_count Census_2006_census_night_population_count Census_2013_census_night_population_count Census_2018_census_night_population_count Census_2018_Unit_record_data_source_11_2018_Census_individual_form_CURP Census_2018_Unit_record_data_source_12_Individuals_on_the_household_listing_only_CURP ... Census_2013_Maori_descent_04_Dont_know_CURP Census_2013_Maori_descent_Total_stated_CURP Census_2013_Maori_descent_99_Not_elsewhere_included_CURP Census_2013_Maori_descent_Total_CURP Census_2018_Maori_descent_01_Māori_descent_CURP Census_2018_Maori_descent_02_No_Māori_descent_CURP Census_2018_Maori_descent_04_Dont_know_CURP Census_2018_Maori_descent_Total_stated_CURP Census_2018_Maori_descent_99_Not_elsewhere_included_CURP Census_2018_Maori_descent_Total_CURP
Area_code
7000000 SA1 7000000 7000000 165 144 141 177 150 138 114 6 ... 3 132 12 144 135 6 3 141 0 141
7000001 SA1 7000001 7000001 93 105 114 117 108 120 87 3 ... 3 87 15 105 96 18 0 114 0 114
7000002 SA1 7000002 7000002 0 0 0 0 0 0 C C ... C C C 0 C C C C C 0
7000003 SA1 7000003 7000003 216 171 225 219 168 222 171 12 ... 3 144 24 171 210 15 0 225 0 225
7000004 SA1 7000004 7000004 90 102 138 90 105 129 117 3 ... 0 75 27 102 102 30 3 138 0 138
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
16 16 Tasman Region Tasman Region 44625 47157 52389 48306 51258 55206 46428 1443 ... 1074 43251 3903 47157 5589 45471 1329 52389 0 52389
17 17 Nelson Region Nelson Region 42888 46437 50880 45372 48444 53082 44922 1680 ... 1173 42528 3909 46437 6336 43167 1377 50880 0 50880
18 18 Marlborough Region Marlborough Region 42558 43416 47340 46179 46302 50562 41457 1515 ... 1104 39237 4179 43416 7341 38583 1416 47340 0 47340
99 99 Area Outside Region Area Outside Region 618 600 669 660 600 822 618 33 ... 24 546 54 600 432 210 27 669 0 669
total Total NZ (Regional Council) Total NZ (Regional Council) 4027947 4242048 4699755 4143282 4353198 4793358 3971892 203010 ... 87234 3821445 420603 4242048 869850 3715050 114855 4699755 0 4699755

32521 rows × 435 columns

In [ ]:
sa2["Census2018_population"] = pop.Census_2018_usually_resident_population_count[sa2.Code].tolist()
sa2.plot(column="Census2018_population", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
sa2[["Name", "Census2018_population"]].sort_values("Census2018_population", ascending=False).head(20)
Out[ ]:
Name Census2018_population
1000 Ormiston South 5514
982 Papatoetoe Central 5085
1059 Pukekohe West 4980
706 Aorere South 4944
919 Point England 4923
137 Weymouth North 4911
927 Mount Wellington Central 4827
974 Papatoetoe North 4779
788 Sunnyvale East 4773
128 Papatoetoe West 4755
747 Birkdale South 4725
786 Glendene North 4686
837 Clover Park North 4683
1056 Pukekohe North West 4674
749 Birkenhead West 4653
844 New Lynn South 4650
1011 Homai West 4605
796 Point Chevalier East 4602
869 Mount Roskill White Swan 4596
732 Massey South 4554
In [ ]:
sa2.Census2018_population.plot(kind="hist", bins=100)
Out[ ]:
<AxesSubplot: ylabel='Frequency'>
  1. Number of dwellings from 2018 census Census2018_dwellings
  2. Average Household Income Census2018_avg_HH_income
  3. Median Household Income Census2018_med_HH_income
In [ ]:
dwellings = pd.read_excel("input/2018_census_dwellings_by_SA2.xlsx", sheet_name="Table 1", skiprows=11)
dwellings = dwellings[~pd.isna(dwellings.Total)]
dwellings.index = dwellings["Unnamed: 0"].str.split(" ").str[0]
dwellings = dwellings.replace("..C", np.nan)
dwellings
Out[ ]:
Unnamed: 0 Loss Zero income $1-$5,000 $5,001-$10,000 $10,001-$15,000 $15,001-$20,000 $20,001-$25,000 $25,001-$30,000 $30,001-$35,000 ... $50,001-$60,000 $60,001-$70,000 $70,001-$100,000 $100,001-$150,000 $150,001 or More Total stated Not stated Median Household\n Income ($) Mean Household \nIncome ($) Total
Unnamed: 0
100100 100100 North Cape 3.0 6.0 3.0 12.0 12.0 45.0 66.0 12.0 21.0 ... 48.0 39.0 69.0 60.0 42.0 525.0 105.0 49400.0 65300.0 630.0
100200 100200 Rangaunu Harbour 3.0 6.0 3.0 9.0 30.0 48.0 78.0 24.0 21.0 ... 42.0 63.0 123.0 96.0 48.0 693.0 81.0 56400.0 67000.0 774.0
100300 100300 Inlets Far North District 0.0 0.0 0.0 3.0 0.0 3.0 6.0 0.0 0.0 ... 0.0 0.0 3.0 0.0 3.0 30.0 30.0 24400.0 41300.0 60.0
100400 100400 Karikari Peninsula 3.0 0.0 6.0 0.0 12.0 12.0 54.0 12.0 18.0 ... 30.0 27.0 57.0 51.0 24.0 393.0 69.0 47200.0 62800.0 465.0
100500 100500 Tangonge 3.0 3.0 0.0 0.0 6.0 12.0 30.0 9.0 6.0 ... 24.0 24.0 54.0 69.0 36.0 330.0 57.0 67100.0 81600.0 390.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
400013 400013 Snares Islands NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.0
400014 400014 Oceanic Antipodes Islands NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.0
400015 400015 Antipodes Islands NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.0
400016 400016 Ross Dependency NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.0
Total Total New Zealand 4974.0 10152.0 15312.0 14538.0 32031.0 59175.0 105777.0 45423.0 45849.0 ... 107058.0 97539.0 242262.0 295119.0 272208.0 1526961.0 126831.0 75700.0 91300.0 1653792.0

2254 rows × 22 columns

In [ ]:
sa2["Census2018_dwellings"] = dwellings.Total[sa2.Code].tolist()
sa2["Census2018_avg_HH_income"] = dwellings["Mean Household \nIncome ($)"][sa2.Code].tolist()
sa2["Census2018_med_HH_income"] = dwellings["Median Household\n Income ($)"][sa2.Code].tolist()
In [ ]:
sa2.plot(column="Census2018_dwellings", legend=True)
sa2.plot(column="Census2018_avg_HH_income", legend=True)
sa2.plot(column="Census2018_med_HH_income", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
sa2.Census2018_med_HH_income.plot(kind="hist", bins=100)
Out[ ]:
<AxesSubplot: ylabel='Frequency'>
In [ ]:
sa2
Out[ ]:
Code Name REGC2018_V1_00 REGC2018_V1_00_NAME TA2018_V1_00 TA2018_V1_00_NAME Area AREA_SQ_KM Shape_Length geometry ... RC_area RP_area RCZ_area RMU_area RCL_area Coast_indicator Census2018_population Census2018_dwellings Census2018_avg_HH_income Census2018_med_HH_income
33 110900 Dome Valley-Matakana 02 Auckland Region 076 Auckland 84.749966 84.749966 70031.926112 MULTIPOLYGON (((1749212.212 5981874.734, 17492... ... 2.340721e+07 1.387073e+02 0.000000 1.428702e+07 1.204587e+03 True 1530 546.0 104300.0 88200.0
34 111100 Warkworth West 02 Auckland Region 076 Auckland 11.359752 11.359752 22629.664017 MULTIPOLYGON (((1748589.106 5974509.939, 17485... ... 0.000000e+00 1.692265e+05 0.000000 4.307705e+04 1.297497e+03 False 2481 960.0 82000.0 59600.0
35 111200 Puhoi Valley 02 Auckland Region 076 Auckland 236.529965 236.529965 142134.544465 MULTIPOLYGON (((1740248.959 5974374.891, 17402... ... 8.326648e+07 9.488337e+04 0.000000 1.781515e+04 4.528519e+06 True 3702 1242.0 112300.0 104100.0
36 112600 Waikoukou Valley 02 Auckland Region 076 Auckland 52.854583 52.854583 42565.729322 MULTIPOLYGON (((1735693.112 5942203.564, 17359... ... 0.000000e+00 6.625438e+05 0.000000 0.000000e+00 6.620425e+05 False 1728 555.0 132100.0 126700.0
37 112800 Hatfields Beach 02 Auckland Region 076 Auckland 0.923255 0.923255 4314.440531 MULTIPOLYGON (((1750981.811 5952164.661, 17512... ... 0.000000e+00 0.000000e+00 2.666470 0.000000e+00 0.000000e+00 True 1554 558.0 108600.0 97100.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1061 165800 Rooseville Park 02 Auckland Region 076 Auckland 1.345809 1.345809 6010.945714 MULTIPOLYGON (((1770089.518 5882192.248, 17701... ... 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 0.000000e+00 False 2562 864.0 104600.0 96600.0
1062 166000 Pukekohe Central 02 Auckland Region 076 Auckland 2.939129 2.939129 9211.796424 MULTIPOLYGON (((1769469.158 5881504.407, 17694... ... 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 0.000000e+00 False 369 153.0 64500.0 53200.0
1063 166300 Bombay Hills 02 Auckland Region 076 Auckland 31.682020 31.682020 37482.345738 MULTIPOLYGON (((1777896.083 5888522.045, 17779... ... 0.000000e+00 2.835952e+07 0.000000 0.000000e+00 0.000000e+00 False 1974 669.0 122500.0 116200.0
1064 166400 Ararimu 02 Auckland Region 076 Auckland 91.308241 91.308241 57552.107386 MULTIPOLYGON (((1786544.313 5891035.131, 17865... ... 0.000000e+00 1.306492e+03 0.000016 3.740967e+06 0.000000e+00 False 2124 675.0 130100.0 122600.0
1079 168600 Miranda-Pukorokoro 03 Waikato Region 012 Hauraki District 81.340404 81.340404 59717.399740 MULTIPOLYGON (((1803927.880 5898880.697, 18039... ... 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 0.000000e+00 True 849 360.0 76600.0 61200.0

558 rows × 62 columns

In [ ]:
sa2.drop(columns="geometry").to_csv("output/2018_Statistical_Area_2.csv")

Area Unit 2013 dataset¶

  1. Name (string is fine) Name
  2. Numeric code Code
  3. Centroid longitude Centroid_lon
  4. Centroid latitude Centroid_lat
In [ ]:
au = gpd.read_file("input/statsnzarea-unit-2013-FGDB.zip!area-unit-2013.gdb")
In [ ]:
au = au.rename(columns={"AU2013_V1_00_NAME": "Name", "AU2013_V1_00": "Code"})
au["Centroid_lon"] = au.centroid.to_crs(epsg=4326).x
au["Centroid_lat"] = au.centroid.to_crs(epsg=4326).y
  1. Local Area in which the Area Unit’s centroid is located Centroid_local_area
In [ ]:
au["Centroid_local_area"] = au.representative_point().apply(lambda point: df.Name[df.contains(point)].iloc[0] if any(df.contains(point)) else np.nan)
problems = au.Code.isin(["520602", "521135", "506634"])
au.loc[problems, "Centroid_local_area"] = au[problems].geometry.apply(lambda poly: df.Name[df.intersects(poly)].iloc[0])
au["Centroid_local_area"].value_counts()
Out[ ]:
Henderson-Massey                    29
Manurewa                            21
Orakei                              20
Auckland Central                    20
Mangere-Otahuhu                     19
Beach Haven-Birkenhead-Northcote    19
Hibiscus Coast                      17
Whau                                16
Rodney-Helensville                  15
Upper Harbour Local Board Area      15
Papakura                            14
Devonport-Takapuna                  13
Mt Eden                             13
Botany                              13
Franklin-Pukekohe                   12
Titirangi                           12
Rodney-Warkworth                    12
Papatoetoe                          11
Pakuranga                           11
Puketapapa                          11
Tamaki                              11
Mt Albert                           11
East Coast Bays                     11
Franklin-Beachlands-Hunua           10
Howick                              10
Maungakiekie                         9
Otara                                9
Waitakere                            8
Franklin-Waiuku                      5
Rodney-Kumeu-Riverhead               4
Waiheke                              3
Rodney-Wellsford                     3
Rodney-Dairy Flat                    2
Name: Centroid_local_area, dtype: int64
In [ ]:
print(f'{sum(~pd.isna(au["Centroid_local_area"]))} matches, {sum(pd.isna(au["Centroid_local_area"]))} unmatched')
409 matches, 1595 unmatched
In [ ]:
au = au[~pd.isna(au.Centroid_local_area)]
ax = au.plot(column="Centroid_local_area", cmap="Spectral", legend=True)
  1. Haversine distance to Skytower from centroid Hdist_skytower
In [ ]:
au["Hdist_skytower"] = au.centroid.distance(skytower.iloc[0])
au.plot(column="Hdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Minimum Haversine distance from centroid to motorway Hdist_motorway
In [ ]:
%%time
au["Hdist_motorway"] = au.centroid.distance(mway.dissolve().geometry[0])
ax = au.plot(column="Hdist_motorway", legend=True)
gpd.clip(mway, au.envelope).plot(ax=ax, color="red")
CPU times: user 716 ms, sys: 160 ms, total: 876 ms
Wall time: 751 ms
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Out[ ]:
<AxesSubplot: >
  1. Minimum Haversine distance from centroid to rail line Hdist_rail
In [ ]:
%%time
au["Hdist_rail"] = au.centroid.distance(rail.dissolve().geometry[0])
ax = au.plot(column="Hdist_rail", legend=True)
gpd.clip(rail, au.envelope).plot(ax=ax, color="red")
CPU times: user 524 ms, sys: 110 ms, total: 634 ms
Wall time: 489 ms
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Out[ ]:
<AxesSubplot: >
  1. Minimum Manhattan distance to Skytower from centroid Mdist_skytower
In [ ]:
%%time
result = drive(au.centroid.to_crs(epsg=4326), skytower.to_crs(epsg=4326))
north = drive(au.centroid.translate(yoff=-100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
west = drive(au.centroid.translate(xoff=-100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
east = drive(au.centroid.translate(xoff=100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
south = drive(au.centroid.translate(yoff=100).to_crs(epsg=4326), skytower.to_crs(epsg=4326))
CPU times: user 453 ms, sys: 10.2 ms, total: 463 ms
Wall time: 4.56 s
In [ ]:
au["Mdist_skytower_center"] = [r[0] for r in result["distances"]]
au["Mdist_skytower_north"] = [r[0] for r in north["distances"]]
au["Mdist_skytower_west"] = [r[0] for r in west["distances"]]
au["Mdist_skytower_east"] = [r[0] for r in east["distances"]]
au["Mdist_skytower_south"] = [r[0] for r in south["distances"]]
display(au[[
    "Mdist_skytower_center",
    "Mdist_skytower_north",
    "Mdist_skytower_west",
    "Mdist_skytower_east",
    "Mdist_skytower_south"
]].describe())
au["Mdist_skytower"] = au[[
    "Mdist_skytower_center",
    "Mdist_skytower_north",
    "Mdist_skytower_west",
    "Mdist_skytower_east",
    "Mdist_skytower_south"
]].min(axis=1)
display(au["Mdist_skytower"].describe())

au["Mtime_skytower_center"] = [r[0] for r in result["durations"]]
au["Mtime_skytower_north"] = [r[0] for r in north["durations"]]
au["Mtime_skytower_west"] = [r[0] for r in west["durations"]]
au["Mtime_skytower_east"] = [r[0] for r in east["durations"]]
au["Mtime_skytower_south"] = [r[0] for r in south["durations"]]
display(au[[
    "Mtime_skytower_center",
    "Mtime_skytower_north",
    "Mtime_skytower_west",
    "Mtime_skytower_east",
    "Mtime_skytower_south"
]].describe())
au["Mtime_skytower"] = au[[
    "Mtime_skytower_center",
    "Mtime_skytower_north",
    "Mtime_skytower_west",
    "Mtime_skytower_east",
    "Mtime_skytower_south"
]].min(axis=1)
display(au["Mtime_skytower"].describe())
Mdist_skytower_center Mdist_skytower_north Mdist_skytower_west Mdist_skytower_east Mdist_skytower_south
count 409.000000 409.000000 409.000000 409.000000 409.000000
mean 22795.600244 22781.618093 22788.159902 22784.258191 22748.530073
std 16379.256603 16359.032083 16357.011292 16376.317853 16403.724191
min 557.400000 715.700000 707.700000 1143.700000 446.000000
25% 12472.900000 12402.700000 12501.100000 12532.200000 12441.400000
50% 18613.100000 18513.300000 18539.800000 18517.400000 18512.800000
75% 27316.300000 27355.900000 27221.000000 27385.600000 27368.200000
max 89091.100000 89018.800000 89160.200000 87888.800000 89163.300000
count      409.000000
mean     22531.981907
std      16385.776202
min        446.000000
25%      12227.900000
50%      18255.700000
75%      27187.300000
max      87888.800000
Name: Mdist_skytower, dtype: float64
Mtime_skytower_center Mtime_skytower_north Mtime_skytower_west Mtime_skytower_east Mtime_skytower_south
count 409.000000 409.000000 409.000000 409.000000 409.000000
mean 1483.669438 1484.317115 1483.113692 1483.419804 1481.469193
std 1264.627438 1263.705290 1262.503954 1264.549168 1264.771003
min 99.900000 110.600000 148.500000 172.300000 73.100000
25% 910.500000 926.500000 910.300000 913.200000 905.600000
50% 1225.300000 1222.200000 1228.600000 1219.700000 1226.300000
75% 1621.600000 1623.600000 1603.700000 1625.500000 1615.500000
max 14754.400000 14754.400000 14753.900000 14802.600000 14754.400000
count      409.000000
mean      1459.823227
std       1263.493685
min         73.100000
25%        883.600000
50%       1203.900000
75%       1588.300000
max      14753.900000
Name: Mtime_skytower, dtype: float64
In [ ]:
au.plot(column="Mdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
au[au.Mdist_skytower < 10000].plot(column="Mdist_skytower", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Minimum Manhattan distance from centroid to rapid transit station (rail station, Northern busway stop, or Ferry terminal) Mdist_rapid_transit
In [ ]:
%%time
result = drive(from_points=au.centroid.to_crs(epsg=4326), to_points=transit.geometry.to_crs(epsg=4326))
CPU times: user 191 ms, sys: 150 µs, total: 192 ms
Wall time: 1.08 s
In [ ]:
min_indices = np.argmin(result["distances"], axis=1)
au["Mdist_rapid_transit"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
au["Mtime_rapid_transit"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
au["Mdist_rapid_transit_name"] = list(transit.Location[min_indices])
In [ ]:
au.Mdist_rapid_transit_name.value_counts()
Out[ ]:
Hibiscus Coast Bus Station    36
Constellation Bus Station     25
Half Moon Bay                 24
Papakura                      21
West Harbour                  18
Pukekohe                      15
Manukau                       13
Papatoetoe                    12
Otahuhu                       12
Kingsland                     11
Manurewa                      11
Ranui                         10
Onehunga                      10
Glen Innes                    10
Sunnyvale                     10
Mt. Albert                    10
Henderson                      9
Middlemore                     9
Glen Eden                      9
Swanson                        8
Avondale                       7
Morningside                    7
Sylvia Park                    6
Homai                          6
New Lynn                       6
Beach Haven                    6
Fruitvale Road                 6
Grafton                        6
Britomart                      5
Smales Farm Bus Station        5
Akoranga Bus Station           5
Orakei                         5
Newmarket                      4
Gulf Harbour                   4
Birkenhead                     4
Ellerslie                      4
Mt Eden                        4
Panmure                        3
Te Papapa                      3
Remuera                        3
Bayswater                      3
Sturges Road                   3
Takanini                       3
Parnell                        2
Matiatia                       2
Devonport                      2
Northcote                      2
Puhinui                        2
Pine Harbour                   2
Baldwin Avenue                 2
Stanley Bay                    1
Penrose                        1
Meadowbank                     1
Te Mahia                       1
Name: Mdist_rapid_transit_name, dtype: int64
In [ ]:
ax = au.to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
In [ ]:
ax = au[au.Mdist_rapid_transit < 10000].to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
  1. Minimum Manhattan distance from centroid to motorway onramp Mdist_onramp
In [ ]:
%%time
result = drive(from_points=au.centroid.to_crs(epsg=4326), to_points=onramps.centroid.to_crs(epsg=4326))
CPU times: user 338 ms, sys: 102 µs, total: 338 ms
Wall time: 1.79 s
In [ ]:
min_indices = np.argmin(result["distances"], axis=1)
au["Mdist_onramp"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
au["Mtime_onramp"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
au["Mdist_onramp_name"] = list(onramps.DESCRIPTIO.iloc[min_indices])
In [ ]:
ax = au.plot(column="Mdist_onramp", legend=True)
onramps.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
In [ ]:
ax = au[au.Mdist_onramp < 5000].plot(column="Mdist_onramp", legend=True)
onramps.plot(ax=ax, color="red")
Out[ ]:
<AxesSubplot: >
  1. Area (land only) Area
In [ ]:
au = au.rename(columns={"LAND_AREA_SQ_KM": "Area"})
  1. Area zoned Residential under AUP Residential_area
  2. Area zoned Residential - Single House under AUP SH_area
  3. Area zoned Residential - Mixed Housing Suburban under AUP MHS_area
  4. Area zoned Residential - Mixed Housing Urban under AUP MHU_area
  5. Area zoned Residential - Terrace Housing and Apartments under AUP THA_area
  6. Area zoned Residential – Large Lot under AUP LL_area
  7. Area zoned Future Urban under AUP FU_area
  8. Area zones Hauraki Gulf Islands under AUP HGI_area
  9. Area zoned Business under AUP Business_area
  10. Area zoned Rural under AUP Rural Rural_area
  11. Area zoned as Open Space under AUP maps Open_area
  12. Area zoned as Roads under the Unitary Plan Roads_area
  13. Area zoned as Strategic Infrastructure Corridor InfraCorr_area
  14. Area zoned as Green Infrastructure Corridor under the Unitary Plan GrInfraCorr_area
In [ ]:
%%time
for k,v in tqdm(zones_of_interest.items()):
    subset = zones[zones.ZONE_resol.str.startswith(k)] # Just the matched zones (residential, business, rural etc)
    print(k, len(subset))
    clipped = gpd.clip(au, subset) # Clip the local areas to the matched zones
    au[v] = clipped.area # Store the resulting area. Unit is m²
  0%|          | 0/23 [00:00<?, ?it/s]
Residential 22398
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Single House Zone 3766
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Suburban Zone 9775
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Mixed Housing Urban Zone 5864
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Terrace Housing and Apartment Building Zone 2134
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Large Lot Zone 379
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Residential - Rural and Coastal Settlement Zone 480
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Waitakere Ranges Zone 172
Future Urban Zone 282
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Hauraki Gulf Islands 221
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Business 3237
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural 2750
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Open Space 6667
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Road 47012
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Strategic Transport Corridor Zone 4215
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Green Infrastructure Corridor 6
Rural - Waitakere Ranges 172
Rural - Waitakere Foothills 44
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Coastal 768
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Production 1025
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Rural Conservation 71
Rural - Mixed Rural 344
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
Rural - Countryside Living 326
/usr/local/lib/python3.10/dist-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
CPU times: user 2min 21s, sys: 1.66 s, total: 2min 23s
Wall time: 2min 23s
In [ ]:
au = au.fillna(0)
  1. Indicator (0 or 1) for whether the AU is on coastline Coast_indicator
In [ ]:
%%time
au["Coast_indicator"] = au.geometry.progress_apply(lambda poly: coastline.intersects(poly))
  0%|          | 0/409 [00:00<?, ?it/s]
CPU times: user 24.2 s, sys: 60.8 ms, total: 24.3 s
Wall time: 24.2 s
In [ ]:
au.plot(column="Coast_indicator", legend=True, edgecolor="red")
Out[ ]:
<AxesSubplot: >
  1. Total population from 2013 census Census2013_population
In [ ]:
pop = pd.read_csv("input/2013-mb-dataset-Total-New-Zealand-Individual-Part-1.csv", encoding='unicode_escape', low_memory=False)
pop
Out[ ]:
Area_Code_and_Description Code Description 2001_Census_census_usually_resident_population_count(1) 2006_Census_census_usually_resident_population_count(1) 2013_Census_census_usually_resident_population_count(1) 2001_Census_census_night_population_count(2) 2006_Census_census_night_population_count(2) 2013_Census_census_night_population_count(2) 2001_Census_sex_for_the_census_usually_resident_population_count(1)_Male ... 2006_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Don't_Know 2006_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Total_people_stated 2006_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Not_Elsewhere_Included(14) 2006_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Total_people 2013_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Maori_Descent 2013_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_No_Maori_Descent 2013_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Don't_Know 2013_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Total_people_stated 2013_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Not_Elsewhere_Included(14) 2013_Census_Maori_descent_for_the_census_usually_resident_population_count(1)_Total_people
0 MB 0000100 0000100 NaN 9.0 3.0 3.0 15.0 9.0 9.0 6 ... ..C ..C ..C 3.0 ..C ..C ..C ..C ..C 3.0
1 MB 0000200 0000200 NaN 90.0 87.0 84.0 99.0 96.0 84.0 42 ... 0 81 6 90.0 69 3 3 75 9 84.0
2 MB 0000300 0000300 NaN 90.0 72.0 57.0 93.0 72.0 54.0 42 ... 0 66 6 75.0 54 0 0 57 3 57.0
3 MB 0000400 0000400 NaN 30.0 21.0 30.0 45.0 39.0 30.0 18 ... 0 21 3 21.0 12 6 3 21 6 27.0
4 MB 0000501 0000501 NaN 0.0 0.0 0.0 0.0 0.0 0.0 ..C ... ..C ..C ..C 0.0 ..C ..C ..C ..C ..C 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
49028 Footnotes for specific variables or categories 13 Consists of people who were too young to talk ... NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49029 Footnotes for specific variables or categories 14 Consists of response unidentifiable and not st... NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49030 Symbols ..C confidential NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49031 Symbols * not able to be calculated NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
49032 Source Statistics New Zealand NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

49033 rows × 227 columns

In [ ]:
pop = pop.set_index("Code")
In [ ]:
au["Census2013_population"] = pop["2013_Census_census_usually_resident_population_count(1)"][au.Code].tolist()
In [ ]:
au.plot(column="Census2013_population", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Number of dwellings from 2013 census Census2013_dwellings
In [ ]:
households = households.set_index("Code")
In [ ]:
au["Census2013_dwellings"] = households["2013_Census_total_households_in_occupied_private_dwellings"][au.Code].tolist()
In [ ]:
au.plot(column="Census2013_dwellings", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Average Household Income Census2013_avg_HH_income
In [ ]:
income = pd.read_excel("input/2013_census_mean_income_by_AU2013.xlsx", sheet_name = "Data", skiprows=8)
income = income.replace("..C", np.nan)
income.index = income["Census Night Area Unit (2013 Areas)"].str.split().str[0]
income
Out[ ]:
Census Night Area Unit (2013 Areas) ($) Mean Household Income
Census Night Area Unit (2013 Areas)
NaN NaN NaN
500100 500100 Awanui 59700.0
500202 500202 Karikari Peninsula-Maungataniwha 49500.0
500203 500203 Taipa Bay-Mangonui 50400.0
500204 500204 Herekino 63100.0
... ... ...
This This data has been randomly rounded to protect... NaN
Mean Mean has been rounded to nearest $100. NaN
..C ..C has been inserted in cells that have been ... NaN
NaN NaN NaN
Source: Source: Stats NZ NaN

2022 rows × 2 columns

In [ ]:
income[" ($) Mean Household Income"].plot(kind="hist", bins=100)
Out[ ]:
<AxesSubplot: ylabel='Frequency'>
In [ ]:
au["Census2013_avg_HH_income"] = income[" ($) Mean Household Income"][au.Code].astype(float).tolist()
In [ ]:
au.plot(column="Census2013_avg_HH_income", legend=True)
Out[ ]:
<AxesSubplot: >
  1. Median Household Income Census2013_med_HH_income
In [ ]:
key
Out[ ]:
'2013_Census_total_household_income_(grouped)(2)(3)(4)_for_households_in_occupied_private_dwellings_Median_household_income_($)(18)(23)'
In [ ]:
au["Census2013_med_HH_income"] = households[key][au.Code].replace("..C", np.nan).astype(float).tolist()
In [ ]:
au.plot(column="Census2013_med_HH_income", legend=True)
Out[ ]:
<AxesSubplot: >
In [ ]:
au
Out[ ]:
Code Name AREA_SQ_KM Area Shape_Length geometry Centroid_lon Centroid_lat Centroid_local_area Hdist_skytower ... RC_area RP_area RCZ_area RMU_area RCL_area Coast_indicator Census2013_population Census2013_dwellings Census2013_avg_HH_income Census2013_med_HH_income
30 505604 Kumeu East 13.475480 13.310426 24949.702400 MULTIPOLYGON (((1741052.061 5931333.839, 17409... 174.575870 -36.770909 Rodney-Kumeu-Riverhead 18712.837132 ... 0.000000e+00 3.415839e+04 0.000000 2.501360e+07 3.583400e+06 True 1449.0 474.0 98300.0 87700.0
31 505605 Kumeu West 24.388271 24.388271 32928.601801 MULTIPOLYGON (((1734788.301 5932715.055, 17348... 174.524933 -36.774538 Rodney-Kumeu-Riverhead 22696.426769 ... 0.000000e+00 2.181426e+07 0.000000 4.157821e-02 2.410624e+05 False 1725.0 609.0 106200.0 95300.0
32 505804 Hatfields Beach 0.908867 0.908867 5395.241593 MULTIPOLYGON (((1751816.238 5952425.382, 17518... 174.690104 -36.569595 Hibiscus Coast 31594.334161 ... 5.407535e+06 0.000000e+00 45.869441 0.000000e+00 0.000000e+00 True 1380.0 492.0 81500.0 74100.0
33 505805 Orewa 5.572505 4.229676 19755.382361 MULTIPOLYGON (((1750518.569 5950940.087, 17505... 174.686690 -36.589013 Hibiscus Coast 29556.184420 ... 0.000000e+00 7.095903e+07 217.527635 0.000000e+00 0.000000e+00 True 8520.0 3843.0 65000.0 47600.0
34 505902 Manly 3.188420 3.188420 12908.971485 MULTIPOLYGON (((1756245.400 5945964.220, 17562... 174.759445 -36.630419 Hibiscus Coast 24183.805546 ... 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 0.000000e+00 True 6552.0 2535.0 78300.0 63800.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
967 525922 Bledisloe Park 9.643551 9.643551 16858.446790 MULTIPOLYGON (((1770838.870 5881130.225, 17709... 174.915328 -37.215688 Franklin-Pukekohe 42980.054511 ... 0.000000e+00 6.398755e+07 0.000000 0.000000e+00 0.000000e+00 False 2934.0 1092.0 78400.0 70100.0
968 526103 Waiuku West 2.198567 2.198567 9682.515485 MULTIPOLYGON (((1753228.371 5877597.817, 17532... 174.724591 -37.248157 Franklin-Waiuku 44490.721194 ... 0.000000e+00 0.000000e+00 0.000000 1.240984e+08 0.000000e+00 True 3102.0 1221.0 70700.0 56900.0
969 526104 Waiuku East 3.200239 3.158494 9009.196620 MULTIPOLYGON (((1753749.548 5877735.141, 17537... 174.738476 -37.247818 Franklin-Waiuku 44377.597242 ... 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 0.000000e+00 True 3498.0 1248.0 73000.0 60500.0
970 526105 South Waiuku 2.247383 2.247383 9084.157884 MULTIPOLYGON (((1755346.188 5875198.493, 17551... 174.739741 -37.259971 Franklin-Waiuku 45719.614106 ... 0.000000e+00 2.712553e+06 0.000000 2.030531e+05 0.000000e+00 False 1599.0 546.0 93200.0 85600.0
1962 616300 Browns Island 0.595336 0.595336 3430.690993 MULTIPOLYGON (((1769155.864 5922005.512, 17691... 174.894441 -36.830617 Waiheke 11959.563577 ... 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 0.000000e+00 True 0.0 0.0 NaN NaN

409 rows × 58 columns

In [ ]:
au.drop(columns="geometry").to_csv("output/2013_Area_Unit.csv")

Maps¶

  1. Map of Auckland with AUP zones highlighted. As below, but omitting the red rural-urban boundary.
In [ ]:
zones
Out[ ]:
OBJECTID CONTOUR created_da DocumentUR GlobalID GROUPZONE GROUPZONE_ last_edite NAME PARCEL_BAS ... TYPE TYPE_resol VERSIONSTA VERSIONS_1 ZONE ZONE_resol ZONEHEIGHT SHAPE_Leng SHAPE_Area geometry
0 1.0 NaN 20160718211 NaN {4C8F9436-7EA6-417E-B64F-15FCD44459F6} 2 Residential 20161111010 NaN NaN ... NaN NaN 4 Operative 60 Residential - Mixed Housing Urban Zone NaN 285.664016 2.050275e+03 POLYGON ((1768030.306 5901206.846, 1768033.070...
1 2.0 NaN 20160718211 NaN {604AAD87-8ED4-4111-8276-47CEE7E81F92} 1 Public Open Space 20161111010 NaN NaN ... NaN NaN 4 Operative 33 Open Space - Sport and Active Recreation Zone NaN 1246.837757 1.684599e+04 POLYGON ((1764267.286 5919989.370, 1764218.153...
2 3.0 NaN 20160718211 NaN {8D827DA8-BC5B-437A-B17A-532354F7D037} 4 Rural 20161111010 NaN NaN ... NaN NaN 4 Operative 11 Rural - Mixed Rural Zone NaN 3582.113246 6.841744e+05 POLYGON ((1740091.195 5928308.839, 1740089.844...
3 4.0 NaN 20160718211 NaN {96C9E266-3341-4C71-94F1-325F2EE45732} 2 Residential 20161111010 NaN NaN ... NaN NaN 4 Operative 23 Residential - Large Lot Zone NaN 317.098469 6.024226e+03 POLYGON ((1750502.125 5928677.635, 1750456.131...
4 5.0 NaN 20160718211 NaN {90B50FEE-45A3-4E88-819A-370751ACDE3D} 1 Public Open Space 20161111010 NaN NaN ... NaN NaN 4 Operative 31 Open Space - Conservation Zone NaN 230.836636 5.639794e+02 POLYGON ((1741460.217 5918191.600, 1741476.745...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
130295 130296.0 NaN 20161115151 NaN {B2F0FB45-80F6-41ED-AA57-A914B195B31E} 1 Public Open Space 20161115151 NaN NaN ... NaN NaN 4 Operative 31 Open Space - Conservation Zone NaN 179382.307787 9.040193e+07 POLYGON ((1738072.631 5902593.421, 1738095.386...
130296 130297.0 NaN 20161115151 NaN {A3F4EF61-9162-43C3-90BD-DC84D93C6A64} 2 Residential 20161115151 NaN NaN ... NaN NaN 4 Operative 18 Residential - Mixed Housing Suburban Zone NaN 2769.292040 2.920602e+05 POLYGON ((1770189.642 5905789.775, 1770199.407...
130297 130298.0 NaN 20161115151 NaN {A5FC7EB5-76E5-414C-96DD-715C671764B4} 4 Rural 20161115151 Kaipara South Head and Harbour coastal area NaN ... NaN NaN 4 Operative 46 Rural - Rural Coastal Zone NaN 27168.762393 6.344938e+06 POLYGON ((1730253.401 5955767.484, 1730254.399...
130298 130299.0 NaN 20161115151 NaN {C371B83C-35CE-46A1-B94F-F1E592F271F7} 2 Residential 20161115151 NaN NaN ... NaN NaN 4 Operative 8 Residential - Terrace Housing and Apartment Bu... NaN 1812.109533 1.536829e+05 POLYGON ((1743032.759 5924130.564, 1742996.886...
130299 130300.0 NaN 20161115151 NaN {31281924-C74D-4038-8260-FE6D886F4C94} 2 Residential 20161115151 NaN NaN ... NaN NaN 4 Operative 18 Residential - Mixed Housing Suburban Zone NaN 2511.267945 3.539606e+05 POLYGON ((1748979.767 5925771.895, 1748986.615...

130300 rows × 31 columns

In [ ]:
cols = [
    "Residential - Terrace Housing and Apartment Building Zone",
    "Residential - Mixed Housing Urban Zone",
    "Residential - Mixed Housing Suburban Zone"
]
In [ ]:
coastline = gpd.read_file("input/lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip!nz-coastlines-and-islands-polygons-topo-150k.gdb")
In [ ]:
cmap = plt.cm.get_cmap('plasma', 512)
cmap = matplotlib.colors.ListedColormap(cmap([0,.2,.4]))
ax = zones[zones.ZONE_resol.isin(cols)].plot(column="ZONE_resol", legend=True, cmap=cmap, legend_kwds={'fontsize':20, 'loc': 'lower left'})
xmin, xmax = ax.get_xlim()
ymin, ymax = ax.get_ylim()
print(xmin, xmax, ymin, ymax)
coastline.boundary.plot(ax=ax, color="gray", linewidth=.5)
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin + 1e4, ymax - 4e4)

ax.add_artist(ScaleBar(1, location="upper right", font_properties={"size": 20}))

x, y, arrow_length = 0.05, .98, 0.05
ax.annotate('N', xy=(x, y), xytext=(x, y-arrow_length),
            arrowprops=dict(facecolor='black', width=5, headwidth=15),
            ha='center', va='center', fontsize=20,
            xycoords=ax.transAxes)

ax.set_xticks([])
ax.set_yticks([])
1735024.9733500003 1779731.6056499996 5869626.39383 5980785.90757
Out[ ]:
[]
In [ ]:
ax = zones[zones.ZONE_resol == "Residential - Single House Zone"].plot(column="ZONE_resol", legend=True, legend_kwds={'fontsize':20, 'loc': 'lower left'})
#xmin, xmax = ax.get_xlim()
#ymin, ymax = ax.get_ylim()
#print(xmin, xmax, ymin, ymax)
coastline.boundary.plot(ax=ax, color="gray", linewidth=.5)
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin + 1e4, ymax - 4e4)

ax.add_artist(ScaleBar(1, location="upper right", font_properties={"size": 20}))

x, y, arrow_length = 0.05, .98, 0.05
ax.annotate('N', xy=(x, y), xytext=(x, y-arrow_length),
            arrowprops=dict(facecolor='black', width=5, headwidth=15),
            ha='center', va='center', fontsize=20,
            xycoords=ax.transAxes)
ax.set_xticks([])
ax.set_yticks([])
Out[ ]:
[]
In [ ]:
df.Name[df.Hdist_skytower < 2e4].tolist()
Out[ ]:
['Auckland Central',
 'Beach Haven-Birkenhead-Northcote',
 'Botany',
 'Devonport-Takapuna',
 'East Coast Bays',
 'Henderson-Massey',
 'Howick',
 'Mangere-Otahuhu',
 'Maungakiekie',
 'Mt Albert',
 'Mt Eden',
 'Orakei',
 'Otara',
 'Pakuranga',
 'Papatoetoe',
 'Puketapapa',
 'Tamaki',
 'Titirangi',
 'Upper Harbour Local Board Area',
 'Whau']
In [ ]:
df["Core"] = df.Name.isin(['Auckland Central',
 'Beach Haven-Birkenhead-Northcote',
 'Botany',
 'Devonport-Takapuna',
 'East Coast Bays',
 'Henderson-Massey',
 'Howick',
 'Mangere-Otahuhu',
 'Manurewa',
 'Maungakiekie',
 'Mt Albert',
 'Mt Eden',
 'Orakei',
 'Otara',
 'Pakuranga',
 'Papatoetoe',
 'Papakura',
 'Puketapapa',
 'Tamaki',
 'Titirangi',
 'Upper Harbour Local Board Area',
 'Whau'])
display(df[["Name", "Core"]])
Name Core
OBJECTID
1 Auckland Central True
2 Beach Haven-Birkenhead-Northcote True
3 Botany True
4 Devonport-Takapuna True
5 East Coast Bays True
6 Franklin-Beachlands-Hunua False
7 Franklin-Pukekohe False
8 Franklin-Waiuku False
9 Henderson-Massey True
10 Hibiscus Coast False
11 Howick True
12 Mangere-Otahuhu True
13 Manurewa True
14 Maungakiekie True
15 Mt Albert True
16 Mt Eden True
17 Orakei True
18 Otara True
19 Pakuranga True
20 Papakura True
21 Papatoetoe True
22 Puketapapa True
23 Rodney-Dairy Flat False
24 Rodney-Helensville False
25 Rodney-Kumeu-Riverhead False
26 Rodney-Warkworth False
27 Rodney-Wellsford False
28 Tamaki True
29 Titirangi True
30 Upper Harbour Local Board Area True
31 Waiheke False
32 Waitakere False
33 Whau True
In [ ]:
cmap = matplotlib.colors.ListedColormap(['orange', 'yellow'])
ax = df.plot(column = "Core", cmap=cmap, edgecolor="black", linewidth=.5)
xmin, xmax = ax.get_xlim()
ymin, ymax = ax.get_ylim()
print(xmin, xmax, ymin, ymax)
coastline.boundary.plot(ax=ax, color="gray", linewidth=.5)
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)

ax.add_artist(ScaleBar(1, location="lower left"))

x, y, arrow_length = 0.05, .98, 0.05
ax.annotate('N', xy=(x, y), xytext=(x, y-arrow_length),
            arrowprops=dict(facecolor='black', width=5, headwidth=15),
            ha='center', va='center', fontsize=20,
            xycoords=ax.transAxes)
ax.set_xticks([])
ax.set_yticks([])
1699039.1745048524 1809972.3879951476 5864874.988694763 6008322.51060524
Out[ ]:
[]
In [ ]: