Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def test_bbox_from_flat_list(self):
     for bbox_lst in [[46.07, 13.23, 46.24, 13.57], [46.24, 13.23, 46.07, 13.57],
                      [46.07, 13.57, 46.24, 13.23], [46.24, 13.57, 46.07, 13.23]]:
         with self.subTest(msg="bbox={}".format(bbox_lst)):
             bbox = BBox(bbox_lst, CRS.WGS84)
             self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
             self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
             self.assertEqual(bbox.get_crs(), CRS.WGS84)
Exemplo n.º 3
0
def new_coordinates(data, crs, new_crs):
    """ Returns coordinates for xarray DataArray/Dataset in new crs.

    :param data: data for converting coordinates for
    :type data: xarray.DataArray or xarray.Dataset
    :param crs: old crs
    :type crs: sentinelhub.CRS
    :param new_crs: new crs
    :type new_crs: sentinelhub.CRS
    :return: new x and y coordinates
    :rtype: (float, float)
    """
    x_values = data.coords['x'].values
    y_values = data.coords['y'].values
    bbox = BBox((x_values[0], y_values[0], x_values[-1], y_values[-1]),
                crs=crs)
    bbox = bbox.transform(new_crs)
    xmin, ymin = bbox.get_lower_left()
    xmax, ymax = bbox.get_upper_right()
    new_xs = np.linspace(xmin, xmax, len(x_values))
    new_ys = np.linspace(ymin, ymax, len(y_values))

    return new_xs, new_ys
Exemplo n.º 4
0
 def test_bbox_from_list_tuple_combo(self):
     bbox_list = [(46.07, 13.23), (46.24, 13.57)]
     bbox = BBox(bbox_list, 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)
Exemplo n.º 5
0
 def test_bbox_from_nested_tuple(self):
     bbox_tup = (46.07, 13.23), (46.24, 13.57)
     bbox = BBox(bbox_tup, 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)
Exemplo n.º 6
0
 def test_bbox_from_nested_list(self):
     bbox_lst = [[-46.07, -13.23], [46.24, 13.57]]
     bbox = BBox(bbox_lst, 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)
Exemplo n.º 7
0
 def test_bbox_from_string(self):
     bbox_str = '46.07, 13.23, 46.24, 13.57'
     bbox = BBox(bbox_str, CRS.WGS84)
     self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
     self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
     self.assertEqual(bbox.get_crs(), CRS.WGS84)