A dev’s guide to building boundary maps with Australian suburbs

Charlie
7 min readJun 20, 2020

--

A while back I built an app for my employer-at-the-time that mapped every suburb in Australia where its services were offered.

The map highlighted the geographic area of each suburb we worked in, using a colour coding system to group suburbs into 50 or so sales regions.

It turns out that whilst dropping a few pins on a map is trivial, mapping geographic areas such as suburbs, electorates, councils etc is a different kettle of fish.

This article is not a tutorial in building maps. It does not cover the Mapbox GL or the Google Maps libraries. Instead I’m aiming to share what I learnt and in the process answer the questions I came up against:

  • How do I draw the boundary of an Australian suburb on a map?
  • Do I need data for that? What does that data even look like? Where do I get that data from?
  • How do I combine that data with my data to build something useful?
  • What file formats will I be using?
  • There’s nearly 4000 suburbs in Australia. That sounds like a lot of data. Do I have to worry about client-side performance?

Let’s get started.

The first thing I learnt about my project, is that if you want to map the boundary of an Australian suburb you’re gonna need some polygons.

#1 —polygons are a thing

The Vector data model is a common approach used to model features on the earth’s surface in a mapping system. The essential building blocks of this model are three data structures: points, lines & polygons. Each shape or “feature” is defined by one or more geographic locations known as vertices.

Vector data — points, lines, polygons — [reference link]

Polygons — so called for their closed shape, compromising more than two vertices — are perfect for representing geographical areas: states, school catchment areas, suburbs, electorates, flood zones, boroughs etc.

a polygon is data

here’s what a polygon looks like in GeoJSON (a lightweight, web-friendly vector format).

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
111.09374999999999,
-45.27488643704891
],
[
158.115234375,
-45.27488643704891
],
[
158.115234375,
-10.31491928581316
],
[
111.09374999999999,
-10.31491928581316
],
[
111.09374999999999,
-45.27488643704891
]
]
]
}
}
]
}

Copy the JSON above and paste it into Geojson.io to see it on a map!

Here’s a more useful example. This map represents the 12 suburbs in the City of Moreland.

suburbs in the City of Moreland, in Melbourne, Victoria

#2 — the best polygons in life are free

Obviously I didn’t hand draw the suburb polygons shown above (although there are tools for that). Someone’s already produced that data, and thanks to the Open Data movement, published it for free.

There is all manner of freely available geospatial data from skateparks in Ballarat to boroughs in New York. Closer to home, here’s an example of polygons in action from the City of Melbourne’s data portal, showing the City’s postcode boundaries.

City of Melbourne Postcode boundaries

Here’s the underground stations for the Melbourne Metro Tunnel project from the Vic Gov Data Portal.

* Melbourne Metro Tunnel underground stations in GeoJSON

To explore the staggering breadth of freely available Australian geospatial data checkout this extraordinary resource: https://nationalmap.gov.au/

#3 —the Aussie suburb polygon mother lode

For my purposes I needed a polygon for every suburb in every Australian state. It turns out there’s a single dataset for that.

It’s called the PSMA Administrative Boundaries Dataset, which includes…

“Australian Bureau of Statistics boundaries, electoral boundaries, state and territory boundaries, local government areas, suburbs/localities, wards and town points”.

It’s the mother lode of Australian suburb polygon data and it’s freely available.

In early 2016, the federal government — then led by Malcolm Turnbull — made the national PSMA Boundaries dataset freely available on the data.gov.au portal, under the Creative Commons Attribution 4.0 International license. A massive win for Open Data and for your next Australian mapping project!

See it for yourself

Using the nationalmap.gov.au website you can check out every Australian suburb polygon from the PSMA dataset.

the PSMA boundaries suburb localities dataset as seen on the nationalmap.gov.au

Take a wander here, and as you do, remember J.R.R Tolkien’s words

Not all those who wander are lost

#4 — vector features have metadata

As we learnt earlier, a vector feature — such as a point, line or polygon — defines a geometry used to represent a feature in the real world (such as a place of interest like Melbourne’s State Library, a cycle route or a suburb).

A feature on its own however is not very useful. To anchor this geometry in the real world, and therefore give it meaning, we must give it some metadata.

Putting that another way

