How to use sentinelhub - 10 common examples

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 / tests / test_data_request.py View on Github external
def test_init(self):

        bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
        data_request = WcsRequest(data_folder=self.OUTPUT_FOLDER, bbox=bbox, layer='BANDS-S2-L1C')
        data_request.create_request(reset_wfs_iterator=True)  # This method is used by s2cloudless, don't rename it

        self.assertEqual(self.OUTPUT_FOLDER, data_request.data_folder,
                         msg="Expected {}, got {}".format(self.OUTPUT_FOLDER, data_request.data_folder))
        self.assertTrue(isinstance(data_request.get_filename_list(), list), "Expected a list")
        self.assertTrue(isinstance(data_request.get_url_list(), list), "Expected a list")
        self.assertTrue(data_request.is_valid_request(), "Request should be valid")
github sentinel-hub / sentinelhub-py / tests / test_data_request.py View on Github external
class TestDataRequest(TestSentinelHub):
    def test_init(self):

        bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
        data_request = WcsRequest(data_folder=self.OUTPUT_FOLDER, bbox=bbox, layer='BANDS-S2-L1C')
        data_request.create_request(reset_wfs_iterator=True)  # This method is used by s2cloudless, don't rename it

        self.assertEqual(self.OUTPUT_FOLDER, data_request.data_folder,
                         msg="Expected {}, got {}".format(self.OUTPUT_FOLDER, data_request.data_folder))
        self.assertTrue(isinstance(data_request.get_filename_list(), list), "Expected a list")
        self.assertTrue(isinstance(data_request.get_url_list(), list), "Expected a list")
        self.assertTrue(data_request.is_valid_request(), "Request should be valid")


class TestDataRequestSaving(TestSentinelHub):

    @classmethod
    def setUpClass(cls):
        super().setUpClass()

        cls.product_id = 'S2A_MSIL1C_20180113T001101_N0206_R073_T55KGP_20180113T013328.SAFE'
        metafiles = 'inspire '
        cls.request_without_folder = AwsProductRequest(bands='', metafiles=metafiles, safe_format=True,
                                                       product_id=cls.product_id)
        cls.request_with_folder = AwsProductRequest(data_folder=cls.OUTPUT_FOLDER, bands='', metafiles=metafiles,
                                                    safe_format=True, product_id=cls.product_id)

    def test_saving_responses(self):
        try:
            data = self.request_without_folder.get_data()
            self.assertTrue(isinstance(data, list), "Expected a list")
github sentinel-hub / sentinelhub-py / tests / test_data_request.py View on Github external
import unittest
import os

from sentinelhub import WcsRequest, AwsProductRequest, BBox, CRS, get_file_list, get_folder_list, TestSentinelHub


class TestDataRequest(TestSentinelHub):
    def test_init(self):

        bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
        data_request = WcsRequest(data_folder=self.OUTPUT_FOLDER, bbox=bbox, layer='BANDS-S2-L1C')
        data_request.create_request(reset_wfs_iterator=True)  # This method is used by s2cloudless, don't rename it

        self.assertEqual(self.OUTPUT_FOLDER, data_request.data_folder,
                         msg="Expected {}, got {}".format(self.OUTPUT_FOLDER, data_request.data_folder))
        self.assertTrue(isinstance(data_request.get_filename_list(), list), "Expected a list")
        self.assertTrue(isinstance(data_request.get_url_list(), list), "Expected a list")
        self.assertTrue(data_request.is_valid_request(), "Request should be valid")


class TestDataRequestSaving(TestSentinelHub):

    @classmethod
github sentinel-hub / sentinelhub-py / tests / test_ogc.py View on Github external
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,
github sentinel-hub / sentinelhub-py / tests / test_geopedia.py View on Github external
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)
        ]
github sentinel-hub / sentinelhub-py / tests / test_geometry.py View on Github external
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)
github sentinel-hub / sentinelhub-py / tests / test_geometry.py View on Github external
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)
github sentinel-hub / sentinelhub-py / tests / test_geometry.py View on Github external
def setUpClass(cls):
        super().setUpClass()

        polygon = shapely.geometry.Polygon([(465888.8773268595, 5079639.43613863),
                                            (465885.3413983975, 5079641.52461826),
                                            (465882.9542217017, 5079647.16604353),
                                            (465888.8780175466, 5079668.70367663),
                                            (465888.877326859, 5079639.436138632)])
        cls.wkt_string = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), ' \
                         '(30 20, 20 15, 20 25, 30 20)))'
        cls.geometry1 = Geometry(polygon, CRS(32633))
        cls.geometry2 = Geometry(cls.wkt_string, CRS.WGS84)
        cls.bbox = BBox(bbox=[14.00, 45.00, 14.03, 45.03], crs=CRS.WGS84)
        cls.bbox_collection = BBoxCollection([cls.bbox, BBox('46,13,47,20', CRS.WGS84)])

        cls.geometry_list = [cls.geometry1, cls.geometry2, cls.bbox, cls.bbox_collection]
github sentinel-hub / sentinelhub-py / tests / test_geopedia.py View on Github external
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()
github sentinel-hub / sentinelhub-py / tests / test_geometry.py View on Github external
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')