GetBands.R 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. GetBands <-
  2. function(Product)
  3. {
  4. if(!any(Product == GetProducts())) stop("Product entered does not match any available products; see ?GetProducts.")
  5. getbands.xml <- paste('
  6. <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:mod="https://modis.ornl.gov/MODIS_soapservice">
  7. <soapenv:Header/>
  8. <soapenv:Body>
  9. <mod:getbands soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  10. <Product xsi:type="xsd:string">', Product, '</Product>
  11. </mod:getbands>
  12. </soapenv:Body>
  13. </soapenv:Envelope>',
  14. sep = "")
  15. header.fields <- c(Accept = "text/xml",
  16. Accept = "multipart/*",
  17. 'Content-Type' = "text/xml; charset=utf-8",
  18. SOAPAction = "")
  19. reader <- basicTextGatherer()
  20. header <- basicTextGatherer()
  21. curlPerform(url = paste0(daacmodis, wsdl_loc),
  22. httpheader = header.fields,
  23. postfields = getbands.xml,
  24. writefunction = reader$update,
  25. verbose = FALSE)
  26. # Check the server is not down by insepcting the XML response for internal server error message.
  27. if(grepl("Internal Server Error", reader$value())){
  28. stop("Web service failure: the ORNL DAAC server seems to be down, please try again later.
  29. The online subsetting tool may indicate when the server is up and running again.")
  30. }
  31. xmlres <- xmlRoot(xmlTreeParse(reader$value()))
  32. bandsres <- xmlSApply(xmlres[[1]],
  33. function(x) xmlSApply(x,
  34. function(x) xmlSApply(x,xmlValue)))
  35. if(colnames(bandsres) == "Fault"){
  36. if(length(bandsres['faultstring.text', ][[1]]) == 0){
  37. stop("Downloading from the web service is currently not working. Please try again later.")
  38. }
  39. stop(bandsres['faultstring.text', ])
  40. } else{
  41. return(as.vector(bandsres))
  42. }
  43. }