## Follow-up: geometric median centres of population

Mean and geometric median centres of population. Click to expand.

My post yesterday discussed the mean centres of population of South Africa and its provinces. The mean centre is (relatively) easy to calculate, but it may not be the most useful type of population centre. It is essentially an arithmetic mean, which means that outliers can have a massive effect on the centre. It minimizes the average square of distance from the centre, not the average distance from the centre. The centre that does minimize the average distance is called the geometric median, and it is not quite so simple to calculate, since there is no closed form solution. But it can be done!

## Methodology

Finding the geometric median uses an iterative method known as Weiszfeld's algorithm, which is described in section 2.2 here (amongst many other places). As before, the calculations were performed using a PostGIS spatial database with the small area layer from Census 2011. The code implementing Weiszfeld's algorithm is in this GitHub repository; it is a naive implementation but sufficient for this purpose.

## Results

The national geometric median centre of population is at 26.84307°S 28.23545°E, on Bezuidenhoutsberg just north of Vaal Marina on the Vaal Dam. This point is 75km south of the Johannesburg CBD and very close to the tripoint of Gauteng, Mpumalanga and the Free State. It is 165km north (and a bit east) of the mean centre of population.

The provincial geometric medians are:

• Eastern Cape: 32.16487°S 27.86171°E - Sigingqini village in the former Transkei, 90km north of East London. 25km north-east of the mean centre.
• Free State: 28.33606°S 27.06762°E - on Helpmekaar farm just off the N1 highway between Winburg and Ventersburg, 120km north-east of Bloemfontein. 15km north-west of the mean centre.
• Gauteng: 26.14121°S 28.06846°E - in Abbotsford, near the M1 freeway, 7km north of Johannesburg CBD. 4km south of the mean centre.
• KwaZulu-Natal: 29.60336°S 30.85128°E - Upper Mantungwa village below Nanda Hill, 30km north-west of Durban CBD. 40km south of the mean centre.
• Limpopo: 23.82932°S 29.83916°E - Mohlatsweng village, 35 km east of Polokwane. 3km east of the mean centre.
• Mpumalanga: 25.73029°S 30.20358°E - on Dalmanutha farm near Machadodorp, 80 km west of Nelspruit and 100 km east of Witbank. Less than 1km from the mean centre.
• North West: 26.01753°S 26.70463°E - on Skaapplaas farm, 65km south-west of Rustenburg and 100km east of Mahikeng.
• Northern Cape: 28.47446°S 23.63121°E - on Nooitgedacht farm just outside Papkuil, 110km west of Kimberley. 65kim north-east of the mean centre.
• Western Cape: 33.96004°S 18.65801°E - in Blackheath, just off the R300 freeway, 20km east of Cape Town CBD. 45km west of the mean centre.

## Centres of population of South Africa

Follow-up: a subsequent post describes the geometric median centre of population, which is some respects a more sensible definition than the mean centre of population described here.

National and provincial centres of population, with population density. Click to expand.

The centre of population is a point that represents an "average" location of the people in a country or other area; exactly what that "average" is depends on the way the centre is calculated. As far as I can tell, nobody has calculated a centre of population of South Africa; at least nobody has published it anywhere that Google can find. So I've calculated one myself, both out of interest and also in case anyone else finds it useful. I also calculated the centre of population of each province.

## Methodology

The method of calculation is that described in the US Census Bureau publication Centers of Population Computation for the United States. This method produces a mean centre of population, and adjusts for the fact that the distance between meridians (lines of longitude) decreases with latitude. The calculations were performed in a PostGIS spatial database using the Census 2011 small area layer, the most detailed level of population data available fron the census.

## Results

The national centre of population is located at 28.28430°S 27.70690°E, at the foot of Ghwarriekop just outside the town of Senekal in the Free State. (If we ever decide to move all the branches of national government to one place, perhaps Senekal should be the site.) The population centre is substantially further east than the geographic centre of South Africa because South Africa is much more densely populated in the east than the west, as can be seen from the map above.

The provincial centres of population are:

• Eastern Cape: 32.25099°S 27.60710°E - at Dratini village on the Great Kei River, 90 km north of East London.
• Free State: 28.39131°S 27.21450°E - on Eendracht farm between Winburg and Senekal, 120 km north-east of Bloemfontein.
• Gauteng: 26.10533°S 28.07713°E - in Sandton, on the M1 freeway where it passes Innesfree Park.
• KwaZulu-Natal: 29.22932°S 30.83280°E - at KwaNjengabantu in the Umvoti River valley, 70 km north of Durban.
• Limpopo: 23.82332°S 29.80877°E - between Makgwareng and Mohlatsweng villages, 35 km east of Polokwane.
• Mpumalanga: 25.72471°S 30.19713°E - on Driefontein farm near Machadodorp, 80 km west of Nelspruit and 100 km east of Witbank.
• North West: 26.10084°S 26.54186°E - on the farm Goedvooruitzicht close to the village of Ga-Motlala, 90 km equidistant from Mafikeng, Rustenburg and Klerksdorp.
• Northern Cape: 28.69990°S 23.02761°E - on the farm Onderongeluk near Griekwastad, 170 km west of Kimberley.
• Western Cape: 33.84144°S 19.14170°E - in the Haweqwa Nature Reserve north of Franschhoek, 60 km east of Cape Town.

## Getting rid of the decimal comma in Ubuntu

