File: hello-world.py

package info (click to toggle)
mapnik-vector-tile 0.5.1%2Bdfsg-1.3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,548 kB
  • ctags: 249
  • sloc: cpp: 2,483; python: 421; makefile: 65; xml: 12
file content (40 lines) | stat: -rwxr-xr-x 1,300 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import json
# put `./lib` dir on path
sys.path.append("./python")

import renderer

if __name__ == "__main__" :
    # create a single tile at 0/0/0.png like tile.osm.org/0/0/0.png
    zoom = 0
    x = 0
    y = 0
    # request object holds a Tile XYZ and internally holds mercator extent
    req = renderer.Request(x,y,zoom)
    # create a vector tile, given a tile request
    vtile = renderer.VectorTile(req)
    # for a given point representing a spot in NYC
    lat = 40.70512
    lng = -74.01226
    # and some attributes
    attr = {"hello":"world"}
    # convert to mercator coords
    x,y = renderer.lonlat2merc(lng,lat)
    # add this point and attributes to the tile
    vtile.add_point(x,y,attr)
    # print the protobuf as geojson just for debugging
    # NOTE: coordinate rounding is by design and 
    print 'GeoJSON representation of tile (purely for debugging):'
    print vtile.to_geojson()
    print '-'*60
    # print the protobuf message as a string
    print 'Protobuf string representation of tile (purely for debugging):'
    print vtile
    print '-'*60
    # print the protobuf message, zlib encoded
    print 'Serialized, deflated tile message (storage and wire format):'
    print vtile.to_message().encode('zlib')