/
OGCExpression.R
627 lines (588 loc) · 20.5 KB
/
OGCExpression.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#' OGCExpression
#' @docType class
#' @export
#' @keywords OGC Expression
#' @return Object of \code{\link{R6Class}} for modelling an OGC Expression
#' @format \code{\link{R6Class}} object.
#'
#' @note abstract class
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
OGCExpression <- R6Class("OGCExpression",
inherit = OGCAbstractObject,
private = list(
exprVersion = "1.1.0"
),
public = list(
#'@description Initializes an object of class \link{OGCExpression}
#'@param element element name
#'@param namespacePrefix XML namespace prefix
#'@param attrs attributes
#'@param defaults default values
#'@param exprVersion OGC version for the expression
initialize = function(element, namespacePrefix, attrs = NULL, defaults = NULL, exprVersion = "1.1.0"){
self$setExprVersion(exprVersion)
super$initialize(element = element, namespacePrefix = namespacePrefix,
attrs = attrs, defaults = defaults)
},
#'@description Sets expression version. The methods will control proper XML namespace prefix setting
#'@param exprVersion OGC expression version
setExprVersion = function(exprVersion) {
private$exprVersion = exprVersion
if(exprVersion=="2.0"){
private$xmlNamespacePrefix <- "FES"
}else{
private$xmlNamespacePrefix <- "OGC"
}
},
#'@description Gets expression version
#'@return object of class \code{character}
getExprVersion = function(){
return(private$exprVersion)
}
)
)
#' BinaryComparisonOpType
#' @docType class
#' @export
#' @keywords OGC Expression BinaryComparisonOpType
#' @return Object of \code{\link{R6Class}} for modelling an BinaryComparisonOpType
#' @format \code{\link{R6Class}} object.
#'
#' @note abstract super class of all the property operation classes
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
BinaryComparisonOpType <- R6Class("BinaryComparisonOpType",
inherit = OGCExpression,
public = list(
#'@field PropertyName property name field for XML encoding
PropertyName = NULL,
#'@field Literal literal field for XML encoding
Literal = NULL,
#'@field attrs attributes for XML encoding
attrs = list(matchCase = NA),
#'@description Initializes an object extending \link{BinaryComparisonOpType}
#'@param element element name
#'@param namespacePrefix XML namespace prefix
#'@param PropertyName property name
#'@param Literal literal
#'@param matchCase match case
initialize = function(element, namespacePrefix, PropertyName, Literal, matchCase = NA){
super$initialize(element = element, namespacePrefix = namespacePrefix)
self$PropertyName = PropertyName
self$Literal = Literal
self$attrs$matchCase = matchCase
}
)
)
#' PropertyIsEqualTo
#' @docType class
#' @export
#' @keywords OGC Expression BinaryComparisonOpType PropertyIsEqualTo
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsEqualTo
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsEqualTo$new(PropertyName = "property", Literal = "value")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsEqualTo <-R6Class("PropertyIsEqualTo",
inherit = BinaryComparisonOpType,
private = list(
xmlElement = "PropertyIsEqualTo",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an object extending \link{PropertyIsEqualTo}
#'@param PropertyName property name
#'@param Literal literal
#'@param matchCase match case
initialize = function(PropertyName, Literal, matchCase = NA){
super$initialize(
element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix,
PropertyName, Literal, matchCase
)
}
)
)
#' PropertyIsNotEqualTo
#' @docType class
#' @export
#' @keywords OGC Expression BinaryComparisonOpType PropertyIsNotEqualTo
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsNotEqualTo
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsNotEqualTo$new(PropertyName = "property", Literal = "value")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsNotEqualTo <-R6Class("PropertyIsNotEqualTo",
inherit = BinaryComparisonOpType,
private = list(
xmlElement = "PropertyIsNotEqualTo",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an object extending \link{PropertyIsNotEqualTo}
#'@param PropertyName property name
#'@param Literal literal
#'@param matchCase match case
initialize = function(PropertyName, Literal, matchCase = NA){
super$initialize(
element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix,
PropertyName, Literal, matchCase
)
}
)
)
#' PropertyIsLessThan
#' @docType class
#' @export
#' @keywords OGC Expression BinaryComparisonOpType PropertyIsLessThan
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsLessThan
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsLessThan$new(PropertyName = "property", Literal = "value")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsLessThan <-R6Class("PropertyIsLessThan",
inherit = BinaryComparisonOpType,
private = list(
xmlElement = "PropertyIsLessThan",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an object extending \link{PropertyIsLessThan}
#'@param PropertyName property name
#'@param Literal literal
#'@param matchCase match case
initialize = function(PropertyName, Literal, matchCase = NA){
super$initialize(
element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix,
PropertyName, Literal, matchCase
)
}
)
)
#' PropertyIsGreaterThan
#' @docType class
#' @export
#' @keywords OGC Expression BinaryComparisonOpType PropertyIsGreaterThan
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsGreaterThan
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsGreaterThan$new(PropertyName = "property", Literal = "value")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsGreaterThan <-R6Class("PropertyIsGreaterThan",
inherit = BinaryComparisonOpType,
private = list(
xmlElement = "PropertyIsGreaterThan",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an object extending \link{PropertyIsGreaterThan}
#'@param PropertyName property name
#'@param Literal literal
#'@param matchCase match case
initialize = function(PropertyName, Literal, matchCase = NA){
super$initialize(
element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix,
PropertyName, Literal, matchCase
)
}
)
)
#' PropertyIsLesserThanOrEqualTo
#' @docType class
#' @export
#' @keywords OGC Expression BinaryComparisonOpType PropertyIsLesserThanOrEqualTo
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsLesserThanOrEqualTo
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsLessThanOrEqualTo$new(PropertyName = "property", Literal = "value")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsLessThanOrEqualTo <-R6Class("PropertyIsLessThanOrEqualTo",
inherit = BinaryComparisonOpType,
private = list(
xmlElement = "PropertyIsLessThanOrEqualTo",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an object extending \link{PropertyIsLessThanOrEqualTo}
#'@param PropertyName property name
#'@param Literal literal
#'@param matchCase match case
initialize = function(PropertyName, Literal, matchCase = NA){
super$initialize(
element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix,
PropertyName, Literal, matchCase
)
}
)
)
#' PropertyIsGreaterThanOrEqualTo
#' @docType class
#' @export
#' @keywords OGC Expression BinaryComparisonOpType PropertyIsGreaterThanOrEqualTo
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsGreaterThanOrEqualTo
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsGreaterThanOrEqualTo$new(PropertyName = "property", Literal = "value")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsGreaterThanOrEqualTo <-R6Class("PropertyIsGreaterThanOrEqualTo",
inherit = BinaryComparisonOpType,
private = list(
xmlElement = "PropertyIsGreaterThanOrEqualTo",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an object extending \link{PropertyIsGreaterThanOrEqualTo}
#'@param PropertyName property name
#'@param Literal literal
#'@param matchCase match case
initialize = function(PropertyName, Literal, matchCase = NA){
super$initialize(
element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix,
PropertyName, Literal, matchCase
)
}
)
)
#' PropertyIsLike
#' @docType class
#' @export
#' @keywords OGC Expression PropertyIsLike
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsLike
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsLike$new(PropertyName = "property", Literal = "value")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsLike <- R6Class("PropertyIsLike",
inherit = OGCExpression,
private = list(
xmlElement = "PropertyIsLike",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@field PropertyName property name field for XML encoding
PropertyName = NULL,
#'@field Literal literal field for XML encoding
Literal = NULL,
#'@field attrs attributes for XML encoding
attrs = list(
escapeChar = "\\",
singleChar = "_",
wildCard = "%",
matchCase = NA
),
#'@description Initializes an object extending \link{PropertyIsLike}
#'@param PropertyName property name
#'@param Literal literal
#'@param escapeChar escape character. Default is "\\"
#'@param singleChar single character. Default is "_"
#'@param wildCard wildcard
#'@param matchCase match case
initialize = function(PropertyName, Literal,
escapeChar = "\\", singleChar = "_", wildCard = "%", matchCase = NA){
super$initialize(element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix)
self$PropertyName = PropertyName
self$Literal = Literal
self$attrs = list(
escapeChar = escapeChar,
singleChar = singleChar,
wildCard = wildCard,
if(is.logical(matchCase)) matchCase = tolower(as.character(matchCase))
)
}
)
)
#' PropertyIsNull
#' @docType class
#' @export
#' @keywords OGC Expression PropertyIsNull
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsNull
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsNull$new(PropertyName = "property")
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsNull <- R6Class("PropertyIsNull",
inherit = OGCExpression,
private = list(
xmlElement = "PropertyIsNull",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@field PropertyName property name field for XML encoding
PropertyName = NULL,
#'@description Initializes an object extending \link{PropertyIsLike}
#'@param PropertyName property name
initialize = function(PropertyName){
super$initialize(element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix)
self$PropertyName = PropertyName
}
)
)
#' PropertyIsBetween
#' @docType class
#' @export
#' @keywords OGC Expression PropertyIsBetween
#' @return Object of \code{\link{R6Class}} for modelling an PropertyIsBetween
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsBetween$new(PropertyName = "property", lower = 1, upper = 10)
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
PropertyIsBetween <- R6Class("PropertyIsBetween",
inherit = OGCExpression,
private = list(
xmlElement = "PropertyIsBetween",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@field PropertyName property name field for XML encoding
PropertyName = NULL,
#'@field lower lower value
lower = NULL,
#'@field upper upper value
upper = NULL,
#'@description Initializes an object extending \link{PropertyIsLike}
#'@param PropertyName property name
#'@param lower lower value
#'@param upper upper value
initialize = function(PropertyName, lower, upper){
super$initialize(element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix)
self$PropertyName = PropertyName
self$lower = lower
self$upper = upper
}
)
)
#' BBOX
#' @docType class
#' @export
#' @keywords OGC Expression BBOX
#' @return Object of \code{\link{R6Class}} for modelling an BBOX
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' bbox <- OWSUtils$toBBOX(-180,-90,180,90)
#' expr <- BBOX$new(bbox)
#' expr_xml <- expr$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
BBOX <- R6Class("BBOX",
inherit = OGCExpression,
private = list(
xmlElement = "BBOX",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@field PropertyName property name field for XML encoding
PropertyName = "ows:BoundingBox",
#'@field Envelope envelope as object of class \link{GMLEnvelope} from \pkg{geometa}
Envelope = NULL,
#'@description Initializes a \link{BBOX} expression
#'@param bbox an object of class \code{matrix}
#'@param srsName srs name
initialize = function(bbox, srsName = NULL){
super$initialize(element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix)
envelope <- GMLEnvelope$new(bbox = bbox, srsName = srsName)
envelope$wrap <- FALSE
#gmlNS <- envelope$getNamespaceDefinition()
#private$xmlNamespace = c(private$xmlNamespace, ns = gmlNS$gml)
#names(private$xmlNamespace)[length(private$xmlNamespace)] <- names(gmlNS)
self$Envelope = envelope
}
)
)
#BINARY
#' BinaryLogicOpType
#' @docType class
#' @export
#' @keywords OGC Expression BinaryLogicOpType
#' @return Object of \code{\link{R6Class}} for modelling an BinaryLogicOpType
#' @format \code{\link{R6Class}} object.
#' @note abstract super class of all the binary logical operation classes
BinaryLogicOpType <- R6Class("BinaryLogicOpType",
inherit = OGCExpression,
public = list(
#'@field operations a list OGC expressions
operations = list(),
#'@description Initializes a \link{BinaryLogicOpType} expression
#'@param ... list of objects of class \link{OGCExpression}
#'@param element element
#'@param namespacePrefix namespacePrefix
#'@param exprVersion OGC expression version. Default is "1.1.0"
initialize = function(..., element, namespacePrefix, exprVersion = "1.1.0"){
super$initialize(element = element, namespacePrefix = namespacePrefix, exprVersion = exprVersion)
operations <- list(...)
if(length(operations)<2){
stop("Binary operations (And / Or) require a minimum of two operations")
}
self$operations = operations
self$setExprVersion(exprVersion)
},
#'@description Sets expression version. The methods will control that expression versions are set
#' for each of the operations specified in the expression.
#'@param exprVersion OGC expression version
setExprVersion = function(exprVersion){
private$exprVersion <- exprVersion
if(length(self$operations)>0) for(i in 1:length(self$operations)){
self$operations[[i]]$setExprVersion(exprVersion)
}
}
)
)
#' And
#' @docType class
#' @export
#' @keywords OGC Expression BinaryLogicOpType And
#' @return Object of \code{\link{R6Class}} for modelling an And operator
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr1 <- PropertyIsEqualTo$new(PropertyName = "property1", Literal = "value1")
#' expr2 <- PropertyIsEqualTo$new(PropertyName = "property2", Literal = "value2")
#' and <- And$new(expr1,expr2)
#' and_xml <- and$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
And <- R6Class("And",
inherit = BinaryLogicOpType,
private = list(
xmlElement = "And",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an \link{And} expression
#'@param ... list of objects of class \link{OGCExpression}
initialize = function(...){
super$initialize(..., element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix)
}
)
)
#' Or
#' @docType class
#' @export
#' @keywords OGC Expression BinaryLogicOpType Or
#' @return Object of \code{\link{R6Class}} for modelling an Or operator
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr1 <- PropertyIsEqualTo$new(PropertyName = "property1", Literal = "value1")
#' expr2 <- PropertyIsEqualTo$new(PropertyName = "property2", Literal = "value2")
#' or <- Or$new(expr1,expr2)
#' or_xml <- or$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
Or <- R6Class("Or",
inherit = BinaryLogicOpType,
private = list(
xmlElement = "Or",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an \link{Or} expression
#'@param ... list of objects of class \link{OGCExpression}
initialize = function(...){
super$initialize(..., element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix)
}
)
)
#UNARY
#' UnaryLogicOpType
#' @docType class
#' @export
#' @keywords OGC Expression UnaryLogicOpType
#' @return Object of \code{\link{R6Class}} for modelling an UnaryLogicOpType
#' @format \code{\link{R6Class}} object.
#' @note abstract super class of all the unary logical operation classes
UnaryLogicOpType <- R6Class("UnaryLogicOpType",
inherit = OGCExpression,
public = list(
#'@field operations a list OGC expressions
operations = list(),
#'@description Initializes a \link{UnaryLogicOpType} expression
#'@param ... list of objects of class \link{OGCExpression}
#'@param element element
#'@param namespacePrefix namespacePrefix
#'@param exprVersion OGC expression version. Default is "1.1.0"
initialize = function(..., element, namespacePrefix, exprVersion = "1.1.0"){
super$initialize(element = element, namespacePrefix = namespacePrefix, exprVersion = exprVersion)
self$operations = list(...)
self$setExprVersion(exprVersion)
},
#'@description Sets expression version. The methods will control that expression versions are set
#' for each of the operations specified in the expression.
#'@param exprVersion OGC expression version
setExprVersion = function(exprVersion){
private$exprVersion <- exprVersion
if(length(self$operations)>0) for(i in 1:length(self$operations)){
self$operations[[i]]$setExprVersion(exprVersion)
}
}
)
)
#' Not
#' @docType class
#' @export
#' @keywords OGC Expression UnaryLogicOpType Not
#' @return Object of \code{\link{R6Class}} for modelling an Not
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' expr <- PropertyIsEqualTo$new(PropertyName = "property", Literal = "value")
#' not <- Not$new(expr)
#' not_xml <- not$encode() #see how it looks like in XML
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
Not <- R6Class("Not",
inherit = UnaryLogicOpType,
private = list(
xmlElement = "Not",
xmlNamespacePrefix = "OGC"
),
public = list(
#'@description Initializes an \link{Not} expression
#'@param ... list of objects of class \link{OGCExpression}
initialize = function(...){
super$initialize(..., element = private$xmlElement, namespacePrefix = private$xmlNamespacePrefix)
}
)
)