Add GPX generation
This commit is contained in:
parent
3a0a59c76f
commit
0c69ba5d9e
5
.gitignore
vendored
5
.gitignore
vendored
@ -158,3 +158,8 @@ cython_debug/
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
.idea/
|
||||
|
||||
# Project specific files
|
||||
data.json
|
||||
*.osm
|
||||
*.gpx
|
||||
|
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Megalith OSM
|
||||
|
||||
Retrieve data for English megalith sites and convert to an OsmAnd-compatible format
|
@ -29,6 +29,8 @@ def get_megalithic_data(country=1):
|
||||
'lat': row['lat'],
|
||||
'lng': row['lng'],
|
||||
'name': row['Name'],
|
||||
'type': row['Type'],
|
||||
'url': 'https://megalithic.co.uk/article.php?sid={}'.format(row['SID']),
|
||||
})
|
||||
|
||||
return data
|
||||
@ -52,11 +54,16 @@ def get_stone_circles_data():
|
||||
data.append({
|
||||
'lat': item[0],
|
||||
'lng': item[1],
|
||||
'name': re.match(r'.+<a .+>(.+)</a>', item[2]).groups()[0],
|
||||
'name': re.sub(r'<.+?>', '', re.match(r'<b>(.+)</b>', item[2]).groups()[0]),
|
||||
'type': re.sub(r'.+>', '', item[2].replace('<br>', ' ')),
|
||||
'url': 'http://www.stone-circles.org.uk/stone/{}'.format(re.search(r'href=([a-zA-Z.]+)', item[2]).groups()[0]),
|
||||
})
|
||||
|
||||
return data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
all_data = get_megalithic_data() + get_stone_circles_data()
|
||||
all_data = get_stone_circles_data() # + get_megalithic_data()
|
||||
|
||||
with open('data.json', 'w') as f:
|
||||
json.dump(all_data, f)
|
||||
|
30
to_gpx.py
Normal file
30
to_gpx.py
Normal file
@ -0,0 +1,30 @@
|
||||
import json
|
||||
from html import escape
|
||||
|
||||
with open('data.json') as data_file:
|
||||
data = json.load(data_file)
|
||||
|
||||
with open('Megaliths.gpx', 'w') as gpx_file:
|
||||
gpx_file.write('''<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gpx xmlns="http://www.topografix.com/GPX/1/1"
|
||||
version="1.1"
|
||||
creator="megalithosm"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
||||
<metadata>
|
||||
<name>Megalith sites</name>
|
||||
<author>
|
||||
<name>Jude Southworth</name>
|
||||
</author>
|
||||
</metadata>''')
|
||||
|
||||
for poi in data:
|
||||
gpx_file.write(
|
||||
'''
|
||||
<wpt lat="{}" lon="{}">
|
||||
<name>{}</name>
|
||||
<type>{}</type>
|
||||
<url>{}</url>
|
||||
</wpt>'''.format(poi['lat'], poi['lng'], escape(poi['name']), poi['type'], poi['url'])
|
||||
)
|
||||
gpx_file.write('</gpx>')
|
Loading…
Reference in New Issue
Block a user