Ejemplo n.º 1
0
 def test_ctrans_z0(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)
Ejemplo n.º 2
0
 def test_ctrans_z0(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)
Ejemplo n.º 3
0
 def test_simple_tile_z0(self):
     """ Test creating a tile, adding a single layer and a single point """
     req = renderer.Request(0, 0, 0)
     vtile = renderer.VectorTile(req)
     #Test creating a layer
     layerName = "points"
     layer = vtile.add_layer(name=layerName)
     #test adding a point feature
     lat, lng = 38, -121
     attr = {"hello": "world"}
     x, y = renderer.lonlat2merc(lng, lat)
     assert vtile.add_point(layer, x, y, attr)
     assert len(layer.features) == 1
     feature = layer.features[0]
     key_id = feature.tags[0]
     value_id = feature.tags[1]
     key = str(layer.keys[key_id])
     assert key == "hello"
     value = layer.values[value_id]
     assert value.HasField('string_value')
     assert value.string_value == "world"
     #dump the layer to GeoJSON and make sure the output matches the input
     j_obj = vtile.to_geojson(layer_names=True, lonlat=True)
     assert isinstance(j_obj, dict)
     self.assertEqual(j_obj["type"], "FeatureCollection")
     self.assertEqual(len(j_obj["features"]), 1)
     self.assertEqual(j_obj["features"][0]["geometry"]["type"], "Point")
     self.assertEqual(len(j_obj["features"][0]["geometry"]["coordinates"]),
                      2)
     self.assertAlmostEqual(
         j_obj["features"][0]["geometry"]["coordinates"][0], lng, 0)
     self.assertAlmostEqual(
         j_obj["features"][0]["geometry"]["coordinates"][1], lat, 0)
     self.assertEqual(j_obj["features"][0]["properties"]["layer"],
                      layerName)
     self.assertEqual(j_obj["features"][0]["properties"]["hello"], "world")
     #now dump tile to protocol buffer message
     pbf = vtile.to_message()
     assert len(pbf) > 0
     tile = vector_tile_pb2.Tile()
     tile.ParseFromString(pbf)
     vtile2 = renderer.VectorTile(req, tile)
     j_obj_deserialized = vtile2.to_geojson(layer_names=True, lonlat=True)
     self.assertDictEqual(j_obj, j_obj_deserialized)
Ejemplo n.º 4
0
 def test_simple_tile_z0(self):
     """ Test creating a tile, adding a single layer and a single point """
     req = renderer.Request(0,0,0)
     vtile = renderer.VectorTile(req)
     #Test creating a layer
     layerName = "points"
     layer = vtile.add_layer(name=layerName)
     #test adding a point feature
     lat, lng = 38, -121
     attr = {"hello":"world"}
     x,y = renderer.lonlat2merc(lng,lat)
     assert vtile.add_point(layer,x,y,attr)
     assert len(layer.features) == 1
     feature = layer.features[0]
     key_id = feature.tags[0]
     value_id = feature.tags[1]
     key = str(layer.keys[key_id])
     assert key == "hello"
     value = layer.values[value_id]
     assert value.HasField('string_value')
     assert value.string_value == "world"
     #dump the layer to GeoJSON and make sure the output matches the input
     j_obj = vtile.to_geojson(layer_names=True, lonlat=True)
     assert isinstance(j_obj, dict)
     self.assertEqual(j_obj["type"], "FeatureCollection")
     self.assertEqual(len(j_obj["features"]), 1)
     self.assertEqual(j_obj["features"][0]["geometry"]["type"], "Point")
     self.assertEqual(len(j_obj["features"][0]["geometry"]["coordinates"]), 2)
     self.assertAlmostEqual(j_obj["features"][0]["geometry"]["coordinates"][0], lng, 0)
     self.assertAlmostEqual(j_obj["features"][0]["geometry"]["coordinates"][1], lat, 0)
     self.assertEqual(j_obj["features"][0]["properties"]["layer"], layerName)
     self.assertEqual(j_obj["features"][0]["properties"]["hello"], "world")
     #now dump tile to protocol buffer message
     pbf = vtile.to_message()
     assert len(pbf) > 0
     tile = vector_tile_pb2.Tile()
     tile.ParseFromString(pbf)
     vtile2 = renderer.VectorTile(req, tile)
     j_obj_deserialized = vtile2.to_geojson(layer_names=True, lonlat=True)
     self.assertDictEqual(j_obj, j_obj_deserialized)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
 # create a layer in the tile
 layer = vtile.add_layer(name="points")
 # 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(layer,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(json.dumps(vtile.to_geojson(), indent=4))
 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
 if sys.version_info.major == 3:
     print('Serialized, gzip-coded tile message as bytes:')
     print(vtile.to_message())
Ejemplo n.º 8
0
 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)
 # create a layer in the tile
 layer = vtile.add_layer(name="points")
 # 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(layer, 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(json.dumps(vtile.to_geojson(), indent=4))
 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
 if sys.version_info.major == 3:
     print('Serialized, gzip-coded tile message as bytes:')
     print(vtile.to_message())