From 556328e98d479725cc68f03d4f0ac510aa31ab22 Mon Sep 17 00:00:00 2001 From: Bennici Date: Fri, 9 Jul 2021 09:49:36 +0200 Subject: [PATCH 1/2] #43 Manage feature info response convertion to dataframe for xml format --- R/WMSLayer.R | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/R/WMSLayer.R b/R/WMSLayer.R index 966675a..79a067c 100644 --- a/R/WMSLayer.R +++ b/R/WMSLayer.R @@ -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) } From 65f4c262a286cc7fea652c89a927d88767f90e4c Mon Sep 17 00:00:00 2001 From: Bennici Date: Fri, 9 Jul 2021 09:55:17 +0200 Subject: [PATCH 2/2] #43 consolidate --- R/WMSLayer.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/WMSLayer.R b/R/WMSLayer.R index 79a067c..ab52e87 100644 --- a/R/WMSLayer.R +++ b/R/WMSLayer.R @@ -302,7 +302,7 @@ WMSLayer <- R6Class("WMSLayer", write(obj, destfile) # }else if(destext == "xml"){ # write(obj, destfile) - # } + } ftFeatures <- NULL if(destext == "xml"){ @@ -320,9 +320,9 @@ WMSLayer <- R6Class("WMSLayer", 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")) + 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)