add more comments
This commit is contained in:
@@ -3,17 +3,24 @@ import json
|
||||
import pyexcel_ods
|
||||
|
||||
def dms_to_decimal(dms_str):
|
||||
"""
|
||||
Turn a degree/minute/second format to decimal
|
||||
"""
|
||||
# the pattern matches 3 groups degrees, minutes and seconds
|
||||
pattern = re.compile(r'(\d+)°(\d+)\'([\d.]+)\"([NSEW])')
|
||||
match = pattern.match(dms_str)
|
||||
|
||||
# check if there was a match
|
||||
if match:
|
||||
degrees = float(match.group(1))
|
||||
minutes = float(match.group(2))
|
||||
seconds = float(match.group(3))
|
||||
direction = match.group(4)
|
||||
|
||||
# round to 6 significant figures (google maps does this)
|
||||
decimal_degrees = round(degrees + (minutes / 60) + (seconds / 3600), 6)
|
||||
|
||||
# in decimal there are no cardinal diractions, only signed or unsigned
|
||||
if direction in ['S', 'W']:
|
||||
decimal_degrees *= -1
|
||||
|
||||
@@ -22,16 +29,22 @@ def dms_to_decimal(dms_str):
|
||||
raise ValueError("invalid coordinate format")
|
||||
|
||||
def split_coordinates(coord_str):
|
||||
"""
|
||||
Split a dms coordinate into latitude and longitude
|
||||
E.g: 33°56'35.02"S, 023°30'26.10"E
|
||||
"""
|
||||
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)
|
||||
# specific implementation: ironwood_site (dd mm ss)
|
||||
sites = pyexcel_ods.get_data("../data/ironwood_data_cleaned.ods", sheet_name="Sheet1", start_row=1, start_column=1, column_limit=1)
|
||||
# specific implementation: tree data (dd mm ss)
|
||||
trees = pyexcel_ods.get_data("../data/ironwood_data_cleaned.ods", sheet_name="Sheet1", start_row=1, start_column=5, column_limit=5)
|
||||
|
||||
# iterate over the retrieved data and convert everything
|
||||
for cell in trees["Sheet1"]:
|
||||
if cell:
|
||||
latitude, longitude = split_coordinates(cell[0])
|
||||
|
||||
Reference in New Issue
Block a user