Ejemplo n.º 1
0
    def test_search(self):

        expected = """
        <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://earthexplorer.usgs.gov/inventory/soap">
          <soapenv:Header/>
          <soapenv:Body>
            <soap:search soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
              <datasetName xsi:type="xsd:string">GLS2005</datasetName>
              <node xsi:type="xsd:string">EE</node>
              <lowerLeft xsi:type="soap:Service_Class_Coordinate">
                <latitude xsi:type="xsd:double">75</latitude>
                <longitude xsi:type="xsd:double">-135</longitude>
              </lowerLeft>
              <upperRight xsi:type="soap:Service_Class_Coordinate">
                <latitude xsi:type="xsd:double">90</latitude>
                <longitude xsi:type="xsd:double">-120</longitude>
              </upperRight>
              <startDate xsi:type="xsd:string">2006-01-01T00:00:00Z</startDate>
              <endDate xsi:type="xsd:string">2007-12-01T00:00:00Z</endDate>
              <maxResults xsi:type="xsd:int">3</maxResults>
              <startingNumber xsi:type="xsd:int">1</startingNumber>
              <sortOrder xsi:type="xsd:string">ASC</sortOrder>
              <apiKey xsi:type="xsd:string">USERS API KEY</apiKey>
            </soap:search>
          </soapenv:Body>
        </soapenv:Envelope>
        """

        ll = {"longitude": -135, "latitude": 75}
        ur = {"longitude": -120, "latitude": 90}
        start_date = "2006-01-01T00:00:00Z"
        end_date = "2007-12-01T00:00:00Z"

        request = soap.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")
        request = minidom.parseString(request).toprettyxml()

        assert compare_xml(request, expected)
Ejemplo n.º 2
0
    def test_search(self):

        expected = """
        <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://earthexplorer.usgs.gov/inventory/soap">
          <soapenv:Header/>
          <soapenv:Body>
            <soap:search soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
              <datasetName xsi:type="xsd:string">GLS2005</datasetName>
              <node xsi:type="xsd:string">EE</node>
              <lowerLeft xsi:type="soap:Service_Class_Coordinate">
                <latitude xsi:type="xsd:double">75</latitude>
                <longitude xsi:type="xsd:double">-135</longitude>
              </lowerLeft>
              <upperRight xsi:type="soap:Service_Class_Coordinate">
                <latitude xsi:type="xsd:double">90</latitude>
                <longitude xsi:type="xsd:double">-120</longitude>
              </upperRight>
              <startDate xsi:type="xsd:string">2006-01-01T00:00:00Z</startDate>
              <endDate xsi:type="xsd:string">2007-12-01T00:00:00Z</endDate>
              <maxResults xsi:type="xsd:int">3</maxResults>
              <startingNumber xsi:type="xsd:int">1</startingNumber>
              <sortOrder xsi:type="xsd:string">ASC</sortOrder>
              <apiKey xsi:type="xsd:string">USERS API KEY</apiKey>
            </soap:search>
          </soapenv:Body>
        </soapenv:Envelope>
        """

        ll = {"longitude": -135, "latitude": 75}
        ur = {"longitude": -120, "latitude": 90}
        start_date = "2006-01-01T00:00:00Z"
        end_date = "2007-12-01T00:00:00Z"

        request = soap.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")
        request = minidom.parseString(request).toprettyxml()

        assert compare_xml(request, expected)
Ejemplo n.º 3
0
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", api_key=None):
    """
    .. todo:: Export metadata from the search results e.g.
    
        <numberReturned xsi:type="xsd:int">41</numberReturned>
        <totalHits xsi:type="xsd:int">41</totalHits>
        <firstRecord xsi:type="xsd:int">1</firstRecord>
        <lastRecord xsi:type="xsd:int">41</lastRecord>
        <nextRecord xsi:type="xsd:int">41</nextRecord>
    """
    api_key = _get_api_key()
    
    xml = soap.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.post(USGS_API, xml)
    
    root = ElementTree.fromstring(r.text)
    _check_for_usgs_error(root)
    
    items = root.findall("SOAP-ENV:Body/ns1:searchResponse/return/results/item", NAMESPACES)
    
    data = map(lambda item: { el.tag: xsi.get(el) for el in item }, items)
    
    return data
Ejemplo n.º 4
0
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. Not required for searching.

    .. todo:: Export metadata from the search results e.g.

        <numberReturned xsi:type="xsd:int">41</numberReturned>
        <totalHits xsi:type="xsd:int">41</totalHits>
        <firstRecord xsi:type="xsd:int">1</firstRecord>
        <lastRecord xsi:type="xsd:int">41</lastRecord>
        <nextRecord xsi:type="xsd:int">41</nextRecord>
    """
    api_key = api_key if api_key else _get_api_key()

    xml = soap.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.post(USGS_API, xml)

    # Find out what's going on with usgs servers!
    try:
        r.raise_for_status()
    except:
        print(r.text)

    root = ElementTree.fromstring(r.text)
    _check_for_usgs_error(root)

    items = root.findall(
        "SOAP-ENV:Body/ns1:searchResponse/return/results/item", NAMESPACES)

    data = map(lambda item: {el.tag: xsi.get(el) for el in item}, items)

    if extended:
        metadata_urls = map(_get_metadata_url, data)
        results = _async_requests(metadata_urls)
        data = map(lambda idx: _get_extended(data[idx], results[idx]),
                   range(len(data)))

    return data
Ejemplo n.º 5
0
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. Not required for searching.

    .. todo:: Export metadata from the search results e.g.

        <numberReturned xsi:type="xsd:int">41</numberReturned>
        <totalHits xsi:type="xsd:int">41</totalHits>
        <firstRecord xsi:type="xsd:int">1</firstRecord>
        <lastRecord xsi:type="xsd:int">41</lastRecord>
        <nextRecord xsi:type="xsd:int">41</nextRecord>
    """
    api_key = api_key if api_key else _get_api_key()

    xml = soap.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.post(USGS_API, xml)

    # Find out what's going on with usgs servers!
    try:
        r.raise_for_status()
    except:
        print(r.text)

    root = ElementTree.fromstring(r.text)
    _check_for_usgs_error(root)

    items = root.findall("SOAP-ENV:Body/ns1:searchResponse/return/results/item", NAMESPACES)

    data = map(lambda item: {el.tag: xsi.get(el) for el in item}, items)

    if extended:
        metadata_urls = map(_get_metadata_url, data)
        results = _async_requests(metadata_urls)
        data = map(lambda idx: _get_extended(data[idx], results[idx]), range(len(data)))

    return data