As explained yesterday, one of the first things we need to do is decide on the granularity for the analysis. The New Zealand Electoral Commission makes election results available at the polling place-level, which makes them a good place to start, but difficulties occur when polling places are discontinued or new polling places are added between elections, and also when there is significant migration, such as that which occurred in and around Christchurch after the 2011 Christchurch Earthquake. As such we need to look at where the polling places are physically located, and try to understand what happens to voter turnout between elections at the polling place-level. This will give us an idea of where New Zealanders actually cast their votes.

But first, an aside on geographic datums.

The surface of the earth is flat, at least to first approximation. This means that instead of dealing with spherical coordinates, such as longitude and latitude, it is often preferable to project the surface onto a plane, and treat it as a two-dimensional cartesian space where points are described by an x-coordinate and a y-coordinate (and a “height”, if necessary). One example of such a projection is the New Zealand Transverse Mercator (NZTM) produced by LINZ specifically to represent the New Zealand mainland accurately. Points are given as an “easting” (the x-coordinate) and a “northing” (the y-coordinate), and are expressed in meters east and north of an arbitrary reference point to the southwest of the country. Because the NZTM is a conformal map shapes and direction are preserved, and it is therefore easy to calculate distances and bearings between nearby points.

As it happens, Elections New Zealand have handily produced a list of all the polling places used in the 2008 and 2011 elections along with their NZTM coordinates. When we combine this information with the 2011 election party vote results by polling place we get a good idea of where people are voting. The NZ Herald have an excellent interactive map that shows where the polling places fall under the previous 2008 electoral boundaries and the new 2014 electoral boundaries. But we can go further and aggregate the information to look at, for example, the centre of gravity of each electorate as defined by the average of the polling place locations weighted by votes. Results are as follows.

Clicking on the points shows the electorate name and number, total party votes (excluding special votes), and location in latitude and longitude.

One thing that immediately stands out is how sparsely populated much of the country is. At a fundamental level the map is really only showing population density, but even then it is surprising that if you were to draw a line from Nelson to Invercargill and carve off everything to the west then that quarter-or-so of New Zealand’s land area would contain only a single electorate seat (West Coast-Tasman). Similarly the middle of the North Island is pretty empty; if you were to cut out an area from Whakatane to New Plymouth to Whanganui to Napier you would have over one-third of the North Island and it would contain only a single electorate seat: East Coast. (The Taupō electorate has been dragged north by polling places in Tokoroa and Cambridge.)

Of course you may think that this is a bit gimmicky, and you’d be right. With the exception of a bit of data-vis showing election results this kind of thing isn’t of much use. The real reasons why we want the polling place geodata are four-fold:

**Boundary changes.**The New Zealand Electoral Commission has just finished the latest review of electorate boundaries. In order to simulate election results for the 2014 or 2017 elections we must figure out where each of the polling places used in the 2011 and 2008 elections are and which new electorate they now fall in.**Discontinued polling places.**At every election some former polling places are discontinued, and other new polling places are added. If we make the reasonable assumption that most people will vote at their nearest polling place then we can somewhat predict votes and turnout at polling places for the 2014 election even if they were not used for previous elections.**Regression**. If we know the physical locations of each polling place, and again make reasonable assumptions about where people vote then we can at least theoretically make comparisons with the Census meshblock-level data from Statistics NZ and try and predict people’s votes based on their age, education, income, family size and so on. A little outside the scope of my work here, but it would be a fascinating project.**Get-out-the-vote**. Certain polling places will have a higher proportion than others of swing voters. Depending on your political leanings polling place geodata will tell you where you need to concentrate your get-out-the-vote efforts.

The next post will look at political segregation in different electorates.

**Appendix**

I don’t have a lot of experience handling geodata, and it took a bit of effort to get the coordinate transforms into longitude and latitude working properly so that the results would show up correctly in Google Maps. By far the best solution I found was to use the PROJ.4 – Cartographic Projections Library. As I’m using python I needed the pyproj wrapper for PROJ. On Mac the easiest way to get it is to use pip as follows:

`curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python`

pip install pyproj

There is an excellent tutorial on using geospatial data with python from the SciPy 2013 conference (see the first video). The secret is to instantiate PROJ classes using the European Petroleum Survey Group (EPSG) Geodetic Parameter Dataset code numbers:

`import pyproj`

nztm_proj = pyproj.Proj("+init=EPSG:2193")

latlong_proj = pyproj.Proj("+init=EPSG:3857")

long, lat = pyproj.transform(nztm_proj, latlong_proj, easting, northing)

**keywords: python, PROJ, pyproj, NZTM, Google Maps, EPSG.**