Example #1
0
    def test_GIVEN_two_entry_for_envelope_THEN_bounding_box_is_that_entry(
            self):
        gen = GeoJSONGenerator(latitudes=[1.0, 3.0], longitudes=[2.0, 5.0])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.0, 3.0, 2.0, 5.0)
Example #2
0
    def test_GIVEN_two_entry_for_envelope_with_lats_and_lons_in_reverse_order_THEN_bounding_box_is_lons_in_same_order_lats_in_other_order(
            self):
        gen = GeoJSONGenerator(latitudes=[3.0, 1.0], longitudes=[5.0, 2.0])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.0, 3.0, 5.0, 2.0)
Example #3
0
    def test_GIVEN_three_entry_for_envelope_with_lats_and_lons_in_any_order_on_front_of_globe_THEN_bounding_box_is_min_to_max(
            self):
        gen = GeoJSONGenerator(latitudes=[3.1, 5.1, 1.1],
                               longitudes=[5.0, 1.0, 2.0])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.1, 5.1, 1.0, 5.0)
Example #4
0
    def test_GIVEN_three_equispaced_entries_for_envelope_with_lats_and_lons_in_any_order_on_back_of_globe_THEN_bounding_box_is_on_front_of_globe(
            self):
        gen = GeoJSONGenerator(latitudes=[3.1, 5.1, 1.1],
                               longitudes=[0, 120, -120])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.1, 5.1, -120, 120)
Example #5
0
    def test_GIVEN_masked_entries_for_lats_and_lons_in_any_order_on_back_of_globe_THEN_masked_enties_ignored(self):
        latitudes = ma.masked_array([3.1, 5.1, 1.1], [False, True, False])
        longitudes = ma.masked_array([0, 120,  -120], [False, False, True])
        gen = GeoJSONGenerator(latitudes=latitudes, longitudes=longitudes)

        box = gen._gen_envelope()

        # @charlienewey: Changed this test because masked entries are now not
        # used in generating bounding boxes
        # self.assert_type_and_coords(box, False, 1.1, 3.1, 0, 120)
        self.assert_type_and_coords(box, False, 3.1, 3.1, 0, 0)
Example #6
0
    def test_GIVEN_masked_entries_for_lats_and_lons_in_any_order_on_back_of_globe_THEN_masked_enties_ignored(
            self):
        latitudes = ma.masked_array([3.1, 5.1, 1.1], [False, True, False])
        longitudes = ma.masked_array([0, 120, -120], [False, False, True])
        gen = GeoJSONGenerator(latitudes=latitudes, longitudes=longitudes)

        box = gen._gen_envelope()

        # @charlienewey: Changed this test because masked entries are now not
        # used in generating bounding boxes
        # self.assert_type_and_coords(box, False, 1.1, 3.1, 0, 120)
        self.assert_type_and_coords(box, False, 3.1, 3.1, 0, 0)
Example #7
0
 def _add_region_to_query_filter(self, latitudes, longitudes, from_file):
     """
     Add a region query to the filter
     :param latitudes: the list of latitudes
     :param longitudes: the list of longitudes
     :param from_file: whether query was from a file (if so a polygon is created not just an envelope)
     :return: nothing
     """
     generator = GeoJSONGenerator(latitudes, longitudes)
     if from_file:
         bbox = generator._gen_bbox()
     else:
         bbox = generator._gen_envelope()
     if bbox is None:
         raise ValueError("No bounding box generated when reading the file.")
     constraint = {
         "geo_shape": {
             "eufar.spatial.geometries.bbox": {
                 "shape": bbox
             }
         }
     }
     self._add_to_query_filter("must", constraint)
Example #8
0
 def _add_region_to_query_filter(self, latitudes, longitudes, from_file):
     """
     Add a region query to the filter
     :param latitudes: the list of latitudes
     :param longitudes: the list of longitudes
     :param from_file: whether query was from a file (if so a polygon is created not just an envelope)
     :return: nothing
     """
     generator = GeoJSONGenerator(latitudes, longitudes)
     if from_file:
         bbox = generator._gen_bbox()
     else:
         bbox = generator._gen_envelope()
     if bbox is None:
         raise ValueError(
             "No bounding box generated when reading the file.")
     constraint = {
         "geo_shape": {
             "eufar.spatial.geometries.bbox": {
                 "shape": bbox
             }
         }
     }
     self._add_to_query_filter("must", constraint)
Example #9
0
    def test_GIVEN_three_equispaced_entries_for_envelope_with_lats_and_lons_in_any_order_on_back_of_globe_THEN_bounding_box_is_on_front_of_globe(self):
        gen = GeoJSONGenerator(latitudes=[3.1, 5.1, 1.1], longitudes=[0, 120,  -120])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.1, 5.1, -120, 120)
Example #10
0
    def test_GIVEN_three_entry_for_envelope_with_lats_and_lons_in_any_order_on_back_of_globe_THEN_bounding_box_is_min_to_max(self):
        gen = GeoJSONGenerator(latitudes=[3.1, 5.1, 1.1], longitudes=[-160, -170,  170])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.1, 5.1, 170, -160)
Example #11
0
    def test_GIVEN_two_entry_for_envelope_with_lats_and_lons_in_reverse_order_THEN_bounding_box_is_lons_in_same_order_lats_in_other_order(self):
        gen = GeoJSONGenerator(latitudes=[3.0, 1.0], longitudes=[5.0, 2.0])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.0, 3.0, 5.0, 2.0)
Example #12
0
    def test_GIVEN_two_entry_for_envelope_THEN_bounding_box_is_that_entry(self):
        gen = GeoJSONGenerator(latitudes=[1.0, 3.0], longitudes=[2.0, 5.0])

        box = gen._gen_envelope()

        self.assert_type_and_coords(box, False, 1.0, 3.0, 2.0, 5.0)