def test_unary_union(): box1 = geometry.box(10, 10, 30, 30, crs=epsg4326) box2 = geometry.box(20, 10, 40, 30, crs=epsg4326) box3 = geometry.box(30, 10, 50, 30, crs=epsg4326) box4 = geometry.box(40, 10, 60, 30, crs=epsg4326) union0 = geometry.unary_union([box1]) assert union0 == box1 union1 = geometry.unary_union([box1, box4]) assert union1.type == 'MultiPolygon' assert union1.area == 2.0 * box1.area union2 = geometry.unary_union([box1, box2]) assert union2.type == 'Polygon' assert union2.area == 1.5 * box1.area union3 = geometry.unary_union([box1, box2, box3, box4]) assert union3.type == 'Polygon' assert union3.area == 2.5 * box1.area union4 = geometry.unary_union([union1, box2, box3]) assert union4.type == 'Polygon' assert union4.area == 2.5 * box1.area assert geometry.unary_union([]) is None with pytest.raises(ValueError): geometry.unary_union([box1, box1.to_crs(epsg3577)])
def polygon_from_sources_extents(sources, geobox): sources_union = geometry.unary_union( source.extent.to_crs(geobox.crs) for source in sources) if sources_union is None: _LOG.warning('Failed to compute "valid_region" from a set of datasets') return geobox.extent valid_data = geobox.extent.intersection(sources_union) resolution = min([abs(x) for x in geobox.resolution]) return valid_data.simplify(tolerance=resolution * 0.01)
def polygon_from_sources_extents(sources, geobox): sources_union = geometry.unary_union(source.extent.to_crs(geobox.crs) for source in sources) # TODO: remove ._geom check once datacube-core is fixed older versions of # datacube returned unusable Geometry object instead of None on # failure if sources_union is None or sources_union._geom is None: # pylint: disable=protected-access _LOG.warning('Failed to compute "valid_region" from a set of datasets') return geobox.extent valid_data = geobox.extent.intersection(sources_union) resolution = min([abs(x) for x in geobox.resolution]) return valid_data.simplify(tolerance=resolution * 0.01)
def test_unary_union(): box1 = geometry.box(10, 10, 30, 30, crs=geometry.CRS('EPSG:4326')) box2 = geometry.box(20, 10, 40, 30, crs=geometry.CRS('EPSG:4326')) box3 = geometry.box(30, 10, 50, 30, crs=geometry.CRS('EPSG:4326')) box4 = geometry.box(40, 10, 60, 30, crs=geometry.CRS('EPSG:4326')) union0 = geometry.unary_union([box1]) assert union0 == box1 union1 = geometry.unary_union([box1, box4]) assert union1.type == 'MultiPolygon' assert union1.area == 2.0 * box1.area union2 = geometry.unary_union([box1, box2]) assert union2.type == 'Polygon' assert union2.area == 1.5 * box1.area union3 = geometry.unary_union([box1, box2, box3, box4]) assert union3.type == 'Polygon' assert union3.area == 2.5 * box1.area union4 = geometry.unary_union([union1, box2, box3]) assert union4.type == 'Polygon' assert union4.area == 2.5 * box1.area
def _polygon_from_sources_extents(sources, geobox): sources_union = geometry.unary_union( source.extent.to_crs(geobox.crs) for source in sources) valid_data = geobox.extent.intersection(sources_union) return valid_data
def valid_region(dataset_box, index): item = dataset_box.box[index].item() datasets = item['collate'][1] return unary_union(ds.extent for ds in datasets)
def polygon_from_sources_extents(sources, geobox): sources_union = geometry.unary_union( source.extent.to_crs(geobox.crs) for source in sources) valid_data = geobox.extent.intersection(sources_union) resolution = min([abs(x) for x in geobox.resolution]) return valid_data.simplify(tolerance=resolution * 0.01)