Add a BaseCamp export rework script
This commit is contained in:
27
Python/process CSV with locations/functions/convertGPS.py
Normal file
27
Python/process CSV with locations/functions/convertGPS.py
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
def dms2dd(degrees, minutes, seconds, direction):
|
||||
dd = float(degrees) + float(minutes)/60 + float(seconds)/(60*60);
|
||||
|
||||
return dd;
|
||||
|
||||
def dd2dms(deg):
|
||||
d = int(deg)
|
||||
md = abs(deg - d) * 60
|
||||
m = int(md)
|
||||
sd = (md - m) * 60
|
||||
return [d, m, sd]
|
||||
|
||||
def parse_dms(dms):
|
||||
parts = re.split('[^\d\w]+', dms)
|
||||
lat = dms2dd(parts[0], parts[1], parts[2], parts[3])
|
||||
|
||||
if 'W' in dms or 'S' in dms:
|
||||
lat = lat * -1
|
||||
|
||||
return (lat)
|
||||
|
||||
|
||||
#dd = parse_dms("5°38'38.5 W")
|
||||
#print(dd)
|
@ -0,0 +1,35 @@
|
||||
import urllib.request
|
||||
import json
|
||||
|
||||
def getplace(lat, lon):
|
||||
lat = str(lat)
|
||||
lon = str(lon)
|
||||
url = "http://maps.googleapis.com/maps/api/geocode/json?"
|
||||
url += "latlng=%s,%s&sensor=false" % (lat, lon)
|
||||
|
||||
v = urllib.request.urlopen(url).read()
|
||||
j = json.loads(v)
|
||||
try:
|
||||
components = j['results'][0]['address_components']
|
||||
except:
|
||||
#print(lat + ' - ' + lon)
|
||||
#print('## Google Shizzle ##')
|
||||
return None
|
||||
else:
|
||||
country = town = street = None
|
||||
for c in components:
|
||||
if "route" in c['types']:
|
||||
street = c['long_name']
|
||||
if "country" in c['types']:
|
||||
country = c['long_name']
|
||||
if "locality" in c['types']:
|
||||
town = c['long_name']
|
||||
|
||||
return (str(country) + "," + str(town) + "," + str(street))
|
||||
|
||||
|
||||
# print(getplace(47.591737, 2.759478))
|
||||
# print(getplace(51.2, 0.1))
|
||||
# print(getplace(51.3, 0.1))
|
||||
|
||||
#print(getplace("60°04'52.3N", "14°09'13.7E"))
|
Reference in New Issue
Block a user