-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgridtogps.py
27 lines (22 loc) · 941 Bytes
/
gridtogps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
from bs4 import BeautifulSoup
import csv
def gridtogps (gridref):
r = requests.get("http://batlab.ucd.ie/gridref/?reftype=NATGRID&refs=" + gridref)
xml = r.text
soup = BeautifulSoup(xml, 'xml')
pm = soup.gridref.placemark
lat = pm.latitude.text
lon = pm.longitude.text
return {
'Latitude': lat,
'Longitude': lon
}
with open('./areas.csv') as f:
d = csv.DictReader(f)
for row in d:
if (row['OS Map Coordinates']):
ll = gridtogps(row['OS Map Coordinates'].replace(' ', ''))
print ','.join([row['Area Name'],row['Number of Problems'],row['Type of Rock'],row['Aspect'],row['County'],row['OS Map Coordinates'],ll['Latitude'],ll['Longitude']])
else:
print ','.join([row['Area Name'],row['Number of Problems'],row['Type of Rock'],row['Aspect'],row['County'],row['OS Map Coordinates'],row['Latitude'],row['Longitude']])