def test_search2(self): expected = """{"node": "EE", "datasetName": "GLS2005", "apiKey": "USERS API KEY", "spatialFilter": {"upperRight": {"latitude": 85.00158953883317, "longitude": -124.98175340746137}, "lowerLeft": {"latitude": 84.99840995696343, "longitude": -125.01823502237109}, "filterType": "mbr"}, "maxResults": 3, "startingNumber": 1, "sortOrder": "ASC", "temporalFilter": {"dateField": "search_date", "endDate": "2007-12-01T00:00:00Z", "startDate": "2006-01-01T00:00:00Z"}}""" lat = 85 lng = -125 dist = 1000 start_date = "2006-01-01T00:00:00Z" end_date = "2007-12-01T00:00:00Z" payload = payloads.search("GLS2005", "EE", lat=lat, lng=lng, distance=dist, start_date=start_date, end_date=end_date, max_results=3, sort_order="ASC", api_key="USERS API KEY") assert compare_json( payload, expected), "wrong result: {r} \n for expected: {e}".format( r=payload, e=expected)
def test_search(self): expected = """{"node": "EE", "datasetName": "GLS2005", "apiKey": "USERS API KEY", "spatialFilter": {"upperRight": {"latitude": 90, "longitude": -120}, "lowerLeft": {"latitude": 75, "longitude": -135}, "filterType": "mbr"}, "maxResults": 3, "startingNumber": 1, "sortOrder": "ASC", "temporalFilter": {"dateField": "search_date", "endDate": "2007-12-01T00:00:00Z", "startDate": "2006-01-01T00:00:00Z"}}""" 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.search("GLS2005", "EE", ll=ll, ur=ur, start_date=start_date, end_date=end_date, max_results=3, sort_order="ASC", api_key="USERS API KEY") assert compare_json(payload, expected)
def test_search2(self): expected = """{"node": "EE", "datasetName": "GLS2005", "apiKey": "USERS API KEY", "spatialFilter": {"upperRight": {"latitude": 85.00158953883317, "longitude": -124.98175340746137}, "lowerLeft": {"latitude": 84.99840995696343, "longitude": -125.01823502237109}, "filterType": "mbr"}, "maxResults": 3, "startingNumber": 1, "sortOrder": "ASC", "temporalFilter": {"dateField": "search_date", "endDate": "2007-12-01T00:00:00Z", "startDate": "2006-01-01T00:00:00Z"}}""" lat = 85 lng = -125 dist = 1000 start_date = "2006-01-01T00:00:00Z" end_date = "2007-12-01T00:00:00Z" payload = payloads.search("GLS2005", "EE", lat=lat, lng=lng, distance=dist, start_date=start_date, end_date=end_date, max_results=3, sort_order="ASC", api_key="USERS API KEY") assert compare_json(payload, expected), "wrong result: {r} \n for expected: {e}".format(r=payload, e=expected)
def test_search(self): expected = """{"node": "EE", "startDate": "2006-01-01T00:00:00Z", "datasetName": "GLS2005", "apiKey": "USERS API KEY", "endDate": "2007-12-01T00:00:00Z", "upperRight": {"latitude": 90, "longitude": -120}, "maxResults": 3, "startingNumber": 1, "sortOrder": "ASC", "lowerLeft": {"latitude": 75, "longitude": -135}}""" 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.search("GLS2005", "EE", ll=ll, ur=ur, start_date=start_date, end_date=end_date, max_results=3, sort_order="ASC", api_key="USERS API KEY") assert compare_json(payload, expected)
def search(dataset, node, lat=None, lng=None, distance=100, ll=None, ur=None, start_date=None, end_date=None, where=None, max_results=50000, starting_number=1, sort_order="DESC", extended=False, api_key=None): """ :param dataset: USGS dataset (e.g. EO1_HYP_PUB, LANDSAT_8) :param node: USGS node representing a dataset catalog (e.g. CWIC, EE, HDDS, LPVS) :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_fields 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. :extended: Boolean flag. When true a subsequent query will be sent to the `metadataUrl` returned by the first query. :api_key: API key for EROS. Required for searching. """ api_key = _get_api_key(api_key) url = '{}/search'.format(USGS_API) payload = { "jsonRequest": payloads.search(dataset, node, lat=lat, lng=lng, distance=100, ll=ll, ur=ur, start_date=start_date, end_date=end_date, where=where, max_results=max_results, starting_number=starting_number, sort_order=sort_order, api_key=api_key) } r = requests.get(url, payload) response = r.json() _check_for_usgs_error(response) if extended: metadata_urls = map(_get_metadata_url, response['data']['results']) results = _async_requests(metadata_urls) data = map( lambda idx: _get_extended(response['data']['results'][idx], results[idx]), range(len(response['data']['results']))) return response
def search(dataset, node, lat=None, lng=None, distance=100, ll=None, ur=None, start_date=None, end_date=None, where=None, max_results=50000, starting_number=1, sort_order="DESC", extended=False, api_key=None): """ :param dataset: USGS dataset (e.g. EO1_HYP_PUB, LANDSAT_8) :param node: USGS node representing a dataset catalog (e.g. CWIC, EE, HDDS, LPVS) :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_fields 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. :extended: Boolean flag. When true a subsequent query will be sent to the `metadataUrl` returned by the first query. :api_key: API key for EROS. Required for searching. """ api_key = _get_api_key(api_key) url = '{}/search'.format(USGS_API) payload = { "jsonRequest": payloads.search(dataset, node, lat=lat, lng=lng, distance=100, ll=ll, ur=ur, start_date=start_date, end_date=end_date, where=where, max_results=max_results, starting_number=starting_number, sort_order=sort_order, api_key=api_key )} r = requests.get(url, payload) response = r.json() _check_for_usgs_error(response) if extended: metadata_urls = map(_get_metadata_url, response['data']['results']) results = _async_requests(metadata_urls) data = map(lambda idx: _get_extended(response['data']['results'][idx], results[idx]), range(len(response['data']['results']))) return response