Registry / data / lat-lon-parser

lat-lon-parser

JSON →
library1.3.1pypypi✓ verified 85d ago

lat-lon-parser is a Python library designed for robustly parsing and converting latitude and longitude strings across various formats, including decimal degrees, degrees decimal minutes, and degrees minutes seconds. It provides functionality to parse coordinate strings into numerical values and to format numerical coordinates back into different string representations. The library's current version is 1.3.1, with the latest update on November 13, 2024, indicating active maintenance.

pip install lat-lon-parser
INSTALL
IMPORT
SIG · LAT-LON-PARSER
L
lat-lon-parser
datapythonv1.3.1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
from lat_lon_parser import parse
The primary function for parsing a latitude-longitude string.
to_dec_deg
from lat_lon_parser import to_dec_deg
Converts degrees, minutes, seconds to decimal degrees.
to_str
from lat_lon_parser import to_str
Converts numeric latitude/longitude components into a formatted string.

Demonstrates parsing various latitude-longitude string formats into decimal degrees and converting numeric coordinates back into a human-readable string.

from lat_lon_parser import parse, to_str # Parse a latitude-longitude string coord_str_dms = "40° 26' 46\" N 79° 58' 56\" W" decimal_degrees = parse(coord_str_dms) print(f"Parsed '{coord_str_dms}' to: {decimal_degrees}°") # Parse a decimal degrees string coord_str_dec = "23.43 N -45.21 W" decimal_degrees_2 = parse(coord_str_dec) print(f"Parsed '{coord_str_dec}' to: {decimal_degrees_2}°") # Convert decimal degrees to a formatted string lat_val = 34.1234 lon_val = -118.5678 formatted_str = to_str(lat_val, lon_val) print(f"Converted {lat_val}, {lon_val} to: {formatted_str}")
Debug
Known issues
gotchaThe parser uses a flexible, 'stupid' algorithm that generally works but might not cover all possible obscure formats. It's designed to accept ambiguous inputs where possible.
fix
For unsupported formats, review the library's test cases on GitHub for similar patterns or consider contributing a patch/test case.
affects: All versions
gotchaCommon parsing errors stem from extra text, incorrect/missing symbols (e.g., degree signs, hemisphere letters), values outside valid ranges (latitude -90 to +90, longitude -180 to +180), or transposed latitude and longitude (e.g., longitude given where latitude is expected).
fix
Ensure input strings contain only the coordinate, use correct symbols, verify values are within geographic ranges, and confirm the order of latitude and longitude (typically latitude first).
affects: All versions
Errors
Common errors & fixes
ValueError: Could not parse latitude/longitude string
The input string does not match any of the expected latitude-longitude formats, often due to extraneous characters, incorrect separators, or unsupported notation.
fix
Simplify the input string to contain only the coordinate values and hemisphere indicators. Remove any descriptive text, labels, or unrecognised symbols. For example, change 'Lat: 45.123, Lon: -123.456' to '45.123, -123.456'.
Output coordinates are in a distant or incorrect location.
Latitude and longitude values have been accidentally swapped or transposed during input. For example, if parsing a string where longitude is provided first, but the parser expects latitude first.
fix
Double-check the order of the parsed coordinates. Latitudes range from -90 to +90, while longitudes range from -180 to +180. If a value greater than 90 appears in the latitude position, it's likely a transposition. Swap the order of the input values or adjust how they are passed to ensure latitude corresponds to latitude and longitude to longitude.
Upgrade
Version history
1.3.1latest on PyPI · released Nov 9, 2024
Audit
Dependencies
pythonrequiredRequires Python 3.9 or newer.
Agent activity
4 hits · last 30 days
node
4
Resources
lat-lon-parser — pip install lat-lon-parser · libregistry