Exemplo n.º 1
0
def test_collection():
    g = GeometryCollection([Point(1, 2), LineString([(1, 2), (3, 4)])])
    assert hash(g) == hash(
        GeometryCollection([Point(1, 2),
                            LineString([(1, 2), (3, 4)])]))
    assert hash(g) != hash(
        GeometryCollection([Point(1, 2),
                            LineString([(1, 2), (3, 3)])]))
Exemplo n.º 2
0
def test_empty_subgeoms():
    geom = GeometryCollection([Point(), LineString()])
    assert geom.type == "GeometryCollection"
    assert geom.type == geom.geom_type
    assert geom.is_empty
    assert len(geom.geoms) == 2
    assert list(geom.geoms) == [Point(), LineString()]
Exemplo n.º 3
0
def test_numpy_object_array():
    geom = GeometryCollection([LineString([(0, 0), (1, 1)])])
    ar = np.empty(1, object)
    ar[:] = [geom]
    assert ar[0] == geom
Exemplo n.º 4
0
            {
                "type": "Point",
                "coordinates": (0, 3, 0)
            },
            {
                "type": "LineString",
                "coordinates": ((2, 0), (1, 0))
            },
        ],
    }


@pytest.mark.parametrize(
    "geom",
    [
        GeometryCollection(),
        shape({
            "type": "GeometryCollection",
            "geometries": []
        }),
        wkt.loads("GEOMETRYCOLLECTION EMPTY"),
    ],
)
def test_empty(geom):
    assert geom.type == "GeometryCollection"
    assert geom.type == geom.geom_type
    assert geom.is_empty
    assert len(geom.geoms) == 0
    assert list(geom.geoms) == []

Exemplo n.º 5
0
def test_numpy_object_array():
    geoms = [Point(), GeometryCollection()]
    arr = np.empty(2, object)
    arr[:] = geoms
Exemplo n.º 6
0
 def test_empty_geometry_collection(self):
     assert GeometryCollection().is_empty
Exemplo n.º 7
0
def test_geometry_collection():
    assert bool(GeometryCollection()) is False
Exemplo n.º 8
0
    assert bool(Point()) is False


def test_geometry_collection():
    assert bool(GeometryCollection()) is False


geometries_all_types = [
    Point(1, 1),
    LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]),
    LineString([(0, 0), (1, 1), (0, 1), (0, 0)]),
    Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]),
    MultiPoint([(1, 1)]),
    MultiLineString([[(0, 0), (1, 1), (0, 1), (0, 0)]]),
    MultiPolygon([Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])]),
    GeometryCollection([Point(1, 1)]),
]


@pytest.mark.parametrize("geom", geometries_all_types)
def test_setattr_disallowed(geom):
    with pytest.raises(AttributeError):
        geom.name = "test"


@pytest.mark.parametrize("geom", geometries_all_types)
def test_comparison_notimplemented(geom):
    # comparing to a non-geometry class should return NotImplemented in __eq__
    # to ensure proper delegation to other (eg to ensure comparison of scalar
    # with array works)
    # https://github.com/shapely/shapely/issues/1056