std.gis — Geospatial Spatial Engine & GeoAI Memory

OGC-compliant geospatial processing, Coordinate Reference System (CRS) transformations, spatial envelopes, hillshading, and TencentDB-inspired Spatial Agent Memory Store.

Module Namespace: import std.gis.geo | import std.gis.spatial | import std.gis.memory

Overview

The std.gis module provides exhaustive enterprise-grade spatial analysis capabilities, enabling developers to build robust desktop and enterprise GIS applications (comparable in feature scope to ArcGIS and QGIS). It includes geodesic distance calculations, Web Mercator CRS projections, ray-casting point-in-polygon containment, spatial grid indexing, elevation raster hillshading, and a location-indexed Spatial Agent Memory Store for GeoAI applications.

Sub-Modules & API Reference

1. std.gis.geo (Geodesic Core & Geometry)

Struct / FunctionDescription
struct PointRepresents a 3D geographic point with lat, lon, and elevation z.
struct WebMercatorPointRepresents projected planar coordinates x, y in EPSG:3857.
fn create_point(lat: f64, lon: f64) -> PointConstructs a new WGS84 point.
fn distance_km(p1: &Point, p2: &Point) -> f64Computes WGS84 geodesic distance using the Haversine formula.
fn to_web_mercator(pt: &Point) -> WebMercatorPointForward projects EPSG:4326 (WGS84) to EPSG:3857 (Web Mercator).
fn to_wgs84(merc: &WebMercatorPoint) -> PointInverse projects EPSG:3857 back to EPSG:4326 WGS84.
fn create_polygon(min_lat: f64, max_lat: f64, min_lon: f64, max_lon: f64) -> PolygonDefines a polygon bounding geometry.
fn point_in_polygon(poly: &Polygon, pt: &Point) -> boolRay-casting spatial intersection test checking if point falls inside polygon bounds.
fn calculate_hillshade(dz_dx: f64, dz_dy: f64) -> f64Calculates terrain surface hillshade illumination value (315° azimuth, 45° altitude).

2. std.gis.spatial (Spatial Indexing & Grid Acceleration)

Struct / FunctionDescription
struct SpatialGridIndexGrid index dividing bounding space into degree-based cell buckets.
fn get_cell_key(self: &SpatialGridIndex, lat: f64, lon: f64) -> StringGenerates spatial grid key string for fast O(1) cell lookup.
struct RasterElevationGridDigital Elevation Model (DEM) raster grid metadata container.

3. std.gis.memory (Spatial Agent Memory Store — GeoAI)

Struct / FunctionDescription
struct SpatialMemoryEntityMemory record binding agent_id, location Point, category, content, and timestamp.
struct SpatialAgentMemoryStoreContainer for agent memory logs with spatio-temporal query support.
fn insert_memory(store: &mut SpatialAgentMemoryStore, mem: SpatialMemoryEntity)Appends a spatial memory entity to the agent store.
fn recall_nearby_memories(store: &SpatialAgentMemoryStore, pos: &Point, radius_km: f64) -> Vec<SpatialMemoryEntity>Queries and returns all agent memories within specified radius in km.

Code Example

import std.io
import std.gis.geo
import std.gis.memory

fn main() {
    // 1. Calculate Geodesic Distance
    let sf = geo.create_point(37.7749, -122.4194)
    let la = geo.create_point(34.0522, -118.2437)
    let dist = geo.distance_km(&sf, &la)
    println("Geodesic Distance SF -> LA: " + dist.to_string() + " km")

    // 2. Forward CRS Projection
    let merc = geo.to_web_mercator(&sf)
    println("EPSG:3857 Mercator X: " + merc.x.to_string() + " Y: " + merc.y.to_string())

    // 3. GeoAI Agent Spatial Memory Recall
    let mut store = memory.SpatialAgentMemoryStore::new("DroneAgent_01".to_string())
    let mem = memory.SpatialMemoryEntity::new(
        "MEM-101".to_string(), "AgentAlpha".to_string(),
        37.7749, -122.4194, "ThermalScan".to_string(), "Heat signature detected".to_string(), 1700000000
    )
    store.insert_memory(mem)
}