Skip to content

Commit

Permalink
Use between as temporal operator with QGIS
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan committed Nov 16, 2018
1 parent 09b1afc commit 4946ac4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/filter/RuleHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import googAsserts from 'goog/asserts.js';
import ngeoFilterCondition from 'ngeo/filter/Condition.js';
import ngeoFormatAttributeType from 'ngeo/format/AttributeType.js';
import * as ngeoFormatFilter from 'ngeo/format/filter.js';
import ngeoMiscFeatureHelper from 'ngeo/misc/FeatureHelper.js';
import ngeoMiscWMSTime from 'ngeo/misc/WMSTime.js';
import ngeoRuleDate from 'ngeo/rule/Date.js';
Expand Down Expand Up @@ -556,11 +557,19 @@ const exports = class {
);
}
if (beginValue && endValue) {
filter = olFormatFilter.during(
propertyName,
beginValue,
endValue
);
if (dataSource.ogcServerType == 'qgisserver') {
filter = ngeoFormatFilter.dateBetween(
propertyName,
beginValue,
endValue
);
} else {
filter = olFormatFilter.during(
propertyName,
beginValue,
endValue
);
}
}
} else if (rule instanceof ngeoRuleSelect) {
const selectedChoices = rule.selectedChoices;
Expand Down
45 changes: 45 additions & 0 deletions src/format/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @module ngeo.format.filter
*/
import olFormatFilterComparison from 'ol/format/filter/Comparison.js';

/**
* @classdesc
* Represents a `<PropertyIsBetween>` temporal comparison operator,
* suitable for QGIS server that does not support `<During>`.
*/
class DateIsBetween extends olFormatFilterComparison {

/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!string} lowerBoundary The lower bound of the range.
* @param {!string} upperBoundary The upper bound of the range.
*/
constructor(propertyName, lowerBoundary, upperBoundary) {
super('PropertyIsBetween', propertyName);

/**
* @type {!string}
*/
this.lowerBoundary = lowerBoundary;

/**
* @type {!string}
*/
this.upperBoundary = upperBoundary;
}
}


/**
* Creates a `<PropertyIsBetween>` comparison operator to test whether an expression
* value lies within a time range given by a lower and upper bound (inclusive).
*
* @param {!string} propertyName Name of the context property to compare.
* @param {!string} lowerBoundary The lower bound of the range.
* @param {!string} upperBoundary The upper bound of the range.
* @returns {!ngeo.format.filter.DateIsBetween} `<PropertyIsBetween>` operator.
*/
export function dateBetween(propertyName, lowerBoundary, upperBoundary) {
return new DateIsBetween(propertyName, lowerBoundary, upperBoundary);
}

0 comments on commit 4946ac4

Please sign in to comment.