At some point in school, we South Africans are told that the official decimal separator is the comma.1 Most of us then proceed to ignore this—at least in English use2—because it differs from the decimal point used in the rest of the English-speaking world, and thereby creates confusion. Thankfully, the maintainers of the glibc locale data—and thus the number formats used in Linux systems—agree with me on this question, and the South African English locale uses the decimal point.

Unfortunately, the developers of Ubuntu Linux have come across a government communications style guide—a style guide widely ignored even within the governmentwhich specifies the use of the decimal comma. They have therefore included in Ubuntu a patch which changes the decimal separator for South African English to a comma.3 Reversing this change is one of the first things I do after setting up a new Ubuntu (or Linux Mint) install. Fortunately it is quite easy, and I give the instructions here to help those who suffer from the same annoyance.

## The simple way

Run the command

sudo update-locale LC_NUMERIC="en_GB.UTF-8"

The change won't take effect until you log out and back in again. This tells your system to use the British English settings for number formatting, and therefore to use the decimal point.

(If, for some reason, update-locale doesn't work for you, you can produce the same results by adding the line LC_NUMERIC="en_GB.UTF-8" to the file /etc/default/locale.)

### The problem

This method changes LC_NUMERIC which defines the format for ordinary numbers, but not LC_MONETARY, which defines the format for currency values. We could change LC_MONETARY to "en_GB.UTF-8", but then it would also change the currency symbol from "R" to "£".

## The complicated way

If we want to change the decimal separator for monetary values, without changing the currency symbol, we will have to edit the en_ZA locale definitions. You can download my patch file en_ZA-decimal-point.patch, and then apply it to the locale definitions by running the commands

sudo patch /usr/share/i18n/locales/en_ZA en_ZA-decimal-point.patch
sudo locale-gen

The changes will take effect immediately. You may have to repeat this process if the locales package is upgraded, because the upgrade will overwrite the locale definitions.

1. Per the "National Measuring Standards", Government Notice R. 1144, published on 5 July 1974 in Government Gazette No. 4326.
2. I am informed that in Afrikaans the decimal comma is more commonly used. I have no information about the other South African languages.
3. See Launchpad bug #887395 and ubuntu-en_ZA-decimal.patch.

## Western Cape number plate codes

Ever wondered where that (Western Cape registered) car is from? Wonder no more: (you can click on the map to see a bigger version)

(Based on this Wikipedia article.)

## Change in parties' share of the vote, 2009 to 2014

I've drawn some maps showing the percentage-point change between the 2009 and 2014 elections in the vote share of the major parties (or, in the case of COPE, formerly major parties). Because municipal boundaries have changed a bit, I had to recalculate the 2009 results for the 2014 boundaries, by assigning the voting districts from 2009 to wards from 2014. In the cases where a 2009 VD was spread across multiple 2014 municipalities, I assigned it according to the location of the voting station.

As always, click on the map to see the full-size version.

## African National Congress (ANC)

The ANC has increased its share substantially in some parts of the Western and Northern Cape; but it appears to have been at the cost of COPE or other smaller opposition parties, as the DA has also seen an increase in most of these areas (see the next map).

## Democratic Alliance (DA)

Some of the substantial increases seen by the DA are thanks to its absorption of the Independent Democrats.

## Economic Freedom Fighters (EFF)

Since the EFF is a new party the map just shows its share of the vote in 2014. The municipality where it won more than 20% is, unsurprisingly, Rustenburg, where it won 20.22% of the vote.

## Congress of the People (COPE)

Essentially, this map just shows COPE's share of the vote in 2009. In the places where it won more votes in 2009, it had more votes to lose in 2014.

## Inkatha Freedom Party (IFP)

The IFP lost badly in northern KZN, shedding votes to the breakaway NFP and, to a lesser extent, the ANC.

## National Freedom Party (NFP)

The NFP, which broke away from the IFP before the 2011 municipal elections, managed to win a substantial share of the vote in northern KZN.

## 2014 election results map

The detailed 2014 election results map promised in my last post is live! It has all the features of the 2009 map, plus you can see the results from both the national and the provincial ballots. As before, you can zoom right down to street level and see the results for individual voting districts.

The code, incidentally, is available on GitHub. The PostGIS database that backs it up can be downloaded here, but be warned it is 700MB. Available for separate download are:

## Another new election results site

As a long-weekend project I've put together this interactive map of the 2009 South African election results. It's a "slippy" (i.e. scrollable and zoomable) map and you can zoom right down to street level and see the results for individual voting districts. (Something you can't do with the News24 election map!)

Use the buttons in the top left to choose the level of detail—province, district municipality, local municipality, ward or voting district—though wards and voting districts aren't available until you zoom in a few levels. Click on an area on the map to see the results for that area. For example, here are the results from my voting district in Rosebank.

It's my plan to have a version with the 2014 election results up as soon as possible after the IEC releases the detailed results spreadsheets once the election is declared.

## New site - visualizing election results

I have a new site up which graphically displays information about the results of the 2009 South African elections. This project was an exercise in learning to use the D3.js framework. All the code and data is available in a github repository.

## Map of electrification from 1996 to 2011

New map I drew this weekend: it shows the spread of electrification in South Africa from 1996 to 2011, based on census data. The actual variable measured is "Main source of energy for lighting". As usual, click for the full-size version.

## Home language distribution map

I have added a layer showing the distribution of first/home languages from Census 2011 to my dot distribution map website. Next up: household income.