.. image:: https://github.com/NOAA-ORR-ERD/lat_lon_parser/workflows/CI/badge.svg
:target: https://github.com/NOAA-ORR-ERD/lat_lon_parser/actions?query=workflow%3ACI
.. image:: https://img.shields.io/pypi/v/lat-lon-parser.svg
:target: https://pypi.org/project/lat-lon-parser/
.. image:: https://img.shields.io/pypi/pyversions/lat-lon-parser.svg
:target: https://pypi.org/project/lat-lon-parser/
.. image:: https://img.shields.io/github/license/NOAA-ORR-ERD/lat_lon_parser
:target: https://github.com/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
.. code-block::
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"'
Usage with Pandas
-----------------
Question from a user:
How to apply this lat_lon_parser on pandas dataframe specific column?
Turns out it's straightforward -- just pass the `parse` function to apply::
In [20]: df = pandas.DataFrame({'coords':["12d13'N","32 5 14", "30.123W"]})
In [21]: df
Out[21]:
coords
0 12d13'N
1 32 5 14
2 30.123W
In [22]: df['coords'] = df['coords'].apply(parse)
In [23]: df
Out[23]:
coords
0 12.216667
1 32.087222
2 -30.123000
Raw data
{
"_id": null,
"home_page": null,
"name": "lat-lon-parser",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "latitude, longitude, coordinates",
"author": null,
"author_email": "\"Christopher H. Barker\" <Chris.Barker@noaa.gov>",
"download_url": "https://files.pythonhosted.org/packages/00/58/879bcefdcec8ea62501270ac4475e75f72b54a32adb3a769c5ba5b10f535/lat_lon_parser-1.3.1.tar.gz",
"platform": null,
"description": ".. image:: https://github.com/NOAA-ORR-ERD/lat_lon_parser/workflows/CI/badge.svg\n :target: https://github.com/NOAA-ORR-ERD/lat_lon_parser/actions?query=workflow%3ACI\n\n.. image:: https://img.shields.io/pypi/v/lat-lon-parser.svg\n :target: https://pypi.org/project/lat-lon-parser/\n\n.. image:: https://img.shields.io/pypi/pyversions/lat-lon-parser.svg\n :target: https://pypi.org/project/lat-lon-parser/\n\n.. image:: https://img.shields.io/github/license/NOAA-ORR-ERD/lat_lon_parser\n :target: https://github.com/NOAA-ORR-ERD/lat_lon_parser/\n\n\n##############\nlat_lon_parser\n##############\n\nCode for parsing lat-long coordinates in \"various\" formats, and for converting between lat-long formats (e.g. decimal degrees to degrees-minutes-seconds)\n\nNote: perhaps it would be better to integrate this with a more full featured lib like:\n\nhttps://pypi.python.org/pypi/LatLon23\n\nBut 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.\n\nParsing Latitude and Longitude strings\n=======================================\n\nUsage:\n------\n\nfrom lat_lon_parser import parse\n\n.. code-block::\n\n In [12]: from lat_lon_parser import parse\n\n In [13]: parse(\"45\u00b0 12.6' W\")\n Out[13]: -45.21\n\n\nFormats supported:\n------------------\n\nDecimal degrees (easy)::\n\n 23.43\n -45.21\n\nDecimal Degrees with quadrant::\n\n 23.43 N\n 45.21 W\n\nOr with spelled out::\n\n 23.43 North\n 45.21 West\n\n(note that all of the cardinal directions are not case-sensitive)\n\nDegrees, decimal minutes: (now it starts getting tricky!)::\n\n 23\u00b0 25.800'\n -45\u00b0 12.600'\n\nor::\n\n 23 25.800'\n -45 12.600'\n\nor::\n\n 23\u00b0 25.8' N\n 45\u00b0 12.6' West\n\nDegrees, Minutes, Seconds: (really fun!!!)::\n\n 23\u00b0 25' 48.0\"\n -45\u00b0 12' 36.0\"\n\nor::\n\n 23d 25' 48.0\"\n -45d 12' 36.0\"\n\nor::\n\n 23\u00b0 25' 48.0\" North\n 45\u00b0 12' 36.0\" S\n\nor -- lots of other combinations!\n\nFor a more complete list, see the tests\n\nHow it works:\n-------------\n\nThis uses a pretty \"stupid\" algorithm -- it assumes that all formats will be something like:\n\n[-][space] degrees [separator] minutes [separator] seconds [separator] [N[orth]|S[outh|E[ast]|W[est]]\n\nBut that actually is pretty darn robust!\n\nIf 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.\n\n\nConversion to Latitude Longitude Formats\n========================================\n\nAlso included is code to convert to other formats used for latitude and longitude:\n\n- degrees\n- degrees minutes\n- degrees minutes seconds\n\nConverting to numbers:\n----------------------\n\nFunctions for returning tuples of numbers::\n\n >>> to_dec_deg(23, 12, 3)\n 23.200833333333332\n >>> to_deg_min(34.1234)\n (34.0, 7.404)\n >>> to_deg_min_sec(34.1234)\n (34.0, 7, 24.24)\n\n\nConverting to strings:\n----------------------\n\nFunctions for converting to various string formats::\n\n >>> to_str_dec_deg(23, 12, 3)\n '23.200833\u00b0'\n >>> to_str_deg_min(2.345)\n \"2\u00b0 20.700'\"\n >>> to_str_deg_min_sec(-23.1234)\n '-23\u00b0 7\\' 24.24\"'\n\n >>> to_str(23.45)\n '23.450000\u00b0'\n >>> to_str(23, 45)\n \"23\u00b0 45.000'\"\n >>> to_str(23, 45, 6.7)\n '23\u00b0 45\\' 6.70\"'\n\n\nUsage with Pandas\n-----------------\n\nQuestion from a user:\n\nHow to apply this lat_lon_parser on pandas dataframe specific column?\n\nTurns out it's straightforward -- just pass the `parse` function to apply::\n\n\n In [20]: df = pandas.DataFrame({'coords':[\"12d13'N\",\"32 5 14\", \"30.123W\"]})\n\n In [21]: df\n Out[21]:\n coords\n 0 12d13'N\n 1 32 5 14\n 2 30.123W\n\n In [22]: df['coords'] = df['coords'].apply(parse)\n\n In [23]: df\n Out[23]:\n coords\n 0 12.216667\n 1 32.087222\n 2 -30.123000\n\n\n\n\n",
"bugtrack_url": null,
"license": "CC0 1.0 Universal",
"summary": "Simple parser for latitude-longitude strings",
"version": "1.3.1",
"project_urls": null,
"split_keywords": [
"latitude",
" longitude",
" coordinates"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f61a4fda4c2dd7f84814647ce2124edc24dd2c313f4ac0aad786064d5ab9d82",
"md5": "9e7f1e24112de13d67c412a392f0dd0b",
"sha256": "e2abfff8a81de4b4db2c11a02867c5cd8b057a978e7b03c178abdeaa627e8ba8"
},
"downloads": -1,
"filename": "lat_lon_parser-1.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9e7f1e24112de13d67c412a392f0dd0b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 11269,
"upload_time": "2024-11-09T00:06:20",
"upload_time_iso_8601": "2024-11-09T00:06:20.579292Z",
"url": "https://files.pythonhosted.org/packages/4f/61/a4fda4c2dd7f84814647ce2124edc24dd2c313f4ac0aad786064d5ab9d82/lat_lon_parser-1.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0058879bcefdcec8ea62501270ac4475e75f72b54a32adb3a769c5ba5b10f535",
"md5": "7554ec46472f77fe0fd8726bdcfe7b67",
"sha256": "62b8191e72150a7bf5d55fe6a8dddf3e20dd4937a995130f74832cd7ede39e91"
},
"downloads": -1,
"filename": "lat_lon_parser-1.3.1.tar.gz",
"has_sig": false,
"md5_digest": "7554ec46472f77fe0fd8726bdcfe7b67",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 14299,
"upload_time": "2024-11-13T19:13:14",
"upload_time_iso_8601": "2024-11-13T19:13:14.879736Z",
"url": "https://files.pythonhosted.org/packages/00/58/879bcefdcec8ea62501270ac4475e75f72b54a32adb3a769c5ba5b10f535/lat_lon_parser-1.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-13 19:13:14",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "lat-lon-parser"
}