Exemple #1
0
 def test_adding_duplicate_points(self):
     req = renderer.Request(0, 0, 0)
     vtile = renderer.VectorTile(req)
     vtile.add_point(0, 0, {})
     vtile.add_point(0, 0, {})
     j_obj = json.loads(vtile.to_geojson())
     self.assertEqual(len(j_obj['features']), 1)
Exemple #2
0
 def test_vtile_z0(self):
     req = renderer.Request(0, 0, 0)
     vtile = renderer.VectorTile(req)
     x, y = -8526703.378081053, 4740318.745473632
     vtile.add_point(x, y, {})
     j_obj = json.loads(vtile.to_geojson())
     feature = j_obj['features'][0]
     self.assertEqual(feature['type'], 'Feature')
     self.assertEqual(feature['geometry']['type'], 'Point')
     coords = feature['geometry']['coordinates']
     self.assertAlmostEqual(coords[0], x, -4)
     self.assertAlmostEqual(coords[1], y, -4)
Exemple #3
0
 def test_vtile_z22_higher_precision(self):
     merc = renderer.SphericalMercator()
     x, y = -8526703.378081053, 4740318.745473632
     xyz_bounds = merc.xyz([x, y, x, y], 22)
     req = renderer.Request(xyz_bounds[0], xyz_bounds[1], 22)
     vtile = renderer.VectorTile(req, 512)
     vtile.add_point(x, y, {})
     j_obj = json.loads(vtile.to_geojson())
     feature = j_obj['features'][0]
     coords = feature['geometry']['coordinates']
     self.assertAlmostEqual(coords[0], x, 4)
     self.assertAlmostEqual(coords[1], y, 4)
Exemple #4
0
 def test_vtile_attributes(self):
     req = renderer.Request(0, 0, 0)
     vtile = renderer.VectorTile(req)
     attr = {
         "name": "DC",
         "integer": 10,
         "bigint": sys.maxint,
         "nbigint": -1 * sys.maxint,
         "float": 1.5,
         "bigfloat": float(sys.maxint),
         "unistr": u"élan",
         "bool": True,
         "bool2": False
     }
     vtile.add_point(0, 0, attr)
     j_obj = json.loads(vtile.to_geojson())
     self.assertEqual(j_obj['type'], "FeatureCollection")
     self.assertEqual(len(j_obj['features']), 1)
     feature = j_obj['features'][0]
     self.assertDictEqual(feature['properties'], attr)
Exemple #5
0
 def test_vtile_z20(self):
     merc = renderer.SphericalMercator()
     x, y = -8526703.378081053, 4740318.745473632
     xyz_bounds = merc.xyz([x, y, x, y], 20)
     req = renderer.Request(xyz_bounds[0], xyz_bounds[1], 20)
     vtile = renderer.VectorTile(req)
     vtile.add_point(x, y, {"name": "DC", "integer": 10, "float": 1.5})
     j_obj = json.loads(vtile.to_geojson())
     self.assertEqual(j_obj['type'], "FeatureCollection")
     self.assertEqual(len(j_obj['features']), 1)
     feature = j_obj['features'][0]
     self.assertDictEqual(feature['properties'], {
         "integer": 10,
         "float": 1.5,
         "name": "DC"
     })
     self.assertEqual(feature['type'], 'Feature')
     self.assertEqual(feature['geometry']['type'], 'Point')
     coords = feature['geometry']['coordinates']
     self.assertAlmostEqual(coords[0], x, 2)
     self.assertAlmostEqual(coords[1], y, 2)
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