Object-oriented update

parent 22812851
# Airports in Brazil
# This script genaretes a gpx file for
# airports in gnsbr collection.
import json
import bson
import html
import datetime
import numpy as np
from gpx import GPX
from pymongo import MongoClient
# GPX file
gpxfile = "gnsbr_airports.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>Airports in Brazil</name>\n")
gpx.write("\t\t<desc>NGA GEOnet Names Server (GNS)</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
# To calculate the center of the map
minlat = 90
maxlat = -90
minlon = 180
maxlon = -180
def minmaxlatlon(lat, lon):
global maxlat, minlat, maxlon, minlon
maxlat = max(lat,maxlat)
minlat = min(lat,minlat)
maxlon = max(lon,maxlon)
minlon = min(lon,minlon)
# GPX class
gpx = GPX()
gpx.gpxbeg("Airports in Brazil", \
"NGA GEOnet Names Server (GNS)")
# Connect to reficio database on MongoDB server
conn = MongoClient('192.168.0.7', 27017)
......@@ -61,21 +20,11 @@ for airp in db.gnsbr.find({'features.properties.DSG' : "AIRP"}):
desc = airp['features'][0]['properties']['GENERIC']
lat = airp['features'][0]['geometry']['coordinates'][1]
lon = airp['features'][0]['geometry']['coordinates'][0]
wpt(name, desc, str(lat), str(lon))
minmaxlatlon(lat, lon)
gpx.wpt(name, desc, lat, lon)
gpx.minmaxlatlon(lat, lon)
gpx.write("</gpx>")
gpx.close()
gpx.gpxend()
gpx.write()
# WordPress OpenStreetMap Plugin
medlat = (minlat + maxlat)/2
medlon = (minlon + maxlon)/2
d = datetime.date.today()
s = "[osm_map_v3 map_center=\"" + \
str(medlat) + "," + str(medlon) + \
"\" 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()
\ No newline at end of file
......@@ -9,9 +9,8 @@
# address on the map using the OpenStreetMap.
#
# -*- coding: utf-8 -*-
from gpx import GPX
import http.client, urllib.parse
import html
import json
# Read the Google Maps Key from 'GoogleMapsKey.txt' file
......@@ -24,13 +23,6 @@ address = 'Igreja de Nossa Senhora da Candelária - Praça Pio X'
params = '?address=' + urllib.parse.quote (address) + \
'&key=' + GoogleMapsKey
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 get_response():
conn = http.client.HTTPSConnection(host)
conn.request("GET", path + params)
......@@ -40,30 +32,16 @@ def get_response():
results = json.loads(get_response())
print(json.dumps(results, indent=4))
formatted_address = results['results'][0]['formatted_address']
lat = str(results['results'][0]['geometry']['location']['lat'])
lon = str(results['results'][0]['geometry']['location']['lng'])
# GPX
gpx = open("google_maps_candelaria.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>" + address + "</name>\n")
gpx.write("\t\t<desc>" + formatted_address + "</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")
wpt(address, formatted_address, lat, lon)
gpx.write("</gpx>")
gpx.close()
lat = results['results'][0]['geometry']['location']['lat']
lon = results['results'][0]['geometry']['location']['lng']
# GPX class
gpx = GPX()
gpx.gpxbeg(address, formatted_address)
gpx.wpt(address, formatted_address, lat, lon)
gpx.minmaxlatlon(lat, lon)
gpx.gpxend()
gpx.write()
# WordPress OpenStreetMap Plugin
gpx.wposmap()
\ No newline at end of file
# This script genaretes a gpx file for the cities of the
# This script genaretes a gpx file for the Municipalities of
# State of Rio de Janeiro using the ibgelocalidades collection.
import json
import html
import numpy as np
from gpx import GPX
from pymongo import MongoClient
# GPX heading
gpx = open("ibge_cidades_rj.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>Cidades do Estado do Rio de Janeiro - Cities of the State of Rio de Janeiro</name>\n")
gpx.write("\t\t<desc>IBGE (Instituto Brasileiro de Geografia e Estatística / Brazilian Institute of Geography and Statistics)</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("Cidades do Estado do Rio de Janeiro - Cities of the State of Rio de Janeiro", \
"IBGE (Instituto Brasileiro de Geografia e Estatística / Brazilian Institute of Geography and Statistics)")
# Connect to reficio database on MongoDB server
conn = MongoClient('localhost', 27017)
db = conn.reficio
# For cities in Rio de Janeiro
# For cities in Rio de Janeiro State
for city in db.ibgelocalidades.find({ "$and": \
[{'properties.NM_UF' : 'RIO DE JANEIRO'}, \
{'properties.NM_CATEGOR' : 'CIDADE'}]}):
......@@ -47,7 +21,11 @@ for city in db.ibgelocalidades.find({ "$and": \
lat = city['geometry']['coordinates'][1]
lon = city['geometry']['coordinates'][0]
print(name + " - " + desc)
wpt(name, desc, str(lat), str(lon))
gpx.wpt(name, desc, lat, lon)
gpx.minmaxlatlon(lat, lon)
gpx.gpxend()
gpx.write()
gpx.write("</gpx>")
gpx.close()
# WordPress OpenStreetMap Plugin
gpx.wposmap()
\ No newline at end of file
# This script genaretes a gpx file for idee_faros_espana collection.
import json
import html
import numpy as np
from gpx import GPX
from pymongo import MongoClient
# GPX heading
gpx = open("idee_faros_espana.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>Faros de España - Lighthouses of Spain</name>\n")
gpx.write("\t\t<desc>Geoportal IDEE - Infraestructura de Datos Espaciales de España</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("Faros de España - Lighthouses of Spain", \
"Geoportal IDEE - Infraestructura de Datos Espaciales de España")
# Connect to reficio database on MongoDB server
conn = MongoClient('localhost', 27017)
......@@ -45,7 +18,11 @@ for faro in db.idee_faros_espana.find():
id = faro['properties']['id']
lat = faro['geometry']['coordinates'][1]
lon = faro['geometry']['coordinates'][0]
wpt(identificador_geografico, id, str(lat), str(lon))
gpx.wpt(identificador_geografico, id, lat, lon)
gpx.minmaxlatlon(lat, lon)
gpx.gpxend()
gpx.write()
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