def test_bbox_union(): b1 = BoundingBox(0, 1, 10, 20) b2 = BoundingBox(5, 6, 11, 22) assert bbox_union([b1]) == b1 assert bbox_union([b2]) == b2 bb = bbox_union(iter([b1, b2])) assert bb == BoundingBox(0, 1, 11, 22) bb = bbox_union(iter([b2, b1] * 10)) assert bb == BoundingBox(0, 1, 11, 22)
def eo3_lonlat_bbox(doc, tol=None): epsg4326 = CRS('epsg:4326') crs = CRS(doc['crs']) grids = doc['grids'] geometry = doc.get('geometry') if geometry is None: return bbox_union( grid2polygon(grid, crs).to_crs(epsg4326, tol).boundingbox for grid in grids.values()) else: return Geometry(geometry, crs).to_crs(epsg4326, tol).boundingbox
def dss_to_geojson(dss, bbox=False, simplify=True, tolerance=0.001): from datacube.testutils.geom import epsg4326 from datacube.utils.geometry import bbox_union geoms = [ds.extent.to_crs(epsg4326) for ds in dss] if simplify: geoms = [g.simplify(tolerance) for g in geoms] polygons = [g.__geo_interface__ for g in geoms] if bbox: return polygons, bbox_union(g.boundingbox for g in geoms) return polygons
def eo3_lonlat_bbox(doc, tol=None): epsg4326 = CRS('epsg:4326') crs = doc.get('crs') grids = doc.get('grids') if crs is None or grids is None: raise ValueError("Input must have crs and grids") crs = CRS(crs) geometry = doc.get('geometry') if geometry is None: return bbox_union( grid2polygon(grid, crs).to_crs(epsg4326, tol).boundingbox for grid in grids.values()) else: return Geometry(geometry, crs).to_crs(epsg4326, tol).boundingbox
def eo3_lonlat_bbox(doc: Dict[str, Any], resolution: Optional[float] = None) -> BoundingBox: """ Compute bounding box in Lon/Lat for a given EO3 document. """ crs = doc.get('crs') grids = doc.get('grids') if crs is None or grids is None: raise ValueError("Input must have crs and grids") crs = CRS(crs) geom = doc.get('geometry', None) if geom is not None: geom = Geometry(geom, crs) return lonlat_bounds(geom, resolution=resolution) bounds = [ lonlat_bounds(grid2polygon(grid, crs), resolution=resolution) for grid in grids.values() ] return bbox_union(bounds)
def get_bounds(datasets, crs): bbox = geometry.bbox_union( ds.extent.to_crs(crs).boundingbox for ds in datasets) return geometry.box(*bbox, crs=crs)