コード例 #1
0
def test_point_3d():
    p = Point(1.0, 2.0, 3.0)

    point_proto = topb.serialize(p)

    deserialized = to_shapely.deserialize(point_proto)

    assert deserialized.coords[:] == [(1.0, 2.0, 3.0)]
コード例 #2
0
def test_empty_multipolygon():
    geom = MultiPolygon()

    multipolygon_proto = topb.serialize(geom)

    deserialized = to_shapely.deserialize(multipolygon_proto)

    assert deserialized.equals(geom)
コード例 #3
0
def test_coordinate_order_preservation():
    line = LineString(((1.0, 2.0), (3.0, 4.0)))

    line_proto = topb.serialize(line)

    deserialized = to_shapely.deserialize(line_proto)

    assert len(deserialized.coords) == 2
    assert deserialized.coords[:] == [(1.0, 2.0), (3.0, 4.0)]
コード例 #4
0
def test_3d_linestring():
    line = LineString(((1.0, 2.0, 3.0), (3.0, 4.0, 5.0)))

    line_proto = topb.serialize(line)

    deserialized = to_shapely.deserialize(line_proto)
    assert type(deserialized) is LineString

    assert deserialized.coords[:] == [(1.0, 2.0, 3.0), (3.0, 4.0, 5.0)]
コード例 #5
0
def test_empty_linearing():
    ring = LinearRing()

    ring_proto = topb.serialize(ring)

    # with pytest.raises(BaseException):
    deserialized = to_shapely.deserialize(ring_proto)

    assert deserialized.equals(ring)
コード例 #6
0
def test_multilinestring_serialization():
    geom = MultiLineString((((1.0, 2.0), (3.0, 4.0)), ))

    multiline_proto = topb.serialize(geom)

    deserialized = to_shapely.deserialize(multiline_proto)

    assert type(deserialized) is MultiLineString

    assert deserialized.equals(geom)
コード例 #7
0
def test_geometrycollection_serialization():
    coll = GeometryCollection([p, geom, ring])

    coll_proto = topb.serialize(coll)

    deserialized = to_shapely.deserialize(coll_proto)

    assert type(deserialized) is GeometryCollection

    assert deserialized.equals(coll)
コード例 #8
0
def test_linearring_serialization():
    expected_coords = [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (0.0, 0.0)]

    ring = LinearRing(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0)))

    ring_proto = topb.serialize(ring)

    deserialized = to_shapely.deserialize(ring_proto)

    assert deserialized.coords[:] == expected_coords
コード例 #9
0
def test_multipoint():
    geom = MultiPoint(((1.0, 2.0), (3.0, 4.0)))

    multipoint_proto = topb.serialize(geom)

    deserialized = to_shapely.deserialize(multipoint_proto)

    assert type(deserialized) is MultiPoint

    assert len(deserialized.geoms) == 2
コード例 #10
0
def test_linestring_serialization():
    line = LineString(((1.0, 2.0), (3.0, 4.0)))

    line_proto = topb.serialize(line)

    deserialized = to_shapely.deserialize(line_proto)

    assert type(deserialized) is LineString

    assert line.equals(deserialized)
コード例 #11
0
def test_emtpy_multipoint():
    geom = MultiPoint()

    multipoint_proto = topb.serialize(geom)

    deserialized = to_shapely.deserialize(multipoint_proto)

    assert type(deserialized) is MultiPoint

    assert deserialized.equals(geom)
コード例 #12
0
def test_polygon_empty():
    polygon = Polygon()

    polygon_proto = topb.serialize(polygon)

    deserialized = to_shapely.deserialize(polygon_proto)

    assert type(deserialized) is Polygon

    assert deserialized.equals(polygon)
コード例 #13
0
def test_multilinestring_individual_lines():
    line0 = LineString([(0.0, 1.0), (2.0, 3.0)])
    line1 = LineString([(4.0, 5.0), (6.0, 7.0)])

    multi = MultiLineString([line0, line1])

    multiline_proto = topb.serialize(multi)

    deserialized = to_shapely.deserialize(multiline_proto)

    assert multi.geoms[:] == deserialized.geoms[:]
コード例 #14
0
def test_polygonwith_holes():
    coords = [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (0.0, 0.0)]

    polygon = Polygon(coords,
                      [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))])

    polygon_proto = topb.serialize(polygon)

    deserialized = to_shapely.deserialize(polygon_proto)

    assert deserialized.exterior.coords[:] == coords

    assert len(deserialized.interiors[0].coords) == 5
コード例 #15
0
def test_multipolygon():
    geom = MultiPolygon([(
        ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),
        [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))],
    )])

    multipolygon_proto = topb.serialize(geom)

    deserialized = to_shapely.deserialize(multipolygon_proto)

    assert type(deserialized) is MultiPolygon

    assert deserialized.equals(geom)
コード例 #16
0
def test_geometrycollection_in_geometrycollection():

    coll = GeometryCollection([p, geom, ring])

    coll2 = GeometryCollection([coll, p, geom, ring])

    coll2_proto = topb.serialize(coll2)

    deserialized2 = to_shapely.deserialize(coll2_proto)

    assert type(deserialized2) is GeometryCollection

    assert deserialized2.equals(coll2)
コード例 #17
0
def test_polygon_serialization():
    coords = [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (0.0, 0.0)]

    polygon = Polygon(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0)))

    polygon_proto = topb.serialize(polygon)

    deserialized = to_shapely.deserialize(polygon_proto)

    assert type(deserialized) is Polygon

    assert deserialized.equals(polygon)

    assert deserialized.exterior.coords[:] == coords
コード例 #18
0
def test_point_serialization():
    p = Point(1.0, 2.0)

    point_proto = topb.serialize(p)

    assert point_proto.type == pb2.POINT

    coords = point_proto.coordinates
    assert len(coords) == 1

    p1 = to_shapely.deserialize(point_proto)

    assert p1.coords[:] == [(1.0, 2.0)]
    assert p1.has_z is False

    assert type(p1) is Point
コード例 #19
0
def test_multipoint_3d():
    geom = MultiPoint(((1.0, 2.0, 4.0), (3.0, 4.0, 5.0)))

    multipoint_proto = topb.serialize(geom)

    deserialized = to_shapely.deserialize(multipoint_proto)

    assert type(deserialized) is MultiPoint

    assert deserialized.geoms[0].x == 1.0
    assert deserialized.geoms[0].y == 2.0
    assert deserialized.geoms[0].z == 4.0
    assert deserialized.equals(geom)

    assert deserialized.geoms[1].x == 3.0
    assert deserialized.geoms[1].y == 4.0
    assert deserialized.geoms[1].z == 5.0