In [121]:
import geopandas
In [122]:
postcode_shp = geopandas.read_file('aus_poas.shp')
postcode_shp.head()
Out[122]:
| POA_NAME | code | state | geometry | |
|---|---|---|---|---|
| 0 | 6000 | 6000 | None | POLYGON ((115.86782 -31.9534, 115.86782 -31.95... |
| 1 | 6003 | 6003 | None | MULTIPOLYGON (((115.85039 -31.9457, 115.85065 ... |
| 2 | 6004 | 6004 | None | POLYGON ((115.86782 -31.9534, 115.86781 -31.95... |
| 3 | 6005 | 6005 | None | POLYGON ((115.84809 -31.93646, 115.84809 -31.9... |
| 4 | 6006 | 6006 | None | POLYGON ((115.84641 -31.9242, 115.84635 -31.92... |
In [123]:
# Plot the whole geopandas dataframe
#ax = postcode_shp.plot()
fig, ax = plt.subplots(1, figsize=(10,8))
postcode_shp.plot(column='code', cmap='Accent', legend=True, ax=ax)
plt.title('Australia by Postcode')
plt.show()
In [124]:
# Calculate area of each postcode
# Check current coordinate reference system
print(postcode_shp.crs)
# Convert to a projected coordinate system so area can be calculated properly
postcode_shp_lamb = postcode_shp.to_crs(epsg=3112)
ax = postcode_shp_lamb.plot()
# Convert Area in m2 to Km2
postcode_shp_lamb['Area(km2)'] = postcode_shp_lamb.area/1000000
postcode_shp_lamb.head()
fig, ax = plt.subplots(1)
postcode_shp_lamb.plot(column='Area(km2)', cmap='RdPu', legend=True, ax=ax)
ax.set_title("Australia's Biggest Postcode by Area")
EPSG:4283
Out[124]:
Text(0.5, 1.0, "Australia's Biggest Postcode by Area")
In [125]:
# Plot each State with 1- biggest postcodes
def plotState(statename, querycode):
state_shp = postcode_shp_lamb.query(querycode)
# Find the postcodes with biggest area
print(" Ten Biggest Postcodes by Area in " + statename)
#print(state_shp.sort_values(by=['Area(km2)'], ascending=False).head(5))
print(state_shp.sort_values(by=['Area(km2)'], ascending=False).loc[:,['code', 'Area(km2)']].head(10))
fig, ax = plt.subplots(1)
state_shp.plot(column='Area(km2)', cmap='RdPu', legend=True, ax=ax)
ax.set_title(statename + ' Biggest Postcode by Area')
#vic_shp_lamb.head(10)
fig, ax = plt.subplots(1)
state_shp.plot(column='code', cmap='jet', legend=True, ax=ax)
ax.set_title(statename + ' Map By Postcode Distribution')
plotState('Victoria', 'code >= 3000 & code <= 3999')
Ten Biggest Postcodes by Area in Victoria
code Area(km2)
614 3490 11365.203386
1515 3888 5366.068914
592 3401 4780.159329
617 3496 4241.238752
1255 3858 4029.050865
622 3507 3488.073331
1512 3885 3356.127278
1085 3723 3164.307152
1258 3862 3153.682827
624 3512 3100.298504
In [126]:
plotState('Queensland', 'code >= 4000 & code <= 4999')
Ten Biggest Postcodes by Area in Queensland
code Area(km2)
2433 4871 221835.304538
2327 4829 152413.050355
2416 4825 109231.788248
2265 4492 71991.311791
2259 4480 65799.932561
2451 4890 64333.522294
2260 4481 60399.916546
2291 4733 52835.991891
2270 4702 47282.576169
2264 4490 46473.078707
In [127]:
plotState('New South Wales','(code >= 2000 & code <= 2599) or (code >= 2619 & code <= 2899)or (code >= 2921 & code <= 2999)' )
Ten Biggest Postcodes by Area in New South Wales
code Area(km2)
2239 2880 91479.406727
2238 2840 41111.223529
1034 2835 31025.549412
2236 2836 26645.186397
517 2879 25904.669708
510 2648 25733.236498
1035 2877 20759.129008
681 2715 20188.057491
2232 2831 19799.954435
850 2711 16842.995475
In [128]:
plotState('Northern Territory','code >= 800 & code <= 899')
Ten Biggest Postcodes by Area in Northern Territory
code Area(km2)
2212 872 1.180521e+06
2399 852 4.166099e+05
2384 822 1.494598e+05
2402 862 1.033231e+05
2393 840 6.484261e+03
2387 830 1.265572e+03
2398 850 5.638089e+02
2397 847 4.132131e+02
2211 870 3.206348e+02
2392 838 2.386796e+02
In [129]:
plotState('Tasmania','code >= 7000 & code <= 7799')
Ten Biggest Postcodes by Area in Tasmania
code Area(km2)
1298 7030 6614.651879
1182 7321 3802.861351
1310 7140 3002.196109
1176 7304 2746.964698
1019 7330 2332.838957
1188 7469 2233.720171
1524 7190 1788.954106
1529 7264 1753.249793
1309 7120 1688.926854
1337 7255 1449.605656
In [130]:
plotState('Western Australia','code >= 6000 & code <= 6797')
Ten Biggest Postcodes by Area in Western Australia
code Area(km2)
2369 6646 177112.258907
2379 6762 175592.127491
2510 6770 134574.075222
2342 6429 122744.504136
2347 6436 121765.829128
2506 6728 101979.217339
2507 6740 98005.743795
2368 6642 97830.121717
335 6443 91001.883531
2496 6635 71216.603038
In [131]:
plotState('South Australia','code >= 5000 & code <= 5799')
Ten Biggest Postcodes by Area in South Australia
code Area(km2)
2335 5731 252099.541247
2329 5710 212242.140656
2328 5690 189743.957664
504 5440 61701.090859
2333 5724 18123.406838
258 5607 9468.644532
271 5680 6121.001406
265 5641 4616.394751
650 5267 4381.285504
209 5433 4043.585386
In [132]:
plotState('Australian Capital Territory Map','(code >= 2600 & code <= 2618) or (code >= 2900 & code <= 2920)')
Ten Biggest Postcodes by Area in Australian Capital Territory Map
code Area(km2)
1409 2611 510.351084
1414 2618 265.188702
1408 2609 132.362301
1412 2615 98.943993
1501 2900 80.729676
1508 2912 54.152505
1413 2617 26.141415
1402 2602 22.690366
1400 2600 21.397889
1505 2905 19.752223
In [133]:
# Save the projected map to a file
postcode_shp_lamb.to_file("aus_poas_lambert2.shp")