Skip to main content

Crate locat

Crate locat 

Source
Expand description

locat

A blazing fast, zero-copy ISO 6709 geographic coordinate parser and writer in Rust.

github LoC Build codecov

docs.rs crates.io crates.io license

§Features

  • Zero-copy: CRS identifiers borrow directly from the input string
  • no_std compatible: works without the standard library
  • All ISO 6709 notation forms: decimal degrees, degrees+minutes, DMS
  • Altitude & CRS: optional altitude (meters) and coordinate reference system identifier
  • Round-trip: Display impls produce valid ISO 6709 output
  • DFA-powered lexer: logos-based tokenizer classifies components in a single pass

§Installation

[dependencies]
locat = "0.1"

§Quick Start

use locat::parse;

// Decimal degrees (New York City)
let coord = parse("+40.7128-074.0060/").unwrap();
let (lat, lon): (f64, f64) = coord.to_decimal_degrees();
assert!((lat - 40.7128).abs() < 1e-10);
assert!((lon - (-74.006)).abs() < 1e-10);

// Degrees, minutes, seconds
let coord = parse("+404243-0740002/").unwrap();

// With altitude and CRS (Mount Everest)
let coord = parse("+27.5916+086.5640+8848CRSepsg4326/").unwrap();
assert!(coord.altitude().is_some());
assert_eq!(coord.crs().unwrap().as_str(), "epsg4326");

// Round-trip
let input = "+40.7128-074.0060/";
let coord = parse(input).unwrap();
assert_eq!(coord.to_string(), input);

§Supported Formats

FormLatitudeLongitudeExample
Degrees±DD[.D+]±DDD[.D+]+40.7128-074.0060/
Deg+Min±DDMM[.M+]±DDDMM[.M+]+4042.77-07400.36/
DMS±DDMMSS[.S+]±DDDMMSS[.S+]+404243.0-0740002.0/

Optional trailing components: [±Altitude][CRS<id>]/

§Benchmarks

Measured on Apple Silicon with cargo bench (Criterion). All times are per-operation.

§Parse (single coordinate)

FormatTimeThroughput
Minimal (+00+000/)~18 ns424 MiB/s
DMS integer (+404243-0740002/)~22 ns704 MiB/s
Decimal degrees (+40.7128-074.0060/)~27 ns634 MiB/s
Deg+Min (+4042.7700-07400.3600/)~30 ns708 MiB/s
DMS decimal (+404243.123000-0740002.456000/)~34 ns840 MiB/s
With altitude (+27.5916+086.5640+8848/)~32 ns680 MiB/s
With altitude+CRS (+27.5916+086.5640+8848CRSepsg4326/)~37 ns884 MiB/s

§Round-trip (parse + Display)

FormatTime
DMS integer~184 ns
Minimal~180 ns
DMS decimal~339 ns
Decimal degrees~489 ns
Deg+Min~497 ns
With altitude~556 ns
With altitude+CRS~622 ns

§Conversion

to_decimal_degrees() completes in ~1 ns regardless of input format.

§Batch throughput

Parsing 1,000 mixed-format coordinates: ~48 µs (~430 MiB/s).

Run benchmarks yourself:

cargo bench
§License

locat is under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT for details.

Copyright (c) 2026 Al Liu.

Structs§

Altitude
Altitude in meters.
Coordinate
A parsed ISO 6709 geographic coordinate.
CrsId
CRS (Coordinate Reference System) identifier.
LatDMS
Degrees, minutes, and decimal seconds latitude: ±DDMMSS.SSS.
LatDeg
Decimal degrees latitude: ±DD.DDD (0.0–90.0).
LatDegMin
Degrees and decimal minutes latitude: ±DDMM.MMM.
LonDMS
Degrees, minutes, and decimal seconds longitude: ±DDDMMSS.SSS.
LonDeg
Decimal degrees longitude: ±DDD.DDD (0.0–180.0).
LonDegMin
Degrees and decimal minutes longitude: ±DDDMM.MMM.

Enums§

Component
Which coordinate component caused a range error.
Latitude
Latitude component of an ISO 6709 coordinate.
Longitude
Longitude component of an ISO 6709 coordinate.
ParseError
Errors that can occur when parsing an ISO 6709 coordinate string.
Sign
Sign of a coordinate component.

Functions§

parse
Parses an ISO 6709 coordinate string.