Esempio n. 1
0
 def test_get_geometry_from_various_geometry_and_locations(self):
     """The search geometry can be set from a given geometry and a locations config file query"""
     geometry = {
         "lonmin": 20,
         "latmin": 50,
         "lonmax": 22,
         "latmax": 52,
     }
     locations_config = self.dag.locations_config
     geom_combined = get_geometry_from_various(
         locations_config, locations=dict(country="FRA"), geometry=geometry)
     self.assertIsInstance(geom_combined, MultiPolygon)
     # France + Guyana + Corsica + somewhere over Poland
     self.assertEquals(len(geom_combined), 4)
     geometry = {
         "lonmin": 0,
         "latmin": 50,
         "lonmax": 2,
         "latmax": 52,
     }
     geom_combined = get_geometry_from_various(
         locations_config, locations=dict(country="FRA"), geometry=geometry)
     self.assertIsInstance(geom_combined, MultiPolygon)
     # The bounding box overlaps with France inland
     self.assertEquals(len(geom_combined), 3)
Esempio n. 2
0
 def test_get_geometry_from_various_locations_no_match_raises_error(self):
     """If the location search doesn't match any of the feature attribute a ValueError must be raised"""
     locations_config = self.dag.locations_config
     with self.assertRaisesRegex(ValueError,
                                 "country.*regexmatchingnothing"):
         get_geometry_from_various(
             locations_config,
             locations=dict(country="regexmatchingnothing"))
Esempio n. 3
0
 def test_get_geometry_from_various_locations_with_wrong_location_name_in_locations_dict(
     self, ):
     """If the location search has a wrong location name then a ValueError must be raised"""
     locations_config = self.dag.locations_config
     # Bad location name in kwargs
     # 'country' is the expected name here, but kwargs are passed
     # to get_geometry_from_various so we can't detect a bad location name
     with self.assertRaisesRegex(ValueError, "bad_query_arg"):
         get_geometry_from_various(locations_config,
                                   locations=dict(bad_query_arg="FRA"))
Esempio n. 4
0
 def test_get_geometry_from_various_only_locations(self):
     """The search geometry can be set from a locations config file query"""
     locations_config = self.dag.locations_config
     # No query args
     self.assertIsNone(get_geometry_from_various(locations_config))
     # France
     geom_france = get_geometry_from_various(locations_config,
                                             locations=dict(country="FRA"))
     self.assertIsInstance(geom_france, MultiPolygon)
     self.assertEquals(len(geom_france), 3)  # France + Guyana + Corsica
Esempio n. 5
0
 def test_get_geometry_from_various_only_locations_regex(self):
     """The search geometry can be set from a locations config file query and a regex"""
     locations_config = self.dag.locations_config
     # Pakistan + Panama (each has a unique polygon) => Multypolygon of len 2
     geom_regex_pa = get_geometry_from_various(
         locations_config, locations=dict(country="PA[A-Z]"))
     self.assertIsInstance(geom_regex_pa, MultiPolygon)
     self.assertEquals(len(geom_regex_pa), 2)
Esempio n. 6
0
 def test_get_geometry_from_various_no_locations(self):
     """The search geometry can be set from a dict, list, tuple, WKT string or shapely geom"""
     ref_geom_as_wkt = "POLYGON ((0 50, 0 52, 2 52, 2 50, 0 50))"
     ref_geom = wkt.loads(ref_geom_as_wkt)
     # Good dict
     geometry = {
         "lonmin": 0,
         "latmin": 50,
         "lonmax": 2,
         "latmax": 52,
     }
     self.assertEquals(get_geometry_from_various([], geometry=geometry),
                       ref_geom)
     # Bad dict with a missing key
     del geometry["lonmin"]
     self.assertRaises(
         TypeError,
         get_geometry_from_various,
         [],
         geometry=geometry,
     )
     # Tuple
     geometry = (0, 50, 2, 52)
     self.assertEquals(get_geometry_from_various([], geometry=geometry),
                       ref_geom)
     # List
     geometry = list(geometry)
     self.assertEquals(get_geometry_from_various([], geometry=geometry),
                       ref_geom)
     # List without 4 items
     geometry.pop()
     self.assertRaises(
         TypeError,
         get_geometry_from_various,
         [],
         geometry=geometry,
     )
     # WKT
     geometry = ref_geom_as_wkt
     self.assertEquals(get_geometry_from_various([], geometry=geometry),
                       ref_geom)
     # Some other shapely geom
     geometry = LineString([[0, 0], [1, 1]])
     self.assertIsInstance(get_geometry_from_various([], geometry=geometry),
                           LineString)
Esempio n. 7
0
 def test_get_geometry_from_various_locations_with_wrong_location_name_in_kwargs(
     self, ):
     """The search geometry is world wide if the location name is wrong"""
     locations_config = self.dag.locations_config
     # Bad location name in kwargs
     # 'country' is the expected name here, but kwargs are passed
     # to get_geometry_from_various so we can't detect a bad location name
     self.assertIsNone(
         get_geometry_from_various(locations_config, bad_query_arg="FRA"))
Esempio n. 8
0
 def test_get_geometry_from_various_only_locations(self):
     """The search geometry can be set from a locations config file query"""
     locations_config = self.dag.locations_config
     # No query args
     self.assertIsNone(get_geometry_from_various(locations_config))
     # Bad query arg
     # 'country' is the expected name here
     self.assertIsNone(
         get_geometry_from_various(locations_config, bad_query_arg="dummy"))
     # France
     geom_france = get_geometry_from_various(locations_config,
                                             country="FRA")
     self.assertIsInstance(geom_france, MultiPolygon)
     self.assertEquals(len(geom_france), 3)  # France + Guyana + Corsica
     # Not defined
     self.assertIsNone(
         get_geometry_from_various(locations_config,
                                   country="bad_query_value"))