diff --git a/DESCRIPTION b/DESCRIPTION index 5ad64e4..bdbffc2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ows4R Version: 0.4 -Date: 2024-02-13 +Date: 2024-02-23 Title: Interface to OGC Web-Services (OWS) Authors@R: c(person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762")), person("Alexandre", "Bennici", role = c("ctb"), comment = c(ORCID = "0000-0003-2160-3487")), diff --git a/NEWS.md b/NEWS.md index 9157c6e..a49f6b9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,7 @@ - [#122](https://github.com/eblondel/ows4R/issues/122) Service exceptions are not always handled in status code 400 - [#123](https://github.com/eblondel/ows4R/issues/123) Missing axis labels handling for WCS coverage envelope +- [#124](https://github.com/eblondel/ows4R/issues/124) Optimize WFS getFeatures depending on the outputFormat ## [ows4R 0.3-6](https://github.com/eblondel/ows4R) | [![CRAN_Status_Badge](https://img.shields.io/badge/CRAN-published-blue.svg)](https://github.com/eblondel/ows4R) diff --git a/R/WFSFeatureType.R b/R/WFSFeatureType.R index 7192316..20b6a47 100644 --- a/R/WFSFeatureType.R +++ b/R/WFSFeatureType.R @@ -366,6 +366,9 @@ WFSFeatureType <- R6Class("WFSFeatureType", } } + read_features = TRUE + validate_features = TRUE + #write the file to disk tempf = tempfile() if(is.null(outputFormat)){ @@ -384,19 +387,32 @@ WFSFeatureType <- R6Class("WFSFeatureType", "application/json" = { destfile = paste0(tempf,".json") write(obj, destfile) + validate_features = FALSE }, "json" = { destfile = paste0(tempf,".json") write(obj, destfile) + validate_features = FALSE }, "csv" = { destfile = paste0(tempf,".csv") lcolnames = tolower(colnames(obj)) - sf::st_write(obj[,!duplicated(lcolnames)], destfile) + if(self$getGeometryType() %in% colnames(obj)){ + sf::st_write(obj[,!duplicated(lcolnames)], destfile) + validate_features = FALSE + }else{ + readr::write_csv(obj[,!duplicated(lcolnames)], destfile) + read_features = FALSE + } } ) } + if(!read_features){ + self$features = obj + return(self$features) + } + #read features if(!is.null(outputFormat)){ ftFeatures <- switch(tolower(outputFormat), @@ -418,7 +434,7 @@ WFSFeatureType <- R6Class("WFSFeatureType", } #validating attributes vs. schema - for(element in self$description){ + if(validate_features) for(element in self$description){ attrType <- element$getType() if(!is.null(attrType) && !element$isGeometry()){ attrName = element$getName()