Skip to content

Commit

Permalink
#43 improve getfeatureinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Sep 4, 2020
1 parent 3a7283e commit 8a6646b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
7 changes: 4 additions & 3 deletions R/WMSClient.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,23 @@ WMSClient <- R6Class("WMSClient",
},

#getFeatureInfo
getFeatureInfo = function(layer, styles = NULL, feature_count = 1,
getFeatureInfo = function(layer, srs = NULL, crs = NULL,
styles = NULL, feature_count = 1,
x, y, width, height, bbox,
info_format = "application/vnd.ogc.gml",
...){
wmsLayer = self$capabilities$findLayerByName(layer)
features <- NULL
if(is(wmsLayer,"WMSLayer")){
features <- wmsLayer$getFeatureInfo(
styles = styles, feature_count = feature_count,
srs = srs, crs = crs, styles = styles, feature_count = feature_count,
x = x, y = y, width = width, height = height, bbox = bbox,
info_format = info_format,
...
)
}else if(is(wmsLayer, "list")){
features <- wmsLayer[[1]]$getFeatureInfo(
styles = styles, feature_count = feature_count,
srs = srs, crs = crs, styles = styles, feature_count = feature_count,
x = x, y = y, width = width, height = height, bbox = bbox,
info_format = info_format,
...
Expand Down
5 changes: 4 additions & 1 deletion R/WMSGetFeatureInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WMSGetFeatureInfo <- R6Class("WMSGetFeatureInfo",
name = "GetFeatureInfo"
),
public = list(
initialize = function(op, url, version, layers, srs, styles, feature_count = 1,
initialize = function(op, url, version, layers, srs, crs, styles, feature_count = 1,
x, y, width, height, bbox, info_format = "application/vnd.ogc.gml",
logger = NULL, ...) {

Expand All @@ -43,6 +43,8 @@ WMSGetFeatureInfo <- R6Class("WMSGetFeatureInfo",
FORMAT = "image/png",
TRANSPARENT = "true",
QUERY_LAYERS = layers,
SRS = srs,
CRS = crs,
LAYERS = layers,
STYLES = styles,
FEATURE_COUNT = format(feature_count, scientific = FALSE),
Expand All @@ -51,6 +53,7 @@ WMSGetFeatureInfo <- R6Class("WMSGetFeatureInfo",
BBOX = bbox,
INFO_FORMAT = info_format
)
namedParams <- namedParams[!sapply(namedParams, is.null)]
vendorParams <- list(...)
if(length(vendorParams)>0) namedParams <- c(namedParams, vendorParams)
super$initialize(op, "GET", url, request = private$name,
Expand Down
40 changes: 36 additions & 4 deletions R/WMSLayer.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ WMSLayer <- R6Class("WMSLayer",
keywords = NA,
defaultCRS = NA,
boundingBox = NA,
boundingBoxSRS = NA,
boundingBoxCRS = NA,
style = NA,

#fetchLayer
Expand Down Expand Up @@ -71,7 +73,7 @@ WMSLayer <- R6Class("WMSLayer",
}

layerDefaultCRS <- NULL
if(version == "1.1.1"){
if(startsWith(version, "1.1")){
if(!is.null(children$SRS)){
layerDefaultCRS <- xmlValue(children$SRS)
}
Expand All @@ -80,11 +82,20 @@ WMSLayer <- R6Class("WMSLayer",
layerDefaultCRS <- xmlValue(children[names(children)=="CRS"][[1]])
}
}
if(!is.null(layerDefaultCRS)) layerDefaultCRS <- OWSUtils$toCRS(layerDefaultCRS)
if(!is.null(layerDefaultCRS)){
layerDefaultCRS <- OWSUtils$toCRS(layerDefaultCRS)
}

layerSRS <- NULL
layerCRS <- NULL
layerBoundingBox <- NULL
bboxXML <- children$BoundingBox
if(!is.null(bboxXML)){
if(startsWith(version, "1.1")){
layerSRS <- as.character(xmlGetAttr(bboxXML, "SRS"))
}else if(version == "1.3.0"){
layerCRS <- as.character(xmlGetAttr(bboxXML, "CRS"))
}
layerBoundingBox <- OWSUtils$toBBOX(
as.numeric(xmlGetAttr(bboxXML,"minx")),
as.numeric(xmlGetAttr(bboxXML,"maxx")),
Expand All @@ -106,6 +117,8 @@ WMSLayer <- R6Class("WMSLayer",
keywords = layerKeywords,
defaultCRS = layerDefaultCRS,
boundingBox = layerBoundingBox,
boundingBoxSRS = layerSRS,
boundingBoxCRS = layerCRS,
style = layerStyle
)

Expand All @@ -131,6 +144,8 @@ WMSLayer <- R6Class("WMSLayer",
private$keywords = layer$keywords
private$defaultCRS = layer$defaultCRS
private$boundingBox = layer$boundingBox
private$boundingBoxSRS = layer$boundingBoxSRS
private$boundingBoxCRS = layer$boundingBoxCRS
private$style = layer$style

},
Expand Down Expand Up @@ -165,13 +180,23 @@ WMSLayer <- R6Class("WMSLayer",
return(private$boundingBox)
},

#getBoundingBoxSRS
getBoundingBoxSRS = function(){
return(private$boundingBoxSRS)
},

#getBoundingBoxCRS
getBoundingBoxCRS = function(){
return(private$boundingBoxCRS)
},

#getStyle
getStyle = function(){
return(private$style)
},

#getFeatureInfo
getFeatureInfo = function(styles = NULL, feature_count = 1,
getFeatureInfo = function(srs = NULL, crs = NULL, styles = NULL, feature_count = 1,
x, y, width, height, bbox,
info_format = "application/vnd.ogc.gml",
...){
Expand All @@ -180,9 +205,16 @@ WMSLayer <- R6Class("WMSLayer",
styles <- self$getStyle()
}

if(is.null(srs)){
srs <- self$getBoundingBoxSRS()
}
if(is.null(crs)){
crs <- self$getBoundingBoxCRS()
}

ftFeatures <- WMSGetFeatureInfo$new(
op = op, url = private$url, version = private$version,
layers = private$name, styles = styles,
layers = private$name, srs = srs, crs = crs, styles = styles,
feature_count = feature_count,
x = x, y = y, width = width, height = height, bbox = bbox,
info_format = info_format,
Expand Down

0 comments on commit 8a6646b

Please sign in to comment.