pub struct OSI { /* private fields */ }Expand description
Type representing a valid Irish 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 OSI
impl OSI
Sourcepub fn new(
eastings: u32,
northings: u32,
resolution: Resolution,
) -> Result<Self, OutOfBoundsError>
pub fn new( eastings: u32, northings: u32, resolution: Resolution, ) -> Result<Self, OutOfBoundsError>
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::{OSI, Resolution};
let gridref = OSI::new(
389_200,
243_700,
Resolution::_100m
).unwrap();
assert_eq!(gridref.to_string(), "O892437".to_string());pub fn eastings(&self) -> u32
pub fn northings(&self) -> u32
pub fn resolution(&self) -> Resolution
Sourcepub fn recalculate(&self, resolution: Resolution) -> Self
pub fn recalculate(&self, resolution: Resolution) -> Self
Recalculates the grid reference to a new resolution.
§Example
use gridish::{OSI, Resolution};
let gridref_100m: OSI = "O892437".parse().unwrap();
let gridref_10k = gridref_100m.recalculate(Resolution::_10km);
assert_eq!("O84".to_string(), gridref_10k.to_string());Sourcepub fn south_west(&self) -> Point
pub fn south_west(&self) -> Point
Returns the point at the Grid Reference’s South West corner - its origin.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.south_west(), coord! {x: 389_200.0, y: 243_700.0 }.into());Sourcepub fn north_west(&self) -> Point
pub fn north_west(&self) -> Point
Returns the point at the Grid Reference’s North West corner.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.north_west(), coord! {x: 389_200.0, y: 243_800.0 }.into());Sourcepub fn north_east(&self) -> Point
pub fn north_east(&self) -> Point
Returns the point at the Grid Reference’s North East corner.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.north_east(), coord! {x: 389_300.0, y: 243_800.0 }.into());Sourcepub fn south_east(&self) -> Point
pub fn south_east(&self) -> Point
Returns the point at the Grid Reference’s South East corner.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.south_east(), 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 Grid Reference’s centre.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".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 Grid Reference’s perimeter.
§Example
use gridish::OSI;
use geo_types::{LineString, Point, Polygon};
let gridref: OSI = "O892437".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![]
)
);