{"id":9068,"library":"lat-lon-parser","title":"Latitude-Longitude String Parser","description":"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.","status":"active","version":"1.3.1","language":"en","source_language":"en","source_url":"https://github.com/NOAA-ORR-ERD/lat_lon_parser","tags":["geospatial","latitude","longitude","parser","coordinates","gis"],"install":[{"cmd":"pip install lat-lon-parser","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"note":"The primary function for parsing a latitude-longitude string.","symbol":"parse","correct":"from lat_lon_parser import parse"},{"note":"Converts degrees, minutes, seconds to decimal degrees.","symbol":"to_dec_deg","correct":"from lat_lon_parser import to_dec_deg"},{"note":"Converts numeric latitude/longitude components into a formatted string.","symbol":"to_str","correct":"from lat_lon_parser import to_str"}],"quickstart":{"code":"from lat_lon_parser import parse, to_str\n\n# Parse a latitude-longitude string\ncoord_str_dms = \"40° 26' 46\\\" N 79° 58' 56\\\" W\"\ndecimal_degrees = parse(coord_str_dms)\nprint(f\"Parsed '{coord_str_dms}' to: {decimal_degrees}°\")\n\n# Parse a decimal degrees string\ncoord_str_dec = \"23.43 N -45.21 W\"\ndecimal_degrees_2 = parse(coord_str_dec)\nprint(f\"Parsed '{coord_str_dec}' to: {decimal_degrees_2}°\")\n\n# Convert decimal degrees to a formatted string\nlat_val = 34.1234\nlon_val = -118.5678\nformatted_str = to_str(lat_val, lon_val)\nprint(f\"Converted {lat_val}, {lon_val} to: {formatted_str}\")","lang":"python","description":"Demonstrates parsing various latitude-longitude string formats into decimal degrees and converting numeric coordinates back into a human-readable string."},"warnings":[{"fix":"For unsupported formats, review the library's test cases on GitHub for similar patterns or consider contributing a patch/test case.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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).","message":"Common 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).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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'.","cause":"The input string does not match any of the expected latitude-longitude formats, often due to extraneous characters, incorrect separators, or unsupported notation.","error":"ValueError: Could not parse latitude/longitude string"},{"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.","cause":"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.","error":"Output coordinates are in a distant or incorrect location."}]}