示例#1
0
文件: api.py 项目: danlopez00/usgs
def download(dataset, node, entityids, product='STANDARD', api_key=None):
    """
    Though USGS supports multiple products in a single request, there's
    ambiguity in the returned list. This wrapper only allows a single
    product per request.

    Additionally, the response has no indiction which URL is associated
    with which scene/entity id. The URL can be parsed, but the structure
    varies depending on the product.
    """

    api_key = api_key if api_key else _get_api_key()

    xml = soap.download(dataset, node, entityids, [product], 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:downloadResponse/return/item",
                         NAMESPACES)

    data = map(lambda el: xsi.get(el), items)

    return data
示例#2
0
    def test_download(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:download soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
              <datasetName xsi:type="xsd:string">LANDSAT_8</datasetName>
              <node xsi:type="xsd:string">EE</node>
              <apiKey xsi:type="xsd:string">USERS API KEY</apiKey>
              <entityIds xsi:type="soap:ArrayOfString">
                <item xsi:type="xsd:string">LC80130292014100LGN00</item>
              </entityIds>
              <products xsi:type="soap:ArrayOfString">
                <item xsi:type="xsd:string">STANDARD</item>
              </products>
            </soap:download>
          </soapenv:Body>
        </soapenv:Envelope>
        """

        request = soap.download("LANDSAT_8",
                                "EE", ["LC80130292014100LGN00"], ["STANDARD"],
                                api_key="USERS API KEY")
        request = minidom.parseString(request).toprettyxml()

        assert compare_xml(request, expected)
示例#3
0
 def test_download(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:download soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
           <datasetName xsi:type="xsd:string">LANDSAT_8</datasetName>
           <node xsi:type="xsd:string">EE</node>
           <apiKey xsi:type="xsd:string">USERS API KEY</apiKey>
           <entityIds xsi:type="soap:ArrayOfString">
             <item xsi:type="xsd:string">LC80130292014100LGN00</item>
           </entityIds>
           <products xsi:type="soap:ArrayOfString">
             <item xsi:type="xsd:string">STANDARD</item>
           </products>
         </soap:download>
       </soapenv:Body>
     </soapenv:Envelope>
     """
     
     request = soap.download("LANDSAT_8", "EE", ["LC80130292014100LGN00"], ["STANDARD"], api_key="USERS API KEY")
     request = minidom.parseString(request).toprettyxml()
     
     assert compare_xml(request, expected)
示例#4
0
文件: api.py 项目: jonas-eberle/usgs
def download(dataset, node, entityids, product='STANDARD', api_key=None):
    """
    Though USGS supports multiple products in a single request, there's
    ambiguity in the returned list. This wrapper only allows a single
    product per request.

    Additionally, the response has no indiction which URL is associated
    with which scene/entity id. The URL can be parsed, but the structure
    varies depending on the product.
    """

    api_key = api_key if api_key else _get_api_key()

    xml = soap.download(dataset, node, entityids, [product], 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:downloadResponse/return/item", NAMESPACES)

    data = map(lambda el: xsi.get(el), items)

    return data