CoordConversions is a robust TypeScript library designed for seamless conversions between Decimal Degrees, Degrees-Minutes, and Degrees-Minutes-Seconds formats. With features like smart parsing, comprehensive validation, and zero dependencies, it ensures reliable and accurate geographic coordinate handling for developers in any project.
CoordConversions is a powerful TypeScript library designed to facilitate seamless conversions among various geographic coordinate formats: Decimal Degrees (DD), Degrees-Minutes (DM), and Degrees-Minutes-Seconds (DMS). This tool enhances geographic data handling by providing comprehensive features for parsing, validating, and formatting coordinates along with hemisphere indicators.
import {
// For individual coordinates
parseToDD, // Parse values to Decimal Degrees (DD)
ddToDM, // Convert DD to Degrees-Minutes (DM)
ddToDMS, // Convert DD to Degrees-Minutes-Seconds (DMS)
dmToDD, // Convert DM to DD
dmsToDD, // Convert DMS to DD
formatDD, // Format DD for display
formatDM, // Format DM for display
formatDMS, // Format DMS for display
// For coordinate pairs
parsePairToDD, // Parse a pair of values to Decimal Degrees (DD)
ddPairToDM, // Convert a pair of DD values to Degrees-Minutes (DM)
ddPairToDMS, // Convert a pair of DD values to Degrees-Minutes-Seconds (DMS)
dmPairToDD, // Convert a pair of DM values to DD
dmsPairToDD, // Convert a pair of DMS values to DD
formatDDPair, // Format a pair of DD values for display
formatDMPair, // Format a pair of DM values for display
formatDMSPair, // Format a pair of DMS values for display
// Coordinate type for type safety
CoordinateType,
} from "coordconversion";
To convert coordinates using CoordConversions, utilize the following function examples:
Use the following parse -> convert -> format flow:
Start with a coordinate parsing function:
const dd = parseToDD("45° 7' 22.8\" N", CoordinateType.LAT);
Convert the parsing result to another format:
const dm = ddToDM(dd);
Format the conversion result into a human-readable string:
const formatted = formatDM(dm);
console.log(formatted); // e.g. "45° 7.38' N"
Perform operations on pairs of coordinates in an efficient manner:
const [lat, lon] = parsePairToDD("48.8544° N", "123.5005° W");
const [latDM, lonDM] = ddPairToDM(lat, lon);
const [latStr, lonStr] = formatDMPair(latDM, lonDM);
console.log(latStr, lonStr); // e.g. "48° 51.26' N", "123° 30.03' W"
The library allows for custom precision settings, options for clamping values during conversions, and batch processing of coordinates to enhance usability in diverse applications. Comprehensive error handling and validation mechanisms ensure robust performance while converting and formatting geographic coordinates.
This library is ideal for developers working on projects involving geographical data processing, mapping, and location-based services.
No comments yet.
Sign in to be the first to comment.