def test_nonearthbody(): """COGReader should work with non-earth dataset.""" with pytest.warns(UserWarning): with COGReader(COG_EUROPA) as cog: assert cog.minzoom == 0 assert cog.maxzoom == 24 with pytest.warns(None) as warnings: with COGReader(COG_EUROPA) as cog: assert cog.info() assert len(warnings) == 2 img = cog.read() assert numpy.array_equal(img.data, cog.dataset.read(indexes=(1, ))) assert img.width == cog.dataset.width assert img.height == cog.dataset.height assert img.count == cog.dataset.count img = cog.preview() assert img.bounds == cog.bounds part = cog.part(cog.bounds, bounds_crs=cog.crs) assert part.bounds == cog.bounds lon = (cog.bounds[0] + cog.bounds[2]) / 2 lat = (cog.bounds[1] + cog.bounds[3]) / 2 assert cog.point(lon, lat, coord_crs=cog.crs)[0] is not None europa_crs = CRS.from_authority("ESRI", 104915) tms = TileMatrixSet.custom( crs=europa_crs, extent=europa_crs.area_of_use.bounds, matrix_scale=[2, 1], ) with pytest.warns(None) as warnings: with COGReader(COG_EUROPA, tms=tms) as cog: assert cog.minzoom == 4 assert cog.maxzoom == 6 # Get Tile covering the UL corner bounds = transform_bounds(cog.crs, tms.rasterio_crs, *cog.bounds) t = tms._tile(bounds[0], bounds[1], cog.minzoom) img = cog.tile(t.x, t.y, t.z) assert img.height == 256 assert img.width == 256 assert img.crs == tms.rasterio_crs assert len(warnings) == 0
def test_nonearth_custom(): """Test Custom geographic_crs.""" MARS2000_SPHERE = CRS.from_proj4("+proj=longlat +R=3396190 +no_defs") MARS_MERCATOR = CRS.from_proj4( "+proj=merc +R=3396190 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +no_defs" ) mars_tms = TileMatrixSet.custom( [ -179.9999999999996, -85.05112877980656, 179.9999999999996, 85.05112877980656, ], MARS_MERCATOR, extent_crs=MARS2000_SPHERE, title="Web Mercator Mars", geographic_crs=MARS2000_SPHERE, ) @attr.s class MarsReader(COGReader): """Use custom geographic CRS.""" geographic_crs: rasterio.crs.CRS = attr.ib( init=False, default=rasterio.crs.CRS.from_proj4( "+proj=longlat +R=3396190 +no_defs"), ) with pytest.warns(None) as warnings: with MarsReader(COG_MARS, tms=mars_tms) as cog: assert cog.geographic_bounds[0] > -180 assert len(warnings) == 0 with pytest.warns(None) as warnings: with COGReader( COG_MARS, tms=mars_tms, geographic_crs=rasterio.crs.CRS.from_proj4( "+proj=longlat +R=3396190 +no_defs"), ) as cog: assert cog.geographic_bounds[0] > -180 assert len(warnings) == 0