def test_scene_search(self): expected = """{"datasetName": "GLS2005", "maxResults": 3, "metadata_type": null, "sceneFilter": {"acquisitionFilter": {"start": "2006-01-01T00:00:00Z", "end": "2007-12-01T00:00:00Z"}, "spatialFilter": {"filterType": "mbr", "lowerLeft": {"longitude": -135, "latitude": 75}, "upperRight": {"longitude": -120, "latitude": 90}}}}""" ll = {"longitude": -135, "latitude": 75} ur = {"longitude": -120, "latitude": 90} start_date = "2006-01-01T00:00:00Z" end_date = "2007-12-01T00:00:00Z" payload = payloads.scene_search( "GLS2005", ll=ll, ur=ur, start_date=start_date, end_date=end_date, max_results=3) assert compare_json(payload, expected)
def test_scene_search_radial_distance(self): expected = """{"datasetName": "GLS2005", "maxResults": 3, "metadata_type": null, "sceneFilter": {"acquisitionFilter": {"start": "2006-01-01T00:00:00Z", "end": "2007-12-01T00:00:00Z"}, "spatialFilter": {"filterType": "mbr", "lowerLeft": {"longitude": -125.01823502237109, "latitude": 84.99840995696343}, "upperRight": {"longitude": -124.98175340746137, "latitude": 85.00158953883317}}}}""" lat = 85 lng = -125 dist = 1000 start_date = "2006-01-01T00:00:00Z" end_date = "2007-12-01T00:00:00Z" payload = payloads.scene_search( "GLS2005", lat=lat, lng=lng, distance=dist, start_date=start_date, end_date=end_date, max_results=3) assert compare_json(payload, expected), "wrong result: {r} \n for expected: {e}".format(r=payload, e=expected)
def scene_search(dataset, max_results=5000, metadata_type=None, start_date=None, end_date=None, ll=None, ur=None, lat=None, lng=None, distance=100, where=None, starting_number=1, sort_order="DESC", api_key=None): """ :param dataset: USGS dataset (e.g. EO1_HYP_PUB, LANDSAT_8) :param lat: Latitude :param lng: Longitude :param distance: Distance in meters used to for a radial search :param ll: Dictionary of longitude/latitude coordinates for the lower left corner of a bounding box search. e.g. { "longitude": 0.0, "latitude": 0.0 } :param ur: Dictionary of longitude/latitude coordinates for the upper right corner of a bounding box search. e.g. { "longitude": 0.0, "latitude": 0.0 } :param start_date: Start date for when a scene has been acquired :param end_date: End date for when a scene has been acquired :where: Dictionary representing key/values for finer grained conditional queries. Only a subset of metadata fields are supported. Available fields depend on the value of `dataset`, and maybe be found by submitting a dataset_filters query. :max_results: Maximum results returned by the server :starting_number: Starting offset for results of a query. :sort_order: Order in which results are sorted. Ascending or descending w.r.t the acquisition date. :api_key: API key for EROS. Required for searching. """ api_key = _get_api_key(api_key) session = _create_session(api_key) url = '{}/scene-search'.format(USGS_API) payload = payloads.scene_search(dataset, max_results=max_results, metadata_type=metadata_type, start_date=start_date, end_date=end_date, ll=ll, ur=ur, lat=lat, lng=lng, distance=distance, where=where, starting_number=starting_number) r = session.post(url, payload) response = r.json() _check_for_usgs_error(response) return response