parse-dms
Parse a coordinate string into decimal latitude/longitude.
parse-dms turns a human-written geographic coordinate — in degrees/minutes/seconds or
decimal degrees, with optional hemisphere letters — into decimal degrees:
use ;
let c = parse_dms.unwrap;
assert_eq!;
A faithful Rust port of the parse-dms npm
package.
- Accepts varied separators:
°º:dfor degrees,'’‘′:for minutes,"″''for seconds - Infers latitude/longitude from hemisphere letters (
N/S/E/W), or — for two hemisphere-less coordinates — from their order (first = lat, second = lon) - Differential-tested against the reference
parse-dmsimplementation
Install
[]
= "0.1"
Usage
use ;
// DMS with hemispheres
assert_eq!;
// Decimal pair, order-inferred
assert_eq!;
// Single coordinate with a hemisphere → only that axis is set
assert_eq!;
// A bare value with no hemisphere → a single decimal number
assert_eq!;
// Out-of-range and unparseable inputs error
assert!;
assert!;
Return value
parse_dms returns a [Dms]:
Dms::Decimal(f64)— a single coordinate that had no hemisphere letter.Dms::Coordinates { lat, lon }— otherwise; each field isNonewhen the input didn't provide that component.
Components are validated: degrees 0..=180, minutes and seconds 0..=60.
Compatibility note
This is a faithful port, including the reference's quirks — for example a leading
hemisphere letter triggers a one-character overlap when scanning for a second coordinate
(parse_dms("n51") yields { lat: 51, lon: 1 }, matching the npm package). Lowercase
hemisphere letters are, as in the reference, not treated as hemispheres.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.