Project

dx-grid

0.0
No release in over 3 years
Low commit activity in last 3 years
Amateur radio Maidenhead grid locator conversions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.11
~> 5.0
~> 10.0
 Project Readme

DX::Grid

The DX::Grid module provides methods for converting between lat/long coordinate pairs and amateur radio Maidenhead grid locators. It can also validate the format of a grid string.

The supported grid formats are 4-character (e.g. FN22) and 6-character (e.g. FN32ab).

The range of grids is from AA00aa to RR99xx.

You can learn more about grid squares from the ARRL.

Installation

Add this line to your application's Gemfile:

gem 'dx-grid'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dx-grid

Usage

require 'dx/grid'

Decoding a Grid to a Coordinate

DX::Grid.decode('FN22') # => [42.5, -75.0]
DX::Grid.decode('FN22ab') # => [42.0625, -75.95833333333333]

Encoding a Coordinate to a Grid

DX::Grid.encode([42.481076, -75.037847]) # => 'FN22'
DX::Grid.encode([42.481076, -75.037847], :length => 4) # => 'FN22'
DX::Grid.encode([42.481076, -75.037847], :length => 6) # => 'FN22cd'

Validating a Grid

DX::Grid.valid?('FN22') # => true
DX::Grid.valid?('fn22') # => true
DX::Grid.valid?('AA00aa') # => true
DX::Grid.valid?('ab12xx') # => true
DX::Grid.valid?('MO00OO') # => true
DX::Grid.valid?('lo00ol') # => true

DX::Grid.valid?('FN') # => false
DX::Grid.valid?('st12') # => false
DX::Grid.valid?('fn22yz') # => false
DX::Grid.valid?('hello world') # => false
DX::Grid.valid?(nil) # => false
DX::Grid.valid?('') # => false
DX::Grid.valid?(5) # => false
DX::Grid.valid?(Math::PI) # => false

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/schrockwell/dx-grid.

License

The gem is available as open source under the terms of the MIT License.