pcrj_morros_bairros_rio.py 1.58 KB
Newer Older
1 2 3 4
# This script generates a gpx file for the hills and
# districts of the city of Rio de Janeiro using the
# MongoDB collections PCRJ_Locais and PCRJ_Bairros.
import bson
5
from gpx import GPX
6 7
from pymongo import MongoClient

8 9 10 11
# GPX class
gpx = GPX()
gpx.gpxbeg("Hills and districts of the city of Rio de Janeiro", \
           "Portal de Dados Geográficos Abertos da Cidade do Rio de Janeiro")
12 13 14 15 16 17 18 19 20 21 22 23

# Connect to reficio database on MongoDB server
conn = MongoClient('localhost', 27017)
db = conn.reficio

# For all hills in Rio de Janeiro
regx = bson.regex.Regex("^Morro")
for hill in db.PCRJ_Locais.find( { 'properties.Nome' : regx } ):
    name = hill['properties']['Nome']
    desc = hill['properties']['Descricao']
    lat = hill['geometry']['coordinates'][1]
    lon = hill['geometry']['coordinates'][0]
24 25
    gpx.wpt(name, desc, lat, lon)
    gpx.minmaxlatlon(lat, lon)
26

27
#  Perimeters of districts
28
for dist in db.PCRJ_Bairros.find():
29
    gpx.trkbeg(dist['properties']['NOME'])
30 31
    for geo in dist['geometry']['coordinates']:
        if dist['geometry']['type'] == 'Polygon':
32
            gpx.trksegbeg()
33
            for point in geo:
34 35
                gpx.trkpt(point[1], point[0])
                gpx.minmaxlatlon(point[1], point[0])
36
                
37
            gpx.trksegend()
38 39
        else:
            for coord in geo:
40
                gpx.trksegbeg()
41
                for point in coord:
42 43
                    gpx.trkpt(point[1], point[0])
                    gpx.minmaxlatlon(point[1], point[0])
44

45
                gpx.trksegend()
46

47
    gpx.trkend()
48

49 50
gpx.gpxend()
gpx.write()
51 52

#  WordPress OpenStreetMap Plugin
53
gpx.wposmap()