matthewproctor / australianpostcodes

A community sourced comprehensive database of Australian Post Codes with geolocation data.
255 stars 47 forks source link

Electorate data appears to be inaccurate #31

Open scottsidwell opened 2 years ago

scottsidwell commented 2 years ago

Hey Matt and team!

I've been working on reverse mapping postcodes -> electorates for a hobby site - and while attempting to generate "nearest electorates" for every postcode ran into wrong results that appear to be the result of assigning incorrect electorate data.

I wrote a script to check / regenerate this based off the geojson published by PMC https://github.com/pmcau/AustralianElectorates/blob/main/Data/Maps/2022/australia.geojson:

const fs = require('fs');
const turf = require('@turf/turf');
const geojson = JSON.parse(fs.readFileSync('australia.geojson'));
const postcodes = JSON.parse(fs.readFileSync('australian_postcodes.json'));

for (const postcode of postcodes) {
    const pnt = turf.point([postcode.long, postcode.lat]);
    const feature = geojson.features.find(feature => turf.booleanPointInPolygon(pnt, feature.geometry));
    if (feature && feature.properties) {
        if (postcode.electorate !== feature.properties.electorateName) {
            console.log(`UPDATE postcode SET electorate = '${feature.properties.electorateName}', elecoraterating = NULL WHERE id = ${postcode.id} AND electorate <> '${feature.properties.electorateName}'`);
        }
    } else {
        console.log(`-- DELETE FROM postcode WHERE id = ${postcode.id} AND electorate = '${postcode.electorate}'`)
    }
}

which found ~5,269 incorrect electorates, and couldn't resolve an electorate for 53 entries.

I'd be curious to understand how you populated the electorate data for each postcode.

Would raising PR with updated electorates be welcome? It seems there are some postcodes in the dataset that no longer / exist or are not recognised by the AEC. e.g. 0200 via https://electorate.aec.gov.au/ - I'm not sure how we can determine which of these entries are safe to remove / drop - or is the intention in keeping them for historical lookups?