Clojure CLI and library to convert an alpha numeric Ordnance Survey grid reference to easting / northing or easting / northing to a grid reference.
Valid input includes:
ST => [300000.0 100000.0] (The bottom right coordinate of the ST grid square) NN1665071250 => [216650.0 771250.0] (The Ben Nevis) SU387148 => [438700.0 114800.0] (The Ordnance Survey offices in Southampton) SU31NE => [435000.0 115000.0] (The 5 km square of the OS office) TQ336805 => [533600.0 180500.0] (The Tower of London) "[300000.0 100000.0]" => ST (The bottom right coordinate of the ST grid square) "216650.0 771250.0" => NN1665071250 (The Ben Nevis) "[438700 114800]" => SU387148 (The Ordnance Survey offices in Southampton) "533600 180500" => TQ3360080500 (The Tower of London)
Run the following to build a standalone executable
target/gridref using Leiningen:
$ lein bin
Using the standalone executable:
$ gridref <gridref>
$ gridref [--figures=<n>] <coordinate>
For full usage and examples see the file
gridref.core namespace defines the functions
coord2gridref that support converting between a grid reference and coordinate pair. There are also functions to parse input
parse-coord which can help with cleaning up input.
(use 'gridref.core) ; Parsing input (gridref.core/parse-gridref "su 387 148") => "SU387148" (gridref.core/parse-coord "216650.0 771250.0") => [216650.0 771250.0] ; Conversion (gridref.core/gridref2coord "SU387148") => [438700.0 114800.0] (gridref.core/coord2gridref [438700.0 114800.0] 6) => "SU387148"
gridref is available as a Maven artifact from Clojars. To use
gridref as a library in a Clojure project you can add this in your
project.clj with leiningen:
- Input and output in WTK or GeoJSON?
Copyright © 2013 Matt Walker (email@example.com, @_walkermatt on Twitter)
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.