Saturday 3 October 2020

Code-Point Open Postcode Distance AWS Lambda

Redis supports calculating distances using longitude and latitude with GEODIST, but I wanted to use eastings and northings to calculate distance between postcodes.

This project uses the Code-Point Open dataset, loaded in to AWS ElastiCache (Redis) from an AWS S3 bucket, and provides an AWS Lambda REST API to query the distance between two given postcodes.

The Code-Point Open dataset is available as a free download from the Ordnance Survey Data Hub.


CSV Zip Download - Code-Point Open

Source Code

Code available in GitHub - codepoint-distance

Build and Run

Build using Maven:
mvn clean install

See the file on GitHub for AWS deployment instructions using the AWS Command Line Interface.

Example Usage

The REST API takes two postcodes as URL parameters and returns the distance in meters, along with each postcode's eastings and northings.

Using curl from the Linux command line:

curl -s | json_pp
   "distance" : 817.743235985477,
   "toCodePoint" : {
      "postcode" : "YO1 7HH",
      "eastings" : 460350,
      "northings" : 452085
   "fromCodePoint" : {
      "postcode" : "YO24 1AB",      
      "eastings" : 459610,
      "northings" : 451737