Skip to content

Instantly share code, notes, and snippets.

@samuelleach
Created November 28, 2014 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelleach/7ba0057db327960a1c1c to your computer and use it in GitHub Desktop.
Save samuelleach/7ba0057db327960a1c1c to your computer and use it in GitHub Desktop.
Process Doogal UK postcode data into a postcode, lon, lat file
# Doogal downloads:
DOOGAL_SITE=http://www.doogal.co.uk/files/
DOOGAL_DATADIR=data_raw/doogal
all: $(DOOGAL_DATADIR)/postcodes_cut.csv
# PURPOSE: Create directory structure
setup:
mkdir -p data_raw data_intermediate data_deploy log
# 1 - PURPOSE: Download Doogal zipped postcode lookup file (56MB)
$(DOOGAL_DATADIR)/postcodes.zip:
mkdir -p $(dir $@)
wget $(DOOGAL_SITE)/$(notdir $@) -O $@.download && mv $@.download $@
touch $@
# 2 - PURPOSE: Unzip Doogal postcode lookup file
$(DOOGAL_DATADIR)/postcodes.csv: $(DOOGAL_DATADIR)/postcodes.zip
unzip -u $< -d $(dir $@)
touch $@
# 3 - PURPOSE: Convert Doogal file to utf8
$(DOOGAL_DATADIR)/postcodes_utf8.csv: $(DOOGAL_DATADIR)/postcodes.csv
iconv -c -t UTF-8 $< > $@ || true
# 4 - PURPOSE: Cut required columns from Doogal postcode file (68MB file)
$(DOOGAL_DATADIR)/postcodes_cut.csv: $(DOOGAL_DATADIR)/postcodes_utf8.csv
mkdir -p $(dir $@)
$(CSVKITROOT)csvcut -c Postcode,Latitude,Longitude $< > $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment