Project

posty

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Simple geolocation gem that stores the database locally
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Posty¶ ↑

Simple geolocation gem that stores the database locally.

Getting started¶ ↑

gem install posty

To download mySociety’s mirror of the Code-Point Open in WGS84 format, create a database from it, and store that inside the gem (you may not need the sudo):

sudo posty-init -g

This takes about 8 minutes for me, and leaves me with a database of approximately 157M.

If you don’t want the database being stored in your gem, run something like this instead:

posty-init -d database.sqlite3

Then, in Ruby:

require 'posty'
posty = Posty.new
postcode = posty.postcode('SE1 1EN') # space is optional, as is capitalisation

p postcode.postcode                       # => "SE11EN"
p [postcode.longitude, postcode.latitude] # => [-0.0946442029066659, 51.5013874361129]
p postcode.county                         # => "00"

If the database isn’t in the gem, you’ll need to tell it where to find it:

posty = Posty.new('database.sqlite3')

To make things even easier, there’s a class method too (which accepts the database as the second parameter):

Posty.postcode('SE1 1EN')

Notes¶ ↑

The table contains the following columns, extracted from the WGS84 edition of Code-Point Open:

  • postcode

  • quality

  • latitude

  • longitude

  • country

  • nhs_region

  • nhs_health_authority

  • county

  • district

  • ward

It does not contain eastings and northings.