pub struct OSGB { /* private fields */ }
Expand description
Type representing a valid British National Grid Reference. Can be instantiated either by parsing from a string or through a valid set of eastings and northings as coordinates.
Provides functionality to convert between strings and coordinates, as well as re-mapping to a new precision.
Implementations§
Source§impl OSGB
impl OSGB
Sourcepub fn new(
eastings: u32,
northings: u32,
precision: Precision,
) -> Result<Self, Error>
pub fn new( eastings: u32, northings: u32, precision: Precision, ) -> Result<Self, Error>
Creates a new grid reference from the given coordinates and precision.
§Errors
Returns an error if the given coordinates are out of bounds.
§Example
use gridish::{OSGB, Precision};
let gridref = OSGB::new(
389_200,
243_700,
Precision::_100M
).unwrap();
assert_eq!(gridref.to_string(), "SO892437".to_string());
Sourcepub fn recalculate(&self, precision: Precision) -> Self
pub fn recalculate(&self, precision: Precision) -> Self
Recalculates the grid reference to a new precision.
§Example
use gridish::{OSGB, Precision};
let gridref_100m: OSGB = "SO892437".parse().unwrap();
let gridref_10k = gridref_100m.recalculate(Precision::_10Km);
assert_eq!("SO84".to_string(), gridref_10k.to_string());
Sourcepub fn sw(&self) -> Point
pub fn sw(&self) -> Point
Returns the point at the osgb’s ‘South West’ corner - its origin.
§Example
use gridish::OSGB;
use geo_types::coord;
let gridref: OSGB = "SO892437".parse().unwrap();
assert_eq!(gridref.sw(), coord! {x: 389_200.0, y: 243_700.0 }.into());
Sourcepub fn nw(&self) -> Point
pub fn nw(&self) -> Point
Returns the point at the osgb’s ‘North West’ corner.
§Example
use gridish::OSGB;
use geo_types::coord;
let gridref: OSGB = "SO892437".parse().unwrap();
assert_eq!(gridref.nw(), coord! {x: 389_200.0, y: 243_800.0 }.into());
Sourcepub fn ne(&self) -> Point
pub fn ne(&self) -> Point
Returns the point at the osgb’s ‘North East’ corner.
§Example
use gridish::OSGB;
use geo_types::coord;
let gridref: OSGB = "SO892437".parse().unwrap();
assert_eq!(gridref.ne(), coord! {x: 389_300.0, y: 243_800.0 }.into());
Sourcepub fn se(&self) -> Point
pub fn se(&self) -> Point
Returns the point at the osgb’s ‘South East’ corner.
§Example
use gridish::OSGB;
use geo_types::coord;
let gridref: OSGB = "SO892437".parse().unwrap();
assert_eq!(gridref.se(), coord! {x: 389_300.0, y: 243_700.0 }.into());
Sourcepub fn centre(&self) -> Point
pub fn centre(&self) -> Point
Returns the point at the osgb’s centre.
§Example
use gridish::OSGB;
use geo_types::coord;
let gridref: OSGB = "SO892437".parse().unwrap();
assert_eq!(gridref.centre(), coord! {x: 389_250.0, y: 243_750.0 }.into());
Sourcepub fn perimeter(&self) -> Polygon
pub fn perimeter(&self) -> Polygon
Returns the osgb’s perimeter.
§Example
use gridish::OSGB;
use geo_types::{LineString, Point, Polygon};
let gridref: OSGB = "SO892437".parse().unwrap();
assert_eq!(
gridref.perimeter(),
Polygon::new(
LineString::from(
vec![
Point::new(389_200.0, 243_700.0),
Point::new(389_200.0, 243_800.0),
Point::new(389_300.0, 243_800.0),
Point::new(389_300.0, 243_700.0)
]
),
vec![]
)
);