Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUpClass(cls):
super().setUpClass()
wgs84_bbox = BBox(bbox=(-5.23, 48.0, -5.03, 48.17), crs=CRS.WGS84)
wgs84_bbox_2 = BBox(bbox=(21.3, 64.0, 22.0, 64.5), crs=CRS.WGS84)
wgs84_bbox_3 = BBox(bbox=(-72.0, -70.4, -71.8, -70.2), crs=CRS.WGS84)
wgs84_bbox_4 = BBox(bbox=(-72.0, -66.4, -71.8, -66.2), crs=CRS.WGS84)
pop_web_bbox = BBox(bbox=(1292344.0, 5195920.0, 1310615.0, 5214191.0), crs=CRS.POP_WEB)
geometry_wkt_pop_web = 'POLYGON((1292344.0 5205055.5, 1301479.5 5195920.0, 1310615.0 5205055.5, ' \
'1301479.5 5214191.0, 1292344.0 5205055.5))'
geometry_wkt_wgs84 = 'POLYGON((-5.13 48, -5.23 48.09, -5.13 48.17, -5.03 48.08, -5.13 48))'
img_width = 100
img_height = 100
resx = '53m'
resy = '78m'
expected_date = datetime.datetime.strptime('2017-10-07T11:20:58', '%Y-%m-%dT%H:%M:%S')
cls.test_cases = [
cls.OgcTestCase('generalWmsTest',
OgcRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.TIFF_d32f, bbox=wgs84_bbox,
def setUpClass(cls):
super().setUpClass()
bbox = BBox(bbox=[(2947363, 4629723), (3007595, 4669471)], crs=CRS.POP_WEB)
bbox = bbox.transform(CRS.WGS84)
query_filter1 = 'f12458==32632'
query_filter2 = 'f12458==32635'
cls.test_cases = [
TestCaseContainer('All features', GeopediaFeatureIterator(1749), min_features=100, min_size=1609),
TestCaseContainer('BBox filter', GeopediaFeatureIterator('1749', bbox=bbox), min_features=21),
TestCaseContainer('Query Filter', GeopediaFeatureIterator('ttl1749', query_filter=query_filter1),
min_features=76),
TestCaseContainer('Both filters - No data',
GeopediaFeatureIterator(1749, bbox=bbox, query_filter=query_filter1), min_features=0),
TestCaseContainer('Both filters - Some data',
GeopediaFeatureIterator(1749, bbox=bbox, query_filter=query_filter2), min_features=21)
]
def test_bbox_from_bad_string(self):
with self.subTest(msg="Too few coordinates"):
bbox_str = '46.07, 13.23, 46.24'
with self.assertRaises(ValueError):
BBox(bbox_str, CRS.WGS84)
with self.subTest(msg="Invalid string"):
bbox_str = '46N,13E,45N,12E'
with self.assertRaises(ValueError):
BBox(bbox_str, CRS.WGS84)
def test_bbox_from_bbox(self):
bbox_dict = {'min_x': 46.07, 'min_y': 13.23, 'max_x': 46.24, 'max_y': 13.57}
bbox_fst = BBox(bbox_dict, CRS.WGS84)
bbox = BBox(bbox_fst, CRS.WGS84)
self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
self.assertEqual(bbox.get_crs(), CRS.WGS84)
def setUpClass(cls):
super().setUpClass()
bbox = BBox(bbox=[(524358.0140363087, 6964349.630376049),
(534141.9536568124, 6974133.5699965535)], crs=CRS.POP_WEB)
gpd_request = GeopediaWmsRequest(layer=1917, theme='ml_aws', bbox=bbox, width=50, height=50,
image_format=MimeType.PNG)
cls.data = gpd_request.get_data()
def test_bbox(self):
for geometry in [self.geometry1, self.geometry2, self.bbox_collection]:
self.assertEqual(geometry.bbox, BBox(geometry.geometry, geometry.crs), 'Failed bbox property')
def _parse_feature_type_value(feature_type, value):
""" Checks or parses value which will be assigned to a feature type attribute of `EOPatch`. If the value
cannot be parsed correctly it raises an error.
:raises: TypeError, ValueError
"""
if feature_type.has_dict() and isinstance(value, dict):
return value if isinstance(value, _FeatureDict) else _FeatureDict(value, feature_type)
if feature_type is FeatureType.BBOX:
if value is None or isinstance(value, sentinelhub.BBox):
return value
if isinstance(value, (tuple, list)) and len(value) == 5:
return sentinelhub.BBox(value[:4], crs=value[4])
if feature_type is FeatureType.TIMESTAMP:
if isinstance(value, (tuple, list)):
return [timestamp if isinstance(timestamp, datetime.date) else dateutil.parser.parse(timestamp)
for timestamp in value]
raise TypeError('Attribute {} requires value of type {} - '
'failed to parse given value'.format(feature_type, feature_type.type()))
def type(self):
"""Returns type of the data for the given FeatureType."""
if self is FeatureType.TIMESTAMP:
return list
if self is FeatureType.BBOX:
return BBox
return dict