def test_collection_add(): gv1 = GeoVector.from_bounds(xmin=0, ymin=0, xmax=2, ymax=1) gv2 = GeoVector.from_bounds(xmin=1, ymin=0, xmax=3, ymax=1) gv3 = GeoVector.from_bounds(xmin=2, ymin=0, xmax=4, ymax=1) gv4 = GeoVector.from_bounds(xmin=3, ymin=0, xmax=5, ymax=1) assert (gv1 + gv2) == FeatureCollection.from_geovectors([gv1, gv2]) assert (gv1 + gv2 + gv3) == FeatureCollection.from_geovectors( [gv1, gv2, gv3]) assert (((gv1 + gv2) + (gv3 + gv4)) == (gv1 + gv2 + gv3 + gv4) == FeatureCollection.from_geovectors([gv1, gv2, gv3, gv4]))
def test_featurecollection_schema_raises_error_for_heterogeneous_types(): fc = FeatureCollection.from_geovectors([ GeoVector(Polygon.from_bounds(0, 0, 1, 1)), GeoVector(Point(0, 0)) ]) with pytest.raises(FeatureCollectionIOError) as excinfo: fc.schema assert "Cannot generate a schema for a heterogeneous FeatureCollection. " in excinfo.exconly()
def test_convex_hull_and_envelope(): fc = FeatureCollection.from_geovectors([ GeoVector.from_bounds(xmin=0, ymin=0, xmax=1, ymax=1), GeoVector.from_bounds(xmin=1, ymin=0, xmax=2, ymax=1), GeoVector.from_bounds(xmin=1, ymin=1, xmax=2, ymax=2), ]) expected_convex_hull = GeoVector(Polygon([(0, 0), (2, 0), (2, 2), (1, 2), (0, 1), (0, 0)])) expected_envelope = GeoVector.from_bounds(xmin=0, ymin=0, xmax=2, ymax=2) assert fc.convex_hull.equals(expected_convex_hull) assert fc.envelope.equals(expected_envelope)
def test_rasterization_point_single_pixel(): data = np.zeros((5, 5), dtype=np.uint8)[None, :, :] data[0, 2, 2] = 1 mask = ~(data.astype(bool)) expected_image = np.ma.masked_array(data, mask) fc = FeatureCollection.from_geovectors([ GeoVector(Point(2, 2), crs=WEB_MERCATOR_CRS)] ) roi = GeoVector.from_bounds(xmin=0, ymin=0, xmax=5, ymax=5, crs=WEB_MERCATOR_CRS) result = fc.rasterize(1, polygonize_width=1, bounds=roi).image assert_array_equal(result.data, expected_image.data) assert_array_equal(result.mask, expected_image.mask)
def __add__(self, other): # Avoids circular imports from telluric.collections import FeatureCollection return FeatureCollection.from_geovectors([self, other])
def test_feature_collection_from_vectors_is_not_from_rasters(): gv1 = GeoVector.from_bounds(xmin=0, ymin=0, xmax=2, ymax=1) gv2 = GeoVector.from_bounds(xmin=1, ymin=0, xmax=3, ymax=1) fc = FeatureCollection.from_geovectors([gv1, gv2]) assert not fc.is_rasters_collection()