def test_getitem_geometry_collection(polygon): """test if GeometryCollection return self leng""" polygon = Polygon(coordinates=polygon) gc = GeometryCollection(geometries=[polygon, polygon]) assert_wkt_equivalence(gc) item = gc[0] assert item == gc[0]
def test_geometry_collection_iteration(coordinates): """test if geometry collection is iterable""" polygon = Polygon(coordinates=coordinates) gc = GeometryCollection(geometries=[polygon, polygon]) assert hasattr(gc, "__geo_interface__") assert_wkt_equivalence(gc) iter(gc)
def test_polygon_valid_coordinates(coordinates): """ Should accept lists of linear rings """ polygon = Polygon(coordinates=coordinates) assert polygon.type == "Polygon" assert polygon.coordinates == coordinates assert hasattr(polygon, "__geo_interface__")
def test_polygon_invalid_coordinates(coordinates): """ Should not accept when: - Coordinates is not a list - Not all elements in coordinates are lists - If not all elements have four or more coordinates - If not all elements are linear rings """ with pytest.raises(ValidationError): Polygon(coordinates=coordinates)
def test_polygon_valid_coordinates(coordinates): """ Should accept lists of linear rings """ polygon = Polygon(coordinates=coordinates) assert polygon.type == "Polygon" assert polygon.coordinates == coordinates assert hasattr(polygon, "__geo_interface__") assert polygon.exterior == coordinates[0] assert not list(polygon.interiors) assert_wkt_equivalence(polygon)
def test_parse_geometry_obj_polygon(): assert parse_geometry_obj({ "type": "Polygon", "coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]], }) == Polygon(coordinates=[[(100.0, 0.0), (101.0, 0.0), (101.0, 1.0), (100.0, 1.0), (100.0, 0.0)]])
def test_polygon_with_holes(): """Check interior and exterior rings.""" polygon = Polygon( coordinates=[ [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)], [(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)], ] ) assert polygon.type == "Polygon" assert hasattr(polygon, "__geo_interface__") assert polygon.exterior == polygon.coordinates[0] assert list(polygon.interiors) == [polygon.coordinates[1]] assert_wkt_equivalence(polygon)
def spatial_filter(self) -> Optional[_GeometryBase]: """Return a geojson-pydantic object representing the spatial filter for the search request. Check for both because the ``bbox`` and ``intersects`` parameters are mutually exclusive. """ if self.bbox: return Polygon(coordinates=[[ [self.bbox[0], self.bbox[3]], [self.bbox[2], self.bbox[3]], [self.bbox[2], self.bbox[1]], [self.bbox[0], self.bbox[1]], [self.bbox[0], self.bbox[3]], ]]) if self.intersects: return self.intersects return
def test_geometry_collection_iteration(coordinates): """test if geometry collection is iterable""" polygon = Polygon(coordinates=coordinates) gc = GeometryCollection(geometries=[polygon, polygon]) iter(gc)
def test_polygon_from_bounds(): """Result from `from_bounds` class method should be the same.""" coordinates = [[(1.0, 2.0), (3.0, 2.0), (3.0, 4.0), (1.0, 4.0), (1.0, 2.0)]] assert Polygon(coordinates=coordinates) == Polygon.from_bounds(1, 2, 3, 4)
def test_len_geometry_collection(polygon): """test if GeometryCollection return self leng""" polygon = Polygon(coordinates=polygon) gc = GeometryCollection(geometries=[polygon, polygon]) assert_wkt_equivalence(gc) assert len(gc) == 2