Git Product home page Git Product logo

gridref's Introduction

GridRef

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)

CLI

Build

Run the following to build a standalone executable target/gridref using Leiningen:

$ lein bin

CLI Usage

Using the standalone executable:

$ gridref <gridref>

or

$ gridref [--figures=<n>] <coordinate>

For full usage and examples see the file resources/cli-usage.

Clojure Library

The gridref.core namespace defines the functions gridref2coord and coord2gridref that support converting between a grid reference and coordinate pair. There are also functions to parse input parse-gridref and parse-coord which can help with cleaning up input.

Usage

(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"

Installation

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:

[gridref "0.1.5"]

Todo

  • Input and output in WTK or GeoJSON?

References

License

Copyright © 2013 Matt Walker ([email protected], @_walkermatt on Twitter)

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.