add python script to convert gps degrees to decimal

This commit is contained in:
aaron
2024-03-12 12:07:24 +01:00
parent df83af6336
commit 9c947ce95a
3 changed files with 117 additions and 0 deletions

12
tools/Pipfile Normal file
View File

@@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
pyexcel_ods = "*"
[dev-packages]
[requires]
python_version = "3.12"

60
tools/Pipfile.lock generated Normal file
View File

@@ -0,0 +1,60 @@
{
"_meta": {
"hash": {
"sha256": "6bed16df85f1c3045363fc17092ea1e360f81a1d03ba104dde5d1b37c95fde58"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.12"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"defusedxml": {
"hashes": [
"sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69",
"sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==0.7.1"
},
"lml": {
"hashes": [
"sha256:57a085a29bb7991d70d41c6c3144c560a8e35b4c1030ffb36d85fa058773bcc5",
"sha256:ec06e850019942a485639c8c2a26bdb99eae24505bee7492b649df98a0bed101"
],
"version": "==0.1.0"
},
"odfpy": {
"hashes": [
"sha256:db766a6e59c5103212f3cc92ec8dd50a0f3a02790233ed0b52148b70d3c438ec",
"sha256:fc3b8d1bc098eba4a0fda865a76d9d1e577c4ceec771426bcb169a82c5e9dfe0"
],
"version": "==1.4.1"
},
"pyexcel-io": {
"hashes": [
"sha256:19ff1d599a8a6c0982e4181ef86aa50e1f8d231410fa7e0e204d62e37551c1d6",
"sha256:f6084bf1afa5fbf4c61cf7df44370fa513821af188b02e3e19b5efb66d8a969f"
],
"markers": "python_version >= '3.6'",
"version": "==0.6.6"
},
"pyexcel-ods": {
"hashes": [
"sha256:0a45acd47cf920c38b52d6005088dbdefa285dab379f24115d1d335ddb0ab7ed",
"sha256:f61b56515fd4ccd4687f0a112422f74ce8535247ad2da49db90038d7e3ed397c"
],
"index": "pypi",
"markers": "python_version >= '3.6'",
"version": "==0.6.0"
}
},
"develop": {}
}

45
tools/convert_gps.py Normal file
View File

@@ -0,0 +1,45 @@
import re
import json
import pyexcel_ods
def dms_to_decimal(dms_str):
pattern = re.compile(r'(\d+)°(\d+)\'([\d.]+)\"([NSEW])')
match = pattern.match(dms_str)
if match:
degrees = float(match.group(1))
minutes = float(match.group(2))
seconds = float(match.group(3))
direction = match.group(4)
decimal_degrees = round(degrees + (minutes / 60) + (seconds / 3600), 6)
if direction in ['S', 'W']:
decimal_degrees *= -1
return decimal_degrees
else:
raise ValueError("invalid coordinate format")
def split_coordinates(coord_str):
parts = coord_str.split(', ')
latitude = parts[0]
longitude = parts[1]
return latitude, longitude
def main():
# capture site_degree (int dd mm ss)
sites = pyexcel_ods.get_data("../ironwood_data_cleaned.ods", sheet_name="Sheet1", start_row=1, start_column=1, column_limit=1)
trees = pyexcel_ods.get_data("../ironwood_data_cleaned.ods", sheet_name="Sheet1", start_row=1, start_column=5, column_limit=5)
for cell in trees["Sheet1"]:
if cell:
latitude, longitude = split_coordinates(cell[0])
latitude_decimal = dms_to_decimal(latitude)
longitude_decimal = dms_to_decimal(longitude)
print(f"{latitude_decimal},{longitude_decimal}")
else:
print(" ")
if __name__ == "__main__":
main()