def test_lonalt_bounds_more_than_180(): poly = geometry.box(-150, -30, 150, 30, epsg4326).to_crs(epsg3857, math.inf) assert geometry.lonlat_bounds(poly, "quick") == approx( (-150, -30, 150, 30)) assert geometry.lonlat_bounds(poly, "safe") == approx((-150, -30, 150, 30))
def test_lonlat_bounds(): # example from landsat scene: spans lon=180 poly = geometry.box(618300, -1876800, 849000, -1642500, 'EPSG:32660') bb = geometry.lonlat_bounds(poly) assert bb.left < 180 < bb.right assert geometry.lonlat_bounds(poly) == geometry.lonlat_bounds(poly, resolution=1e+8) bb = geometry.lonlat_bounds(poly, mode='quick') assert bb.right - bb.left > 180 poly = geometry.box(1, -10, 2, 20, 'EPSG:4326') assert geometry.lonlat_bounds(poly) == poly.boundingbox with pytest.raises(ValueError): geometry.lonlat_bounds(geometry.box(0, 0, 1, 1, None)) multi = { "type": "MultiPolygon", "coordinates": [ [[[174, 52], [174, 53], [175, 53], [174, 52]]], [[[168, 54], [167, 55], [167, 54], [168, 54]]] ] } multi_geom = geometry.Geometry(multi, "epsg:4326") multi_geom_projected = multi_geom.to_crs('epsg:32659', math.inf) ll_bounds = geometry.lonlat_bounds(multi_geom) ll_bounds_projected = geometry.lonlat_bounds(multi_geom_projected) assert ll_bounds == approx(ll_bounds_projected)
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 test_lonlat_bounds(): # example from landsat scene: spans lon=180 poly = geometry.box(618300, -1876800, 849000, -1642500, 'EPSG:32660') bb = geometry.lonlat_bounds(poly) assert bb.left < 180 < bb.right assert geometry.lonlat_bounds(poly) == geometry.lonlat_bounds( poly, resolution=1e+8) bb = geometry.lonlat_bounds(poly, mode='quick') assert bb.right - bb.left > 180 poly = geometry.box(1, -10, 2, 20, 'EPSG:4326') assert geometry.lonlat_bounds(poly) == poly.boundingbox with pytest.raises(ValueError): geometry.lonlat_bounds(geometry.box(0, 0, 1, 1, None))