From bdff7304de88069df132700965db22dcda16319e Mon Sep 17 00:00:00 2001 From: eblondel Date: Wed, 28 Feb 2024 21:51:43 +0100 Subject: [PATCH] patch for #125 --- R/WFSFeatureType.R | 2 +- R/WFSFeatureTypeElement.R | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/R/WFSFeatureType.R b/R/WFSFeatureType.R index 20b6a47..1e4c4e1 100644 --- a/R/WFSFeatureType.R +++ b/R/WFSFeatureType.R @@ -202,7 +202,7 @@ WFSFeatureType <- R6Class("WFSFeatureType", namespaces <- OWSUtils$getNamespaces(xmlObj) xsdNs <- OWSUtils$findNamespace(namespaces, "XMLSchema") elementXML <- getNodeSet(xmlObj, "//ns:sequence/ns:element", xsdNs) - elements <- lapply(elementXML, WFSFeatureTypeElement$new) + elements <- lapply(elementXML, WFSFeatureTypeElement$new, namespaces) self$description <- elements out <- self$description if(pretty){ diff --git a/R/WFSFeatureTypeElement.R b/R/WFSFeatureTypeElement.R index 656b402..b248020 100644 --- a/R/WFSFeatureTypeElement.R +++ b/R/WFSFeatureTypeElement.R @@ -20,7 +20,7 @@ WFSFeatureTypeElement <- R6Class("WFSFeatureTypeElement", geometry = FALSE, #fetchElement - fetchElement = function(xmlObj){ + fetchElement = function(xmlObj, namespaces){ #minOccurs elementMinOccurs <- xmlGetAttr(xmlObj, "minOccurs") @@ -46,8 +46,10 @@ WFSFeatureTypeElement <- R6Class("WFSFeatureTypeElement", if(is.null(type)){ stop(sprintf("Unknown data type for type '%s' while parsing FeatureType description!", type)) } - if(attr(regexpr("gml", type), "match.length") > 0){ - elementType <- unlist(strsplit(unlist(strsplit(type, "gml:"))[2], "PropertyType"))[1] + + gml_xmlns = namespaces[namespaces$uri =="http://www.opengis.net/gml",]$id + if(attr(regexpr(gml_xmlns, type), "match.length") > 0){ + elementType <- unlist(strsplit(unlist(strsplit(type, paste0(gml_xmlns,":")))[2], "PropertyType"))[1] geometry <- TRUE }else{ baseType <- tolower(type) @@ -86,8 +88,9 @@ WFSFeatureTypeElement <- R6Class("WFSFeatureTypeElement", #'@description Initializes a \link{WFSFeatureTypeElement} #'@param xmlObj object of class \link{XMLInternalNode-class} from \pkg{XML} - initialize = function(xmlObj){ - element = private$fetchElement(xmlObj) + #'@param namespaces namespaces definitions inherited from parent XML, as \code{data.frame} + initialize = function(xmlObj, namespaces){ + element = private$fetchElement(xmlObj, namespaces) private$minOccurs = element$minOccurs private$maxOccurs = element$maxOccurs private$nillable = element$nillable