In [1]:
import geopandas as gpd # Loading geospatial data
import pandas as pd # Tabular data
from taumahi import kupu_māori # Detecting Māori words)
pd.set_option('display.max_rows', 200)
In [2]:
df = gpd.read_file("lds-nz-roads-addressing-FGDB.zip!nz-roads-addressing.gdb")
df
Out[2]:
road_id | geometry_class | road_type | road_name_class | full_road_name | road_name_label | road_name_prefix | road_name_body | road_name_type | road_name_suffix | route_name_body | route_name_number | route_name_alpha | route_name_suffix | full_road_name_ascii | road_name_label_ascii | road_name_body_ascii | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 3073671 | Addressing Road | Unknown | Road Designation | State Highway 73A | SH 73A | None | None | None | None | State Highway | 73.0 | A | None | State Highway 73A | SH 73A | None | MULTILINESTRING ((172.52566 -43.54343, 172.525... |
1 | 3073717 | Addressing Road | Unknown | Road Designation | State Highway 71 | SH 71 | None | None | None | None | State Highway | 71.0 | None | None | State Highway 71 | SH 71 | None | MULTILINESTRING ((172.64672 -43.37443, 172.647... |
2 | 3073674 | Addressing Road | Unknown | Road Designation | State Highway 53 | SH 53 | None | None | None | None | State Highway | 53.0 | None | None | State Highway 53 | SH 53 | None | MULTILINESTRING ((175.45919 -41.21821, 175.458... |
3 | 3073698 | Addressing Road | Unknown | Road Designation | State Highway 62 | SH 62 | None | None | None | None | State Highway | 62.0 | None | None | State Highway 62 | SH 62 | None | MULTILINESTRING ((173.81710 -41.48653, 173.827... |
4 | 3073673 | Addressing Road | Unknown | Road Designation | State Highway 20A | SH 20A | None | None | None | None | State Highway | 20.0 | A | None | State Highway 20A | SH 20A | None | MULTILINESTRING ((174.78502 -36.98478, 174.785... |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
78940 | 3033968 | Addressing Road | Unknown | Road | Jones Avenue | Jones Ave | None | Jones | Avenue | None | None | NaN | None | None | Jones Avenue | Jones Ave | Jones | MULTILINESTRING ((168.77638 -45.00638, 168.777... |
78941 | 3036998 | Addressing Road | Unknown | Road | Wanganui Road | Wanganui Rd | None | Wanganui | Road | None | None | NaN | None | None | Wanganui Road | Wanganui Rd | Wanganui | MULTILINESTRING ((175.37217 -40.06787, 175.370... |
78942 | 3040670 | Addressing Road | Unknown | Road | Wellington Urban Motorway | Wellington Urban Mwy | None | Wellington Urban | Motorway | None | None | NaN | None | None | Wellington Urban Motorway | Wellington Urban Mwy | Wellington Urban | MULTILINESTRING ((174.77204 -41.29388, 174.771... |
78943 | 3049837 | Addressing Road | Unknown | Road | Ahuroa Road | Ahuroa Rd | None | Ahuroa | Road | None | None | NaN | None | None | Ahuroa Road | Ahuroa Rd | Ahuroa | MULTILINESTRING ((174.66110 -36.51192, 174.661... |
78944 | 3056843 | Addressing Road | Unknown | Road | Tunnel Road | Tunnel Rd | None | Tunnel | Road | None | None | NaN | None | None | Tunnel Road | Tunnel Rd | Tunnel | MULTILINESTRING ((172.71672 -43.60220, 172.717... |
78945 rows × 18 columns
In [3]:
df["is_māori"] = df.full_road_name[~pd.isna(df.full_road_name)].apply(lambda name: len(kupu_māori(name)) > 0)
df.is_māori.value_counts(dropna=False)
Out[3]:
is_māori False 61179 True 14577 NaN 3189 Name: count, dtype: int64
In [4]:
display(df[df.is_māori == True][["full_road_name", "is_māori"]])
display(df[df.is_māori == False][["full_road_name", "is_māori"]])
full_road_name | is_māori | |
---|---|---|
5 | State Highway 30 Te Teko | True |
140 | Marama Street | True |
148 | Wiremu Way | True |
162 | Matai Street | True |
172 | Tawiri Place | True |
... | ... | ... |
78931 | Mera Road | True |
78938 | Hamiora Street | True |
78939 | Atawhai Drive | True |
78941 | Wanganui Road | True |
78943 | Ahuroa Road | True |
14577 rows × 2 columns
full_road_name | is_māori | |
---|---|---|
0 | State Highway 73A | False |
1 | State Highway 71 | False |
2 | State Highway 53 | False |
3 | State Highway 62 | False |
4 | State Highway 20A | False |
... | ... | ... |
78936 | Woodford Avenue | False |
78937 | Laban Place | False |
78940 | Jones Avenue | False |
78942 | Wellington Urban Motorway | False |
78944 | Tunnel Road | False |
61179 rows × 2 columns
In [5]:
ax = df.plot(column="is_māori", legend=True, figsize=(20,20), categorical=True)
ax.set_title("Road names containing Māori words in NZ")
Out[5]:
Text(0.5, 1.0, 'Road names containing Māori words in NZ')
In [6]:
df.to_file("lds-nz-roads-addressing-kupu_māori.gpkg", layer='roads', driver="GPKG")
In [7]:
akl = gpd.clip(df, (174.3311,-37.1231,175.2470,-36.6464))
akl
Out[7]:
road_id | geometry_class | road_type | road_name_class | full_road_name | road_name_label | road_name_prefix | road_name_body | road_name_type | road_name_suffix | route_name_body | route_name_number | route_name_alpha | route_name_suffix | full_road_name_ascii | road_name_label_ascii | road_name_body_ascii | geometry | is_māori | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
130 | 3073727 | Addressing Road | Unknown | Road Designation | State Highway 1 | SH 1 | None | None | None | None | State Highway | 1.0 | None | None | State Highway 1 | SH 1 | None | MULTILINESTRING ((174.95201 -37.11788, 174.954... | False |
37892 | 1823659 | Addressing Road | Unknown | Road | Whatipu Road | Whatipu Rd | None | Whatipu | Road | None | None | NaN | None | None | Whatipu Road | Whatipu Rd | Whatipu | MULTILINESTRING ((174.50075 -37.04198, 174.509... | True |
68548 | 3057113 | Addressing Road | Unknown | Road | Taimana Stream Road | Taimana Stream Rd | None | Taimana Stream | Road | None | None | NaN | None | None | Taimana Stream Road | Taimana Stream Rd | Taimana Stream | LINESTRING (174.45101 -36.89618, 174.45114 -36... | True |
19975 | 1831287 | Addressing Road | Unknown | Road | McKay Place | McKay Pl | None | McKay | Place | None | None | NaN | None | None | McKay Place | McKay Pl | McKay | LINESTRING (174.45062 -36.89056, 174.45084 -36... | False |
3205 | 1823658 | Addressing Road | Unknown | Road | Erangi Place | Erangi Pl | None | Erangi | Place | None | None | NaN | None | None | Erangi Place | Erangi Pl | Erangi | LINESTRING (174.45044 -36.88861, 174.45063 -36... | True |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
5240 | 1830965 | Addressing Road | Unknown | Road | Hull Road | Hull Rd | None | Hull | Road | None | None | NaN | None | None | Hull Road | Hull Rd | Hull | LINESTRING (174.58424 -36.64640, 174.58526 -36... | False |
36277 | 1821018 | Addressing Road | Unknown | Road | Anderson Road | Anderson Rd | None | Anderson | Road | None | None | NaN | None | None | Anderson Road | Anderson Rd | Anderson | LINESTRING (174.49255 -36.64640, 174.49260 -36... | False |
69186 | 3001933 | Addressing Road | Unknown | Road | Kahikatea Flat Road | Kahikatea Flat Rd | None | Kahikatea Flat | Road | None | None | NaN | None | None | Kahikatea Flat Road | Kahikatea Flat Rd | Kahikatea Flat | LINESTRING (174.64269 -36.64860, 174.64087 -36... | True |
121 | 3073667 | Addressing Road | Unknown | Road Designation | State Highway 16 | SH 16 | None | None | None | None | State Highway | 16.0 | None | None | State Highway 16 | SH 16 | None | MULTILINESTRING ((174.70389 -36.87275, 174.704... | False |
70901 | 3007739 | Addressing Road | Unknown | Road | Kaipara Coast Highway | Kaipara Coast Hwy | None | Kaipara Coast | Highway | None | None | NaN | None | None | Kaipara Coast Highway | Kaipara Coast Hwy | Kaipara Coast | MULTILINESTRING ((174.45032 -36.66343, 174.450... | True |
13127 rows × 19 columns
In [8]:
ax = akl.plot(column="is_māori", legend=True, figsize=(20,20), categorical=True)
ax.set_title("Road names containing Māori words in Auckland")
ax.set_xlim(174.3311,175.2470)
ax.set_ylim(-37.1231,-36.6464)
Out[8]:
(-37.1231, -36.6464)
In [9]:
from shapely import box
ax = gpd.GeoSeries([box(*akl.total_bounds)]).plot(color="black", figsize=(20,20))
akl.plot(color="#CD8833", ax=ax, linewidth=.5)
ax.set_xlim(174.3311,175.2470)
ax.set_ylim(-37.1231,-36.6464)
ax.figure.savefig("auckland_roads.png", bbox_inches="tight", dpi=1200)
In [10]:
akl["length"] = akl.to_crs(2193).length
In [11]:
from matplotlib import pyplot as plt
ax = gpd.GeoSeries([box(*akl.total_bounds)]).plot(color="black", figsize=(20,20))
akl.plot("length", ax=ax, linewidth=.3, figsize=(20,20), cmap="hsv")
ax.set_xlim(174.3311,175.2470)
ax.set_ylim(-37.1231,-36.6464)
Out[11]:
(-37.1231, -36.6464)
In [12]:
ax = gpd.GeoSeries([box(*akl.total_bounds)]).plot(color="black", figsize=(20,20))
akl.plot("length", ax=ax, linewidth=.3, figsize=(20,20))
ax.set_xlim(174.3311,175.2470)
ax.set_ylim(-37.1231,-36.6464)
Out[12]:
(-37.1231, -36.6464)
In [21]:
akl[akl.full_road_name.str.contains("Hamilton Road",na=False)].plot()
Out[21]:
<Axes: >
In [25]:
with open('akl.svg', 'w') as f:
f.write(akl.unary_union._repr_svg_())