def test_fetch_img(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) extent = [-10, 10, 40, 60] located_image, = source.fetch_raster(self.projection, extent, RESOLUTION) img = np.array(located_image.image) assert img.shape == (512, 512, 4) # No transparency in this image. assert img[:, :, 3].min() == 255 assert located_image.extent == (-180.0, 107.99999999999994, -197.99999999999994, 90.0)
def test_fetch_img_reprojected(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) extent = [-20, -1, 48, 50] # NB single result in this case. located_image, = source.fetch_raster(ccrs.NorthPolarStereo(), extent, (30, 30)) # Check image array is as expected (more or less). img = np.array(located_image.image) assert img.shape == (42, 42, 4) # When reprojected, extent is exactly what you asked for. assert located_image.extent == extent
def test_fetch_img(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) extent = [-10, 10, 40, 60] img, extent_out = source.fetch_raster(self.projection, extent, (30, 30)) img = np.array(img) self.assertEqual(img.shape, (512, 512, 4)) # No transparency in this image. self.assertEqual(img[:, :, 3].min(), 255) self.assertEqual( (-180.0, 107.99999999999994, -197.99999999999994, 90.0), extent_out)
def test_fetch_img_reprojected_twoparts(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) extent = [-10, 12, 48, 50] images = source.fetch_raster(ccrs.NorthPolarStereo(), extent, (30, 30)) # Check for 2 results in this case. assert len(images) == 2 im1, im2 = images # Check image arrays is as expected (more or less). assert np.array(im1.image).shape == (42, 42, 4) assert np.array(im2.image).shape == (42, 42, 4) # When reprojected, extent is exactly what you asked for. assert im1.extent == extent assert im2.extent == extent
def test_unsupported_projection(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) msg = 'Unable to find tile matrix for projection.' with self.assertRaisesRegexp(ValueError, msg): source.validate_projection(ccrs.Miller())
def test_supported_projection(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) source.validate_projection(self.projection)
def test_wmts_service_instance(self): service = WebMapTileService(self.URI) source = ogc.WMTSRasterSource(service, self.layer_name) self.assertIs(source.wmts, service)
def test_string_service(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) self.assertIsInstance(source.wmts, WebMapTileService) self.assertIsInstance(source.layer, ContentMetadata) self.assertEqual(source.layer.name, self.layer_name)
def test_unsupported_projection(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) with mock.patch('cartopy.io.ogc_clients._URN_TO_CRS', {}): match = r'Unable to find tile matrix for projection\.' with pytest.raises(ValueError, match=match): source.validate_projection(ccrs.Miller())
def test_non_native_projection(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) source.validate_projection(ccrs.Miller())
def test_string_service(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) assert isinstance(source.wmts, WebMapTileService) assert isinstance(source.layer, ContentMetadata) assert source.layer.name == self.layer_name
def test_unsupported_projection(self): source = ogc.WMTSRasterSource(self.URI, self.layer_name) with mock.patch('cartopy.io.ogc_clients._URN_TO_CRS', {}): msg = 'Unable to find tile matrix for projection.' with self.assertRaisesRegexp(ValueError, msg): source.validate_projection(ccrs.Miller())