the vector data model is not just about showing something on the map, it’s also about connecting that to data in a table that’s associated with that point, or line, or polygon

Let’s revisit the Melbourne suburbs example from earlier.

suburbs in the City of Moreland, in Melbourne, Victoria

Here’s a trick

  1. copy the raw JSON from this gist to the clipboard
  2. head over to geojson.io and past the JSON into the text box. You should now see the suburbs rendered on a map.
  3. Click the table tab. You’re now seeing the metadata for each of the suburb polygons!

Notably each feature has a descriptive name, such as “Coburg” or “Brunswick” (see column titled vic_loca_2) and each feature has a primary key such as “VIC593” or “VIC361” (see column titled loc_pid).

Not massively useful on it’s own, but as we shall see, it’s a good start.

#5 — you can add more metadata to your vector features with SQL

Here’s where things get interesting.

All the popular relational databases — Postgres, MySQL, SQL Server — have extensions that give those databases geospatial superpowers.

Here’s how our suburbs polygons dataset might look when imported into a Postgres database with the Postgis extension installed.

geospatial data is tabular man! (screenshot from Carto.com)

The simple SQL in the screenshot illustrates how to query a polygon dataset of all suburbs in Victoria for just those suburbs in Melbourne’s City of Moreland.

You forgot Fitzroy North

My City of Moreland map is actually incomplete. There is a small part of Fitzroy North that is within Moreland’s boundary. But how do you draw a portion of a polygon? This is where spatial queries come in.

If I had a polygon for the boundary of Moreland (which you can also get from the PSMA Administrative Boundaries dataset) and a polygon for the suburb of Fitzroy North, I could easily achieve this by running a simple spatial intersection query.

just add data!

Let’s say I want to build a map showing the density of hipsters in each suburb in the City of Moreland. Thankfully I’ve got a csv file with hipsters_per_mille for every suburb in Melbourne.

All I need is some SQL magic to combine the polygon spatial data and the hipster data into a single table.

Now I have what I need in one table for my hipster map: the polygons and the relevant metadata.

I can now export that to a suitable vector data file format such as GeoJSON, do a little magic in Mapbox Studio (no coding necessary) and voila: a Hipster choropleth map!

Hipster density in Melbourne’s City of Moreland. For mason jars try Brunswick!

6 — go server-side with your spatial data to make huge maps fast

In Mapbox GL JS (see here) or Google Maps JS(see here) you can load some GeoJSON from a local file (or in the code itself) to render a polygon on a map.

If you view the source of any Domain.com.au suburb profile page (e.g Brunswick) you’ll see this is exactly how they map the boundary of the profiled suburb.

But that’s not going to cut it if you want to show the nearly 4000 suburbs in Australia on a single map. The file-size of that geojson is simply too large for a performant app experience.

Get your spatial data server-side

To solve this problem you want your spatial data server-side.

Mapbox is great for this. It let’s you upload your vector dataset to their platform (in Shapefile, GeoJSON and other vector formats). Mapbox takes care of delivering your data to the client in a performant way, thanks to the magic of vector tiles.

As far as I can tell, Google Maps no longer offers a means to upload your own spatial data, certainly not since they decommissioned the Google Maps Engine.

7 — A few last things about PSMA Administrative boundaries dataset

  • It’s not so much one dataset as it is a collection of boundary datasets across seven themes: Australian Bureau of Statistics (ABS) boundaries, electoral boundaries, state and territory boundaries, local government areas (i.e the City of Moreland), suburbs/localities, wards (i.e the North-East Ward determines who my Moreland Council councillor is) and town points.
  • You can download the latest datasets in the collection from this page on the data.gov.au portal.
  • The latest national PSMA “suburb localities” dataset is around 155 megabytes or so, is broken out state-by-state and updated twice yearly.
  • The suburb localities dataset is provided in Shapefile file format, which confusingly is a common vector file format comprising not one but many files.
  • Grab the GDA2020 version. An explanation of the Geocentric Datum of Australia is given here.
  • The dataset does not include postcode metadata, which is a shame. But Australia Post is only too happy to sell you that. :-(
  • There’s some data setup you have to do once you’ve downloaded the dataset. I’ll probably write a follow up article about that.

That’s it folks! Hopefully this makes your first project mapping Australian suburb boundaries ever so slightly easier.

--

--