Object-oriented update

parent 1ffea960
......@@ -65,8 +65,11 @@ class GPX:
self.data.append("\t\t\t<trkpt lat=\"" + str(lat) + \
"\" lon=\"" + str(lon) + "\"></trkpt>\n")
def write(self):
f = open(self.outfile, "w")
def write(self, outfile=None):
if outfile == None:
outfile = self.outfile
f = open(outfile, "w")
for line in self.data:
f.write(line)
......@@ -79,7 +82,10 @@ class GPX:
self.minlon = min(lon, self.minlon)
# WordPress OpenStreetMap Plugin
def wposmap(self):
def wposmap(self, outfile=None):
if outfile == None:
outfile = self.outfile
medlat = (self.minlat + self.maxlat)/2
medlon = (self.minlon + self.maxlon)/2
d = datetime.date.today()
......@@ -89,5 +95,5 @@ class GPX:
"map_border=\"thin solid grey\" " + \
"file_list=\"../../../../wp-content/uploads/" + \
'{:04d}'.format(d.year) + "/" + '{:02d}'.format(d.month) + \
"/" + self.outfile + "\" file_color_list=\"blue\"]"
"/" + outfile + "\" file_color_list=\"blue\"]"
print(s)
# This script combines two collections to display the
# hotels in Buenos Aires in the neighborhood of Recoleta
# and the perimeter of Recoleta.
import json
import html
import numpy as np
from gpx import GPX
from pymongo import MongoClient
import numpy as np
# Connect to reficio database on MongoDB server
def Database():
......@@ -15,38 +14,10 @@ def Database():
db = Database()
# GPX heading
gpx = open("hotels_recoleta.gpx", "w")
gpx.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
gpx.write("<gpx version=\"1.1\" " + \
"creator=\"Reficio - http://reficio.cc\" " + \
"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\">\n")
gpx.write("\t<metadata>\n")
gpx.write("\t\t<name>Hotels in Buenos Aires in the neighborhood of Recoleta</name>\n")
gpx.write("\t\t<desc>Buenos Aires Data + Geonames</desc>\n")
gpx.write("\t\t<author>\n")
gpx.write("\t\t\t<name>Halley Pacheco de Oliveira</name>\n")
gpx.write("\t\t\t<email id=\"reficio\" domain=\"reficio.cc\" />\n")
gpx.write("\t\t\t<link href=\"http://reficio.cc/\">\n")
gpx.write("\t\t\t\t<text>Reficio</text>\n")
gpx.write("\t\t\t</link>\n")
gpx.write("\t\t</author>\n")
gpx.write("\t</metadata>\n")
def wpt(name, desc, lat, lon):
gpx.write("\t<wpt lat=\"" + lat + "\" lon=\"" + lon + "\">\n")
gpx.write("\t\t<name>" + html.escape(name) + "</name>\n")
gpx.write("\t\t<desc>" + html.escape(desc) + "</desc>\n")
gpx.write("\t</wpt>\n")
return
def trkpt(lat, lon):
gpx.write("\t\t\t<trkpt lat=\"" + lat + "\" lon=\"" + lon + "\"></trkpt>\n")
return
# GPX class
gpx = GPX()
gpx.gpxbeg("Hotels in Buenos Aires in the neighborhood of Recoleta", \
"Buenos Aires Data + Geonames")
# Geometry of the neighborhood of Recoleta
# from the barrios_porteños collection
......@@ -74,21 +45,24 @@ for geoname in geonamesar.find( \
lat = geoname['features'][0]['geometry']['coordinates'][1]
lon = geoname['features'][0]['geometry']['coordinates'][0]
hotels.append(np.array(name))
wpt(name, geonameid, str(lat), str(lon))
gpx.wpt(name, geonameid, lat, lon)
gpx.minmaxlatlon(lat, lon)
# Perimeter of Recoleta
gpx.write("\t<trk>\n")
gpx.write("\t\t<name>Perimeter of Recoleta</name>\n")
gpx.write("\t\t<trkseg>\n")
gpx.trkbeg("Perimeter of Recoleta")
gpx.trksegbeg()
for geo in geometry[0]:
trkpt(str(geo[1]),str(geo[0]))
gpx.trkpt(geo[1],geo[0])
gpx.minmaxlatlon(geo[1],geo[0])
gpx.write("\t\t</trkseg>\n")
gpx.write("\t</trk>\n")
gpx.write("</gpx>")
gpx.close()
gpx.trksegend()
gpx.trkend()
gpx.gpxend()
gpx.write()
# WordPress OpenStreetMap Plugin
gpx.wposmap()
# Print the hotels in alphabetical order
for hotel in sorted(hotels):
print(hotel)
......@@ -3,8 +3,7 @@
# collection PCRJ_Locais.
import sys
import bson
import html
import datetime
from gpx import GPX
from pymongo import MongoClient
# Parameter = location name
......@@ -14,35 +13,12 @@ if len(sys.argv) < 2:
sys.exit()
location_name = str(sys.argv[1])
outfile = location_name.replace(" ", "_").lower() + ".gpx"
# GPX file
gpxfile = location_name.replace(" ", "_").lower() + ".gpx"
gpx = open(gpxfile, "w")
gpx.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
gpx.write("<gpx version=\"1.1\" " + \
"creator=\"Reficio - http://reficio.cc\" " + \
"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\">\n")
gpx.write("\t<metadata>\n")
gpx.write("\t\t<name>" + location_name + "</name>\n")
gpx.write("\t\t<desc>Portal de Dados Geográficos Abertos da Cidade do Rio de Janeiro</desc>\n")
gpx.write("\t\t<author>\n")
gpx.write("\t\t\t<name>Halley Pacheco de Oliveira</name>\n")
gpx.write("\t\t\t<email id=\"reficio\" domain=\"reficio.cc\" />\n")
gpx.write("\t\t\t<link href=\"http://reficio.cc/\">\n")
gpx.write("\t\t\t\t<text>Reficio</text>\n")
gpx.write("\t\t\t</link>\n")
gpx.write("\t\t</author>\n")
gpx.write("\t</metadata>\n")
def wpt(name, desc, lat, lon):
gpx.write("\t<wpt lat=\"" + lat + "\" lon=\"" + lon + "\">\n")
gpx.write("\t\t<name>" + html.escape(name) + "</name>\n")
gpx.write("\t\t<desc>" + html.escape(desc) + "</desc>\n")
gpx.write("\t</wpt>\n")
return
# GPX class
gpx = GPX()
gpx.gpxbeg(location_name, \
"Portal de Dados Geográficos Abertos da Cidade do Rio de Janeiro")
# Connect to reficio database on MongoDB server
conn = MongoClient('localhost', 27017)
......@@ -57,21 +33,13 @@ if location:
desc = location['properties']['Descricao']
lat = location['geometry']['coordinates'][1]
lon = location['geometry']['coordinates'][0]
wpt(name, desc, str(lat), str(lon))
gpx.wpt(name, desc, lat, lon)
else:
print("Location not found")
sys.exit()
gpx.write("</gpx>")
gpx.close()
gpx.gpxend()
gpx.write(outfile)
# WordPress OpenStreetMap Plugin
d = datetime.date.today()
s = "[osm_map_v3 map_center=\"" + \
str(lat) + "," + str(lon) + \
"\" zoom=\"14\" width=\"100%\" height=\"480\" " + \
"map_border=\"thin solid grey\" " + \
"file_list=\"../../../../wp-content/uploads/" + \
'{:04d}'.format(d.year) + "/" + '{:02d}'.format(d.month) + \
"/" + gpxfile + "\" file_color_list=\"blue\"]"
print(s)
gpx.wposmap(outfile)
\ No newline at end of file
# This script generates a gpx file for the perimeter of Recoleta
import json
import html
import numpy as np
# This script genaretes a gpx file for the perimeter of Recoleta
from gpx import GPX
from pymongo import MongoClient
import numpy as np
# Connect to reficio database on MongoDB server
def Database():
......@@ -13,44 +12,26 @@ def Database():
db = Database()
# GPX heading
gpx = open("perimeter_recoleta.gpx", "w")
gpx.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
gpx.write("<gpx version=\"1.1\" " + \
"creator=\"Reficio - http://reficio.cc\" " + \
"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\">\n")
gpx.write("\t<metadata>\n")
gpx.write("\t\t<name>Perimeter of Recoleta</name>\n")
gpx.write("\t\t<desc>Buenos Aires Data</desc>\n")
gpx.write("\t\t<author>\n")
gpx.write("\t\t\t<name>Halley Pacheco de Oliveira</name>\n")
gpx.write("\t\t\t<email id=\"reficio\" domain=\"reficio.cc\" />\n")
gpx.write("\t\t\t<link href=\"http://reficio.cc/\">\n")
gpx.write("\t\t\t\t<text>Reficio</text>\n")
gpx.write("\t\t\t</link>\n")
gpx.write("\t\t</author>\n")
gpx.write("\t</metadata>\n")
gpx.write("\t<trk>\n")
gpx.write("\t\t<name>Perimeter of Recoleta</name>\n")
gpx.write("\t\t<trkseg>\n")
# GPX class
gpx = GPX()
gpx.gpxbeg("Perimeter of Recoleta", \
"Buenos Aires Data")
def trkpt(lat, lon):
gpx.write("\t\t\t<trkpt lat=\"" + lat + "\" lon=\"" + lon + "\"></trkpt>\n")
return
# Perimeter of Recoleta coordinates
# Perimeter of Recoleta
gpx.trkbeg("Perimeter of Recoleta")
gpx.trksegbeg()
barrios_porteños = db.barrios_porteños
barrio = barrios_porteños.find_one( { 'properties.BARRIO' : 'RECOLETA' } )
geometry = barrio['geometry']['coordinates']
for geo in geometry[0]:
trkpt(str(geo[1]),str(geo[0]))
gpx.trkpt(geo[1],geo[0])
gpx.minmaxlatlon(geo[1],geo[0])
gpx.trksegend()
gpx.trkend()
gpx.gpxend()
gpx.write()
gpx.write("\t\t</trkseg>\n")
gpx.write("\t</trk>\n")
gpx.write("</gpx>")
gpx.close()
# WordPress OpenStreetMap Plugin
gpx.wposmap()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment