In this article i'll describe how I coded a map of all the postoffices in australia. Really this technique could be used to map anything you want, such as the location of all sales made in the last month, or the location of all your offices/stores/franchises/whatever. Download the code / executable here [[posterous-content:HAnpfhJibmIbfziCjlGC]] In a previous article I wrote about how to get the latitude and longitude of all the postcodes in australia into a CSV file called 'PostcodeLatLng.csv', with the contents something like this:
Postcode,Lat,Lng
2000,-33.869027,151.210245
...
Next up you'll need a map of australia. I took some screenshots of google maps and pasted them together using Paint.net. After that, i converted it to black and white and darkened it a bit, so that the 'blobs' would stand out better. Here's my resultant 'map.jpg': [[posterous-content:khHqokzDuwJbywCrCElz]] Then you'll need some way of mapping longitude and latitude to pixel x,y on the map. To do this, i got the x,y coordinates of each of the capitals and wrote it in a 'map.txt' file, along with their postcode:
Postcode,Name,X,Y
6000,Perth,111,546
5000,Adelaide,627,627
3000,Melbourne,773,709
2600,Canberra,868,637
2000,Sydney,915,598
4000,Brisbane,956,429
4870,Cairns,791,169
7000,Hobart,827,860
7250,Launceston,822,816
So now you've got enough information to convert a postcode into an X,Y location on the given map. The general idea is to convert the postcode into a longitude/latitude; then find the X/Y of the nearest 2 capital cities, and interpolate the long/lat values to create X/Y values. Finally, you'll need an input file with a list of postcodes of interest that you wish to plot, and the colour you wish to plot them. I'm using the following format for this in a file named 'PlotData.csv' (Postcode, Hex-RGB):
1001,633714
1002,267428
1003,891142
1004,524856
1005,158570
1006,782284
1007,415998
1008,49612
1009,673326
1010,307040
The full source code is available below. This code also contains a plotting function that generates a heatmap rather than points for each selected postcode. Note that in this article, i've supplied the map as a JPG for the sake of my bandwidth, whereas the code expects a PNG, which you can create using Paint.Net or photoshop. http://pastebin.com/f4d6bf06d

Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.

Chris Hulbert

(Comp Sci, Hons - UTS)

iOS Developer in Sydney.

I have worked at places such as Google, Cochlear, News Corp, Fox Sports, NineMSN, FetchTV, Woolworths, and Westpac, among others. If you're looking for a good iOS developer, drop me a line!

Get in touch:
[email protected]
github.com/chrishulbert
linkedin
my resume



 Subscribe via RSS