Object-oriented update

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