This commit is contained in:
NN Solex 2023-05-01 21:58:23 +03:00
parent 33d02a4845
commit 20c0224bc8
53 changed files with 1329 additions and 60 deletions

View file

@ -0,0 +1 @@
from .geodata import *

Binary file not shown.

View file

@ -0,0 +1,73 @@
from pelican import signals
from xml.dom import minidom
collection = {}
gpx_root = '''<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" 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" version="1.1" creator="nfc.flux.vision"></gpx>'''
kml_root = '''<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"><Document><Folder></Folder></Document></kml>'''
def make_files(void):
makeGPX()
makeKML()
def makeKML():
if len(collection) > 0:
for category in collection:
root = minidom.parseString(kml_root)
folder = root.createElement('name')
foldername = root.createTextNode( collection[category]["name"] )
folder.appendChild( foldername )
root.childNodes[0].childNodes[0].childNodes[0].appendChild( folder )
for place in collection[category]["points"]:
placemark = root.createElement('Placemark')
name = root.createElement('name')
title = root.createTextNode( place['name'] )
name.appendChild( title )
placemark.appendChild( name )
point = root.createElement('Point')
coordinates = root.createElement('coordinates')
lat, lon = place['coordinates'].replace(' ', '').split(',')
latlon = root.createTextNode( lon + ',' + lat)
coordinates.appendChild( latlon )
point.appendChild( coordinates )
placemark.appendChild( point )
root.childNodes[0].childNodes[0].childNodes[0].appendChild( placemark )
with open('output/projects/' + category + '.kml', 'w') as xml_file:
root.writexml(xml_file, indent="", addindent=" ", newl='\n')
def makeGPX():
if len(collection) > 0:
for category in collection:
root = minidom.parseString(kml_root)
for place in collection[category]["points"]:
lat, lon = place['coordinates'].replace(' ', '').split(',')
wpt = root.createElement('wpt')
wpt.setAttribute('lat', lat)
wpt.setAttribute('lon', lon)
name = root.createElement('name')
title = root.createTextNode( place['name'] )
name.appendChild( title )
wpt.appendChild( name )
root.childNodes[0].appendChild( wpt )
with open('output/projects/' + category + '.gpx', 'w') as xml_file:
root.writexml(xml_file, indent="", addindent=" ", newl='\n')
def geodata(generator):
for category, articles in generator.categories:
locations = []
for article in articles:
if "location" in article.metadata:
locations.append({
"name": article.title,
"coordinates": article.metadata["location"]
})
collection.update({
category.slug : {
"name" : category.name,
"points" : locations
}})
def register():
signals.article_generator_finalized.connect(geodata)
signals.finalized.connect(make_files)

View file

@ -5,7 +5,8 @@ def generate_geohash(generator):
for article in generator.articles:
if "location" in article.metadata:
lat, lon = [float(i) for i in article.metadata['location'].replace(' ', '').split(',')]
article.metadata['latlon'] = article.metadata['location'].replace(' ', '')
article.metadata['lat'] = lat
article.metadata['lon'] = lon
article.metadata['geohash'] = gh.encode(lat, lon, 11)
article.slug = gh.encode(lat, lon, 11)