osgb

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: BSD-2-Clause Imports: 9 Imported by: 0

README

go-osgb

GoDoc

A Go library for performing accurate conversions between OS National Grid and GPS coordinates. (More technically, coordinate transformations between the OSGB36/ODN and ETRS89 geodetic datums)

Why would I need this?

Geodetic transformations that assume perfect geometry lose precision on imperfect geoids (e.g. The Helmert transformation for ETRS89 to OSGB36/ODN has errors up to 5m). This library implements the definitive transformation developed by Ordnance Survey for converting between National Grid and GPS coordinates, resulting in very accurate conversions (average < 0.1m error).

Features

  • Supports OSTN02/OSGM02 and OSTN15/OSGM15 transformations
  • All transformation parameters are included in the library. No need to load additional files!
  • Fully tested against the conversion samples provided in the Ordnance Survey developer resources

Installation

go get github.com/mjjbell/go-osgb

Usage

Converting from National Grid to GPS

    import (
        "log"

        osgb "github.com/mjjbell/go-osgb"
    )

    func main() {
        trans, err := osgb.NewOSTN15Transformer()
        if err != nil {
            log.Fatal(err)
        }
        easting := 400001.4
        northing := 305001.4
        height := 5.0
        nationalGridCoord := osgb.NewOSGB36Coord(easting, northing, height)
        gpsCoord, err := trans.FromNationalGrid(nationalGridCoord)
        if err != nil {
            log.Fatal(err)
        }
        log.Printf("%#v\n", gpsCoord)
        // &osgb.ETRS89Coordinate{Lon:-2.001408181413446, Lat:52.64276984554203, Height:55.34172940576156}
    }

Converting from GPS to National Grid

    import (
        "log"

        osgb "github.com/mjjbell/go-osgb"
    )

    func main() {
        trans, err := osgb.NewOSTN15Transformer()
        if err != nil {
            log.Fatal(err)
        }

        lon := -0.1262
        lat := 51.5080
        height := 10.5
        gpsCoord := osgb.NewETRS89Coord(lon, lat, height)
        nationalGridCoord, err := trans.ToNationalGrid(gpsCoord)
        if err != nil {
            log.Fatal(err)
        }
        log.Printf("%#v\n", nationalGridCoord)
        // &osgb.OSGB36Coordinate{Easting:530136.3274244666, Northing:180449.45428526515, Height:-35.04663654446814}
    }

Coordinate Units

National Grid eastings, northings and ODN height are all in metres. GPS longitude and latitude are in decimal degrees. Height is in metres.

Transformation Limits

The transformation is only accurately defined for onshore positions of British Islands.

When using OSTNO2, transformations attempted for positions greater than 10km offshore will return an ErrPointOutsidePolygon error.

OSTN15 will not return an error for offshore transformations, but precision is severely degraded, so usage is not recommended. However, straying outside the extents of the 700x1250km transformation grid completely will lead to an ErrPointOutsideTransformation error.

I want to know more about the transformation

The full details can be found in the developers section of the Ordnance Survey website.

Roadmap

  • Expose geoid regions for ODN heights
  • Support transformations on the Irish mainland

License

This library is released under the BSD license, as are the transformation models provided by Ordnance Survey. Full details can be found in the LICENSE file.

Documentation

Index

Constants

View Source
const (
	Region_OUTSIDE_BOUNDARY       geoidRegion = 0  // 02
	Region_UK_MAINLAND            geoidRegion = 1  // 02,15
	Region_SCILLY_ISLES           geoidRegion = 2  // 02,15
	Region_ISLE_OF_MAN            geoidRegion = 3  // 02,15
	Region_OUTER_HEBRIDES         geoidRegion = 4  // 02,15
	Region_ST_KILDA               geoidRegion = 5  // 02
	Region_SHETLAND_ISLES         geoidRegion = 6  // 02,15
	Region_ORKNEY_ISLES           geoidRegion = 7  // 02,15
	Region_FAIR_ISLE              geoidRegion = 8  // 02
	Region_FLANNAN_ISLES          geoidRegion = 9  // 02
	Region_NORTH_RONA             geoidRegion = 10 // 02
	Region_SULE_SKERRY            geoidRegion = 11 // 02
	Region_FOULA                  geoidRegion = 12 // 02
	Region_REPUBLIC_OF_IRELAND    geoidRegion = 13 // 02
	Region_NORTHERN_IRELAND       geoidRegion = 14 // 02
	Region_OFFSHORE               geoidRegion = 15 // 15
	Region_OUTSIDE_TRANSFORMATION geoidRegion = 16 // 15
)

Variables

View Source
var (
	// ErrPointOutsidePolygon indicates the position is too far offshore to be transformed.
	ErrPointOutsidePolygon = errors.New("point outside polygon")
	// ErrPointOutsideTransformation indicates the position is completely outside the grid transformation extent
	ErrPointOutsideTransformation = errors.New("point outside transformation limits")
)

Functions

This section is empty.

Types

type CoordinateTransformer

type CoordinateTransformer interface {
	// ToNationalGrid coverts a coordinate position from ETRS89 to OSGB36/ODN
	ToNationalGrid(c *ETRS89Coordinate) (*OSGB36Coordinate, error)
	// FromNationalGrid coverts a coordinate position from OSGB36/ODN to ETRS89
	FromNationalGrid(c *OSGB36Coordinate) (*ETRS89Coordinate, error)
}

CoordinateTransformer is used to convert between OSGB36/ODN and ETRS89 geodetic datums

func NewOSTN02Transformer

func NewOSTN02Transformer() (CoordinateTransformer, error)

NewOSTN02Transformer returns a transformer that uses OSTN02/OSGM02

func NewOSTN15Transformer

func NewOSTN15Transformer() (CoordinateTransformer, error)

NewOSTN15Transformer returns a transformer that uses OSTN15/OSGM15

type ETRS89Coordinate

type ETRS89Coordinate struct {
	// Longitude in decimal degrees
	Lon float64
	// Latitude in decimal degrees
	Lat float64
	// Height in metres
	Height float64
}

ETRS89Coordinate represents a coordinate position in the ETRS89 geodetic datum. Whilst not being identical this can be treated as a GPS coordinate.

func NewETRS89Coord

func NewETRS89Coord(lon, lat, height float64) *ETRS89Coordinate

NewETRS89Coord creates a new coordinate position in the ETRS89 geodetic datum.

type OSGB36Coordinate

type OSGB36Coordinate struct {
	// Easting in metres
	Easting float64
	// Northing in metres
	Northing float64
	// Height in metres
	Height float64
}

OSGB36Coordinate represents a coordinate position in the OSGB36/ODN geodetic datum.

func NewOSGB36Coord

func NewOSGB36Coord(easting, northing, height float64) *OSGB36Coordinate

NewOSGB36Coord creates a new coordinate position in the OSGB36/ODN geodetic datum.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL