Making Maps for Australia States and Local Government Areas in R

Kan Nishida
learn data science
Published in
5 min readJan 6, 2017

--

Australian Bureau of Statistics provides a series of the boundaries data. Once you download them, you can simply convert them to GeoJSON in R so that you can start visualizing Australian data geographically using modern tools like Exploratory.

This is similar to what I have done for making maps for Canada, except that, although most of the boundaries data comes in ESRI Shapefile format, this particular boundaries data for the population data I was working on was available only in Google Earth format, not in ESRI Shapefile that I’m used to.

It turned out that converting Google Earth format to GeoJSON is not much different from converting ESRI Shapefile to GeoJSON, with a tiny caveat, which I will describe below.

If you just want to grab the GeoJSON files for Australian States and Local Government Areas, you can download them from our Map Gallery page.

If you are interested in making them by yourself, here’s how. I’ll start with a simple one, that is for Australian States and Territories, then move on to the one with Google Earth format.

Australian States and Territories

Download Shapefile

As mentioned above, you can download the boundaries data of Australian States and Territories in Shapefile format from this page at Australian Bureau of Statistics.

Convert to GeoJSON

Once you have downloaded, then you can load it into R, convert it to GeoJSON format, simplify it, then write it out to your file system.

library(rgdal)
library(spdplyr)
library(geojsonio)
library(rmapshaper)
# Load Australian State and Territories shapefile data
aus_ste <- readOGR(dsn = "/Users/kannishida/Downloads/STE11aAust", layer = "STE11aAust")
# Convert to GeoJSON
aus_ste_json <- geojson_json(aus_ste)
# Simplify the polygons to reduce the size
aus_ste_sim <- ms_simplify(aus_ste_json)
# Write GeoJSON file out to a file system
geojson_write(aus_ste_sim, file = "/Users/kannishida/Downloads/aus_ste.geojson")

Once the GeoJSON is created, then we can register it to Exploratory.

Register to Exploratory

Click GeoJSON for Map menu on Project List page in Exploratory.

When you register, you want to select an appropriate Key Property to map with your data. In my case, I have selected ‘STATE_NAME’.

And once you register it to your Exploratory, you can start visualizing the data like below.

Australian Local Government Areas

I downloaded this data set called ‘Population growth of 2014–2015 for Australian Local Government Areas’ to analyze their population growth at the local government areas level. Conveniently, the data is accompanied by a corresponding boundary data.

This is actually great because the one listed on another page of Australian Bureau of Statistics website, where you can find a series of the boundaries data for different administrative levels, didn’t have the perfect matching for this population growth data.

Only thing is, as I mentioned above, this boundaries data is available only in Google Earth format. But it turned out this data format is also supported by ‘readOGC’ function from ‘rgdal’ package.

Once you download the zip file of ‘LGA data in Google Earth format, Australia, 2005 to 2015’, you want to unzip the file first. After you unzipped it, you will find a file called ‘32180 LGA ERP 2015.kmz’. This is actually still a compressed file, which means that you need to explicitly unzip this file by using ‘unzip’ command in Terminal (for Mac).

Once it’s uncompressed, you will find ‘doc.kml’ file. And this is what you want to import into R by using ‘readOGR’ function from ‘rgdal’ package, which had no problem dealing with Google Earth format, yay! 🎉

But there is one thing. You need to find a value to set for ‘layer’ argument of ‘readOGR’ function, which you can find inside the ‘doc.kml’ file. Basically, what you want to look for is ‘id’ attribute in ‘Scheme’ element.

In this case, that is ‘NewFeatureType’, and you can set it to ‘layer’ argument inside ‘readOGR’ function like below when you load the ‘.kml’ file into R.

# Load Australia Local Government Area in Google Earth format into R
aus_LGA <- readOGR(dsn = "/Users/kannishida/Downloads/doc.kml", layer = "NewFeatureType")

Once it’s imported as SpatialPolygonDataFrame in R, the rest is the same as for any other spatial data. Convert it to GeoJSON format, simplify it, then save to a file system.

# Convert to GeoJSON
aus_LGA_json <- geojson_json(aus_LGA)
# Simplify the polygons to reduce the size
aus_LGA_sim <- ms_simplify(aus_LGA_json)
# Write GeoJSON file out to a file system
geojson_write(aus_LGA_sim, file = "/Users/kannishida/Downloads/aus_LGA2.geojson")

Once the GeoJSON is created, then we can register it to Exploratory.

Register to Exploratory

Click ‘GeoJSON for Map’ menu on Project List page in Exploratory.

When you register, you want to select an appropriate Key Property to map with your data. In my case, I have selected ‘Name’.

Once it’s registered, you can start visualizing the data like below.

Happy Australian Map!

You can download the GeoJSON files from our Map Gallery page and try them out quickly in Exploratory. If you don’t have Exploratory yet, you can sign up from here.

--

--

CEO / Founder at Exploratory(https://exploratory.io/). Having fun analyzing interesting data and learning something new everyday.