def test_search_group_geometry(self):
        import shapely.wkb
        r = requests.get(
            "https://raw.githubusercontent.com/johan/world.geo.json/master/countries/BEL.geo.json"
        )

        area_geom = r.json()
        area_shape = shapely.geometry.shape(
            area_geom['features'][0]['geometry'])

        d_start = date(2017, 1, 1)  # 2017-03-12
        d_end = date(2017, 5, 19)  # epl api is inclusive

        belgium_filter = LandsatQueryFilters()

        # PRE is a collection type that specifies certain QA standards
        # belgium_filter.collection_number.set_value("PRE")
        belgium_filter.cloud_cover.set_range(end=15, end_inclusive=False)
        belgium_filter.acquired.set_range(start=d_start, end=d_end)
        belgium_filter.aoi.set_geometry(area_shape.wkb)
        # belgium_filter.aoi.set_bounds(*area_shape.bounds)
        # search the satellite metadata for images of Belgium withing the given date range
        metadata_service = MetadataService()
        metadata_gen = metadata_service.search_layer_group(
            data_filters=belgium_filter, satellite_id=SpacecraftID.LANDSAT_8)
        unioned_beast = shapely.geometry.Polygon()
        for metadata in metadata_gen:
            wrs_polygon = metadata.get_wrs_polygon()
            wrs_shape = shapely.wkb.loads(wrs_polygon)
            unioned_beast = unioned_beast.union(wrs_shape)

        self.assertTrue(unioned_beast.contains(area_shape))

        belgium_filter.aoi.sort_by(epl_imagery_pb2.DESCENDING)
        metadata_gen = metadata_service.search_layer_group(
            data_filters=belgium_filter, satellite_id=SpacecraftID.LANDSAT_8)
        unioned_beast = shapely.geometry.Polygon()
        for metadata in metadata_gen:
            wrs_polygon = metadata.get_wrs_polygon()
            wrs_shape = shapely.wkb.loads(wrs_polygon)
            unioned_beast = unioned_beast.union(wrs_shape)

        self.assertTrue(unioned_beast.contains(area_shape))
    def test_salt_lake_city(self):
        utah_wkt = 'POLYGON((-114.049883347847 38.677365, -114.049749 38.72920999999999, -114.049168 38.749951, -114.049465 38.874949, -114.048521 38.876197, -114.048054 38.878693, -114.049104 39.005509, -114.047079 39.49994299999999, -114.047727981839 39.5427408023268, -113.815766 39.54409, -113.815743 39.552644, -112.923426 39.552539, -112.803046 39.552648, -112.629539 39.5524, -112.462419 39.552451, -112.462423 39.553704, -112.354467 39.553684, -112.235958 39.553625, -112.212045 39.553987, -112.212029 39.54773, -112.207353 39.54769599999999, -112.207346 39.54408, -112.202672 39.544048, -112.202666 39.540434, -112.193292 39.540451, -112.193242 39.526023, -112.211973 39.526042, -112.211961 39.511579, -112.207285 39.51156599999999, -112.2073 39.504334, -112.202633 39.504323, -112.202626 39.489858, -112.193277 39.48983399999999, -112.193596 39.37309, -112.188907 39.373089, -112.188922 39.329392, -112.137293 39.329397, -112.10962 39.329522, -112.072108 39.329695, -112.072218 39.314923, -112.053423 39.31494199999999, -112.053421 39.314483, -112.016003 39.314561, -112.01452 39.132617, -112.014083 39.045518, -112.014017 39.024282, -112.019034 39.024207, -112.018906 38.995902, -112.056387 38.99568, -112.056402 38.988368, -112.065661 38.98843, -112.06563 38.985359, -112.065591 38.981689, -112.065162 38.959302, -112.133862 38.959302, -112.134031 38.935453, -112.151928 38.935473, -112.150513 38.92005899999999, -112.15076 38.906509, -112.169351 38.906132, -112.169461 38.892104, -112.171554 38.878616, -112.18847 38.879447, -112.188541 38.864787, -112.199098 38.864982, -112.206093 38.865112, -112.224461 38.86480299999999, -112.224553 38.85556, -112.224637 38.837514, -112.228438 38.837508, -112.228381 38.763987, -112.219118 38.763987, -112.219116 38.751251, -112.21808 38.748987, -112.218147 38.740198, -112.218356 38.72736099999999, -112.23664 38.727104, -112.236685 38.723266, -112.236722 38.719859, -112.241362 38.719785, -112.24147 38.71252399999999, -112.255359 38.712306, -112.255438 38.705047, -112.273297 38.704999, -112.273255 38.701353, -112.28235 38.701527, -112.28226 38.686874, -112.291316 38.686961, -112.291329 38.683298, -112.30994 38.68340999999999, -112.309953 38.67629, -112.347179 38.676259, -112.356637 38.67674, -112.356539 38.683855, -112.365964 38.684218, -112.384245 38.68331, -112.401176 38.680972, -112.4198 38.681388, -112.447517 38.68127, -112.447667 38.67392299999999, -112.466001 38.673917, -112.466156 38.659267, -112.475341 38.659257, -112.475185 38.644675, -112.484444 38.644647, -112.484788 38.600632, -112.503074 38.600568, -112.503148 38.571377, -112.51239 38.571358, -112.515394 38.572845, -112.603479 38.572733, -112.752497 38.572681, -113.047215 38.572603, -113.115956 38.572663, -113.11686 38.572612, -113.189536 38.57273199999999, -113.191158 38.57261099999999, -114.05015385888 38.5729744583009, -114.049883347847 38.677365))'
        utah_shape = shapely.wkt.loads(utah_wkt)
        landsat_qf = LandsatQueryFilters()
        # cloud cover less than 30%
        landsat_qf.cloud_cover.set_range(end=30)
        landsat_qf.aoi.set_geometry(utah_shape.wkb)
        # sort by date, with most recent first
        landsat_qf.acquired.sort_by(epl_imagery_pb2.DESCENDING)

        metadata_servce = MetadataService()
        rows = metadata_servce.search_layer_group(data_filters=landsat_qf,
                                                  satellite_id=SpacecraftID.LANDSAT_8)
        self.assertIsNotNone(rows)
        metadata_set = list(rows)
        self.assertGreaterEqual(len(metadata_set), 1)