How to use the sentinelhub.geometry.BBox function in sentinelhub

To help you get started, we’ve selected a few sentinelhub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sentinel-hub / sentinelhub-py / sentinelhub / areas.py View on Github external
def _make_split(self):
        """ This method makes the split
        """
        self.tile_dict = {}

        wfs = WebFeatureService(self.area_bbox, self.time_interval, data_source=self.data_source,
                                instance_id=self.instance_id)
        date_list = wfs.get_dates()
        geometry_list = wfs.get_geometries()
        for tile_info, (date, geometry) in zip(wfs, zip(date_list, geometry_list)):
            tile_name = ''.join(tile_info['properties']['path'].split('/')[4:7])
            if tile_name not in self.tile_dict:
                self.tile_dict[tile_name] = {'bbox': BBox(tile_info['properties']['mbr'],
                                                          crs=tile_info['properties']['crs']),
                                             'times': [],
                                             'geometries': []}
            self.tile_dict[tile_name]['times'].append(date)
            self.tile_dict[tile_name]['geometries'].append(geometry)

        self.tile_dict = {tile_name: tile_props for tile_name, tile_props in self.tile_dict.items() if
                          self._intersects_area(tile_props['bbox'])}

        self.bbox_list = []
        self.info_list = []

        for tile_name, tile_info in self.tile_dict.items():
            tile_bbox = tile_info['bbox']
            bbox_splitter = BBoxSplitter([tile_bbox.geometry], tile_bbox.crs,
                                         split_shape=self.tile_split_shape)
github sentinel-hub / sentinelhub-py / sentinelhub / areas.py View on Github external
def _align_bbox_to_size(self, bbox):
        """ Align input bbox coordinates to be multiples of the bbox size

        :param bbox: Bounding box in UTM coordinates
        :type bbox: sentinelhub.BBox
        :return: BBox objects with coordinates multiples of the bbox size
        :rtype: sentinelhub.BBox
        """
        size_x, size_y = self.bbox_size
        lower_left_x, lower_left_y = bbox.lower_left
        return BBox([(math.floor(lower_left_x / size_x) * size_x, math.floor(lower_left_y / size_y) * size_y),
                     bbox.upper_right], crs=bbox.crs)
github sentinel-hub / sentinelhub-py / sentinelhub / geometry.py View on Github external
def reverse(self):
        """ Returns a new BBox object where x and y coordinates are switched

        :return: New BBox object with switched coordinates
        :rtype: BBox
        """
        return BBox((self.min_y, self.min_x, self.max_y, self.max_x), crs=self.crs)
github sentinel-hub / sentinelhub-py / sentinelhub / areas.py View on Github external
def _reduce_sizes(self, bbox_list):
        """ Reduces sizes of bounding boxes
        """
        return [BBox(self._intersection_area(bbox).bounds, self.crs).transform(bbox.crs) for bbox in bbox_list]
github sentinel-hub / sentinelhub-py / sentinelhub / geometry.py View on Github external
:type num_y: int or None
        :param size_x: Physical dimension of BBox along easting coordinate
        :type size_x: float or None
        :param size_y: Physical dimension of BBox along northing coordinate
        :type size_y: float or None
        :return: Two-dimensional list of smaller bounding boxes. Their location is
        :rtype: list(list(BBox))
        """
        if (num_x is not None and num_y is not None) and (size_x is None and size_y is None):
            size_x, size_y = (self.max_x - self.min_x) / num_x, (self.max_y - self.min_y) / num_y
        elif (size_x is not None and size_y is not None) and (num_x is None and num_y is None):
            num_x, num_y = ceil((self.max_x - self.min_x) / size_x), ceil((self.max_y - self.min_y) / size_y)
        else:
            raise ValueError('Not supported partition. Either (num_x, num_y) or (size_x, size_y) must be specified')

        return [[BBox([self.min_x + i * size_x, self.min_y + j * size_y,
                       self.min_x + (i + 1) * size_x, self.min_y + (j + 1) * size_y],
                      crs=self.crs) for j in range(num_y)] for i in range(num_x)]
github sentinel-hub / sentinelhub-py / sentinelhub / areas.py View on Github external
def get_area_bbox(self, crs=None):
        """ Returns a bounding box of the entire area

        :param crs: Coordinate reference system in which the bounding box should be returned. If `None` the CRS will
            be the default CRS of the splitter.
        :type crs: CRS or None
        :return: A bounding box of the area defined by the `shape_list`
        :rtype: BBox
        """
        bbox_list = [BBox(shape.bounds, crs=self.crs) for shape in self.shape_list]
        area_minx = min([bbox.lower_left[0] for bbox in bbox_list])
        area_miny = min([bbox.lower_left[1] for bbox in bbox_list])
        area_maxx = max([bbox.upper_right[0] for bbox in bbox_list])
        area_maxy = max([bbox.upper_right[1] for bbox in bbox_list])
        bbox = BBox([area_minx, area_miny, area_maxx, area_maxy], crs=self.crs)
        if crs is None:
            return bbox
        return bbox.transform(crs)
github sentinel-hub / sentinelhub-py / sentinelhub / geometry.py View on Github external
def __init__(self, bbox, crs):
        """
        :param bbox: A bbox in any valid representation
        :param crs: Coordinate reference system of the bounding box
        :type crs: constants.CRS
        """
        x_fst, y_fst, x_snd, y_snd = BBox._to_tuple(bbox)
        self.min_x = min(x_fst, x_snd)
        self.max_x = max(x_fst, x_snd)
        self.min_y = min(y_fst, y_snd)
        self.max_y = max(y_fst, y_snd)

        super().__init__(crs)
github sentinel-hub / sentinelhub-py / sentinelhub / ogc.py View on Github external
:type request: OgcRequest or GeopediaRequest
        :param geometry: list of bounding boxes or geometries
        :type geometry: list of BBox or Geometry
        :return:  dictionary with parameters
        :rtype: dict
        """
        date_interval = parse_time_interval(request.time)

        params = {
            'CRS': CRS.ogc_string(geometry.crs),
            'LAYER': request.layer,
            'RESOLUTION': request.resolution,
            'TIME': '{}/{}'.format(date_interval[0], date_interval[1])
        }

        if not isinstance(geometry, (BBox, Geometry)):
            raise ValueError('Each geometry must be an instance of sentinelhub.{} or sentinelhub.{} but {} '
                             'found'.format(BBox.__name__, Geometry.__name__, geometry))
        if geometry.crs is CRS.WGS84:
            geometry = geometry.reverse()
        if isinstance(geometry, Geometry):
            params['GEOMETRY'] = geometry.wkt
        else:
            params['BBOX'] = str(geometry)

        if request.bins:
            params['BINS'] = request.bins

        if request.histogram_type:
            params['TYPE'] = request.histogram_type.value

        return params
github sentinel-hub / sentinelhub-py / sentinelhub / geometry.py View on Github external
def _parse_bbox_list(bbox_list):
        """ Helper method for parsing a list of bounding boxes
        """
        if isinstance(bbox_list, BBoxCollection):
            return bbox_list.bbox_list, bbox_list.crs

        if not isinstance(bbox_list, list) or not bbox_list:
            raise ValueError('Expected non-empty list of BBox objects')

        for bbox in bbox_list:
            if not isinstance(bbox, BBox):
                raise ValueError('Elements in the list should be of type {}, got {}'.format(BBox.__name__, type(bbox)))

        crs = bbox_list[0].crs
        for bbox in bbox_list:
            if bbox.crs is not crs:
                raise ValueError('All bounding boxes should have the same CRS')

        return bbox_list, crs