def test_ctrans(self): req = renderer.Request(0, 0, 0) x, y = renderer.lonlat2merc(-180, -85) ctrans = renderer.CoordTransform(req) px, py = ctrans.forward(x, y) self.assertAlmostEqual(px, 0.0) self.assertAlmostEqual(py, 255.5806938147701) px2, py2 = ctrans.forward(-20037508.34, -20037508.34) self.assertAlmostEqual(px2, 0.0) self.assertAlmostEqual(py2, 256.0) px3, py3 = ctrans.forward(-20037508.34 / 2, -20037508.34 / 2) self.assertAlmostEqual(px2, 0.0) self.assertAlmostEqual(py2, 256.0)
def test_ctrans(self): req = renderer.Request(0,0,0) x,y = renderer.lonlat2merc(-180,-85) ctrans = renderer.CoordTransform(req) px,py = ctrans.forward(x,y) self.assertAlmostEqual(px,0.0) self.assertAlmostEqual(py,255.5806938147701) px2,py2 = ctrans.forward(-20037508.34,-20037508.34) self.assertAlmostEqual(px2,0.0) self.assertAlmostEqual(py2,256.0) px3,py3 = ctrans.forward(-20037508.34/2,-20037508.34/2) self.assertAlmostEqual(px2,0.0) self.assertAlmostEqual(py2,256.0)
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')
def test_lonlat2merc(self): # projection transform # should roughtly match: echo -180 -85 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857 x, y = renderer.lonlat2merc(-180, -85) self.assertAlmostEqual(-20037508.342789244, x) self.assertAlmostEqual(-19971868.8804085888, y)
def test_lonlat2merc(self): # projection transform # should roughtly match: echo -180 -85 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857 x,y = renderer.lonlat2merc(-180,-85) self.assertAlmostEqual(-20037508.342789244,x) self.assertAlmostEqual(-19971868.8804085888,y)
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')