Skip to main content
https://github.com/NOAA-ORR-ERD/lat_lon_parser/workflows/CI/badge.svg https://img.shields.io/pypi/v/lat-lon-parser.svg https://img.shields.io/pypi/pyversions/lat-lon-parser.svg https://img.shields.io/github/license/NOAA-ORR-ERD/lat_lon_parser

lat_lon_parser

Code for parsing lat-long coordinates in “various” formats, and for converting between lat-long formats (e.g. decimal degrees to degrees-minutes-seconds)

Note: perhaps it would be better to integrate this with a more full featured lib like:

https://pypi.python.org/pypi/LatLon23

But that one does not seem to support parsing unknown formats at this point – and it’s GPL, and perhaps a little more complex and structured than it needs to be.

Parsing Latitude and Longitude strings

Usage:

from lat_lon_parser import parse

In [12]: from lat_lon_parser import parse

In [13]: parse("45° 12.6' W")
Out[13]: -45.21

Formats supported:

Decimal degrees (easy):

23.43
-45.21

Decimal Degrees with quadrant:

23.43 N
45.21 W

Or with spelled out:

23.43 North
45.21 West

(note that all of the cardinal directions are not case-sensitive)

Degrees, decimal minutes: (now it starts getting tricky!):

23° 25.800'
-45° 12.600'

or:

23 25.800'
-45 12.600'

or:

23° 25.8' N
45° 12.6' West

Degrees, Minutes, Seconds: (really fun!!!):

 23° 25' 48.0"
-45° 12' 36.0"

or:

 23d 25' 48.0"
-45d 12' 36.0"

or:

23° 25' 48.0" North
45° 12' 36.0" S

or – lots of other combinations!

For a more complete list, see the tests

How it works:

This uses a pretty “stupid” algorithm – it assumes that all formats will be something like:

[-][space] degrees [separator] minutes [separator] seconds [separator] [N[orth]|S[outh|E[ast]|W[est]]

But that actually is pretty darn robust!

If you have other formats you want to be able to parse, please contribute tests! – And ideally a patch if the current code doesn’t work.

Conversion to Latitude Longitude Formats

Also included is code to convert to other formats used for latitude and longitude:

  • degrees

  • degrees minutes

  • degrees minutes seconds

Converting to numbers:

Functions for returning tuples of numbers:

>>> to_dec_deg(23, 12, 3)
23.200833333333332
>>> to_deg_min(34.1234)
(34.0, 7.404)
>>> to_deg_min_sec(34.1234)
(34.0, 7, 24.24)

Converting to strings:

Functions for converting to various string formats:

>>> to_str_dec_deg(23, 12, 3)
'23.200833°'
>>> to_str_deg_min(2.345)
"2° 20.700'"
>>> to_str_deg_min_sec(-23.1234)
'-23° 7\' 24.24"'

>>> to_str(23.45)
'23.450000°'
>>> to_str(23, 45)
"23° 45.000'"
>>> to_str(23, 45, 6.7)
'23° 45\' 6.70"'

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lat_lon_parser-1.2.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lat_lon_parser-1.2.0-py2.py3-none-any.whl (11.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file lat_lon_parser-1.2.0.tar.gz.

File metadata

  • Download URL: lat_lon_parser-1.2.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.6.0.post20210108 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for lat_lon_parser-1.2.0.tar.gz
Algorithm Hash digest
SHA256 cd43cfa833a82981ca3306af7aeb6fa40b3431b7391b82710a2443244cadbf81
MD5 32854228bb62187145401e2dfc0142db
BLAKE2b-256 030e4de73c130244b3cbc657881a4164d9ef1c266dc9dfa4b6254bd8463004fd

See more details on using hashes here.

File details

Details for the file lat_lon_parser-1.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: lat_lon_parser-1.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.6.0.post20210108 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for lat_lon_parser-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cf8cff15d241be854028d2ecdfdd139214685ef3a3546243a9ad14bab6ffc27d
MD5 fd458759e566958473d1c9e971ec7c53
BLAKE2b-256 591f0ad74561247e567a9800b0345b44f7f6bb5ce3c535a8965de81ce22ec468

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.1

2 files

1.3.0

2 files

This release

1.2.0 This release

2 files

1.1.3

2 files

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.0

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page