Skip to content

Commit

Permalink
eblondel#43 Manage feature info response convertion to dataframe for …
Browse files Browse the repository at this point in the history
…xml format
  • Loading branch information
abennici committed Jul 9, 2021
1 parent 3d5d32b commit 556328e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions R/WMSLayer.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,30 @@ WMSLayer <- R6Class("WMSLayer",
saveXML(obj, destfile)
}else if(destext == "json"){
write(obj, destfile)
}
# }else if(destext == "xml"){
# write(obj, destfile)
# }

ftFeatures <- NULL
if(destext == "xml"){
xml<- xmlParse(obj)
rootname <- xmlName(xmlChildren(xml)[[1]])
if(rootname == "FeatureInfoResponse"){
#TODO build sf(s) based on a FeatureInfoResponse xml (eg. case of Thredds data servers)
xml_list <- xmlToList(xml)
if("FIELDS" %in% names(xml_list)){
variables = lapply(xml_list[["FIELDS"]], function(x){
outvar <- x
name <- names(x)
attr(outvar, "description") <- name
return(outvar)
})
ftFeatures<-data.frame(variables)
}else{
#THREDDS STRUCTURE
ftFeatures<-data.frame(xml_list,stringsAsFactors=FALSE)
names(ftFeatures)<-gsub("^.*\\.","",names(ftFeatures))
ftFeatures<-sf::st_as_sf(ftFeatures,coords= c("longitude","latitude"))
}
}else{
ftFeatures <- sf::st_read(destfile, quiet = TRUE)
}
Expand Down

0 comments on commit 556328e

Please sign in to comment.