Module geospatial

Module geospatial 

Source
Expand description

Geospatial functionality for working with geographic coordinates

This module provides basic geospatial operations including:

  • Coordinate system transformations
  • Great circle distance calculations (Haversine formula)
  • Bearing and azimuth calculations
  • Geodesic operations on the sphere

§Coordinate Systems

The module supports common geographic coordinate systems:

  • WGS84: World Geodetic System 1984 (GPS standard)
  • Geographic: Latitude/Longitude coordinates
  • UTM: Universal Transverse Mercator projections
  • Web Mercator: Spherical Mercator (EPSG:3857)

§Examples

use scirs2_spatial::geospatial::{haversine_distance, initial_bearing, destination_point};

// Calculate distance between two cities
let london = (51.5074, -0.1278);  // Latitude, Longitude
let paris = (48.8566, 2.3522);

let distance = haversine_distance(london, paris);
println!("Distance from London to Paris: {:.1} km", distance / 1000.0);

// Calculate bearing
let bearing = initial_bearing(london, paris);
println!("Initial bearing: {:.1}°", bearing.to_degrees());

// Find destination point
let destination = destination_point(london, 100000.0, bearing); // 100 km
println!("100km from London: ({:.4}, {:.4})", destination.0, destination.1);

Constants§

EARTH_ECCENTRICITY_SQ
Earth’s eccentricity squared (WGS84)
EARTH_EQUATORIAL_RADIUS_M
Earth’s equatorial radius in meters (WGS84)
EARTH_FLATTENING
Earth’s flattening (WGS84)
EARTH_POLAR_RADIUS_M
Earth’s polar radius in meters (WGS84)
EARTH_RADIUS_KM
Earth radius in kilometers
EARTH_RADIUS_M
Earth radius in meters (WGS84 mean radius)

Functions§

along_track_distance
Calculate the along-track distance (distance along a great circle path to the closest point)
cross_track_distance
Calculate the cross-track distance (distance from a point to a great circle path)
deg_to_rad
Convert degrees to radians
destination_point
Calculate the destination point given a starting point, distance, and bearing
final_bearing
Calculate the final bearing (back azimuth) when arriving at point2 from point1
geographic_to_utm
Convert geographic coordinates to UTM coordinates
geographic_to_web_mercator
Convert geographic coordinates to Web Mercator (EPSG:3857)
haversine_distance
Calculate the great circle distance between two points using the Haversine formula
initial_bearing
Calculate the initial bearing (forward azimuth) from point1 to point2
midpoint
Calculate the midpoint between two geographic points
normalize_angle
Normalize angle to [0, 2π) range
normalize_bearing
Normalize bearing to [0°, 360°) range
point_in_spherical_polygon
Check if a point is inside a spherical polygon using the winding number method
rad_to_deg
Convert radians to degrees
spherical_polygon_area
Calculate the area of a polygon on the sphere using spherical excess
vincenty_distance
Calculate the vincenty distance between two points (more accurate than Haversine)
web_mercator_to_geographic
Convert Web Mercator coordinates to geographic coordinates