Skip to main content

Location

Struct Location 

Source
pub struct Location {
    pub lat: f64,
    pub lon: f64,
    pub elevation: Option<f64>,
    pub uncertainty_meters: Option<f64>,
    pub name: Option<String>,
}
Expand description

A geographic location using WGS84 coordinates.

Locations are the fundamental spatial unit in spatial narratives. They support optional elevation and uncertainty for real-world data.

§Examples

use spatial_narrative::core::Location;

// Create a location (New York City)
let nyc = Location::new(40.7128, -74.0060);
assert!(nyc.is_valid());

// With elevation (Mount Everest)
let peak = Location::with_elevation(27.9881, 86.9250, 8848.86);

// Using the builder for more options
let approximate = Location::builder()
    .coordinates(40.7, -74.0)
    .uncertainty_meters(1000.0)
    .name("Approximate NYC")
    .build()
    .unwrap();

§Coordinate System

Locations use WGS84 (EPSG:4326):

  • Latitude: -90° to +90° (negative = South)
  • Longitude: -180° to +180° (negative = West)
  • Elevation: meters above sea level (optional)

Fields§

§lat: f64

Latitude in decimal degrees (-90 to 90).

§lon: f64

Longitude in decimal degrees (-180 to 180).

§elevation: Option<f64>

Elevation in meters above sea level.

§uncertainty_meters: Option<f64>

Uncertainty radius in meters.

§name: Option<String>

Human-readable place name.

Implementations§

Source§

impl Location

Source

pub fn new(lat: f64, lon: f64) -> Self

Creates a new location with the given latitude and longitude.

§Arguments
  • lat - Latitude in decimal degrees (-90 to 90)
  • lon - Longitude in decimal degrees (-180 to 180)
§Examples
use spatial_narrative::core::Location;

let loc = Location::new(51.5074, -0.1278); // London
Source

pub fn with_elevation(lat: f64, lon: f64, elevation: f64) -> Self

Creates a new location with elevation.

§Arguments
  • lat - Latitude in decimal degrees
  • lon - Longitude in decimal degrees
  • elevation - Elevation in meters above sea level
Source

pub fn builder() -> LocationBuilder

Creates a new builder for constructing a Location.

Source

pub fn is_valid(&self) -> bool

Checks if the coordinates are valid WGS84 values.

Returns true if latitude is between -90 and 90, and longitude is between -180 and 180.

Source

pub fn validate(&self) -> Result<()>

Validates the location, returning an error if invalid.

Source

pub fn as_tuple(&self) -> (f64, f64)

Returns the coordinates as a tuple (lat, lon).

Source

pub fn to_geo_point(&self) -> Point<f64>

Returns the coordinates as a geo-types Point.

Source

pub fn from_geo_point(point: Point<f64>) -> Self

Creates a Location from a geo-types Point.

Trait Implementations§

Source§

impl Clone for Location

Source§

fn clone(&self) -> Location

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Location

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Location

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Location

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<(f64, f64)> for Location

Source§

fn from((lat, lon): (f64, f64)) -> Self

Converts to this type from the input type.
Source§

impl From<Point> for Location

Source§

fn from(point: Point<f64>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Location

Source§

fn eq(&self, other: &Location) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Location

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Location

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,