From d3041295a1ec17cc05a9347875b86d8311edeb43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Sun, 9 Aug 2020 22:36:41 +0200 Subject: [PATCH 01/10] Initial spike on WFS 2.0 --- src/ol/format/WFS.js | 211 +++++++++++++++++++++++++------- test/spec/ol/format/wfs.test.js | 3 +- 2 files changed, 168 insertions(+), 46 deletions(-) diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index 3438edfe44..d8d277100b 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -51,6 +51,11 @@ const TRANSACTION_SUMMARY_PARSERS = { 'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger), 'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger), }, + 'http://www.opengis.net/wfs/2.0': { + 'totalInserted': makeObjectPropertySetter(readNonNegativeInteger), + 'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger), + 'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger), + }, }; /** @@ -65,6 +70,13 @@ const TRANSACTION_RESPONSE_PARSERS = { ), 'InsertResults': makeObjectPropertySetter(readInsertResults, 'insertIds'), }, + 'http://www.opengis.net/wfs/2.0': { + 'TransactionSummary': makeObjectPropertySetter( + readTransactionSummary, + 'transactionSummary' + ), + 'InsertResults': makeObjectPropertySetter(readInsertResults, 'insertIds'), + }, }; /** @@ -74,6 +86,9 @@ const QUERY_SERIALIZERS = { 'http://www.opengis.net/wfs': { 'PropertyName': makeChildAppender(writeStringTextNode), }, + 'http://www.opengis.net/wfs/2.0': { + 'PropertyName': makeChildAppender(writeStringTextNode), + }, }; /** @@ -87,6 +102,13 @@ const TRANSACTION_SERIALIZERS = { 'Property': makeChildAppender(writeProperty), 'Native': makeChildAppender(writeNative), }, + 'http://www.opengis.net/wfs/2.0': { + 'Insert': makeChildAppender(writeFeature), + 'Update': makeChildAppender(writeUpdate), + 'Delete': makeChildAppender(writeDelete), + 'Property': makeChildAppender(writeProperty), + 'Native': makeChildAppender(writeNative), + }, }; /** @@ -95,6 +117,7 @@ const TRANSACTION_SERIALIZERS = { * @property {Array|string} [featureType] The feature type to parse. Only used for read operations. * @property {GMLBase} [gmlFormat] The GML format to use to parse the response. Default is `ol/format/GML3`. * @property {string} [schemaLocation] Optional schemaLocation to use for serialization, this will override the default. + * @property {string} [version='1.1.0'] WFS version to use. Can be either `1.0.0`, `1.1.0` or `2.0.0`. */ /** @@ -164,14 +187,22 @@ const FEATURE_PREFIX = 'feature'; const XMLNS = 'http://www.w3.org/2000/xmlns/'; /** - * @type {string} + * @type {Object} */ -const OGCNS = 'http://www.opengis.net/ogc'; +const OGCNS = { + '2.0.0': 'http://www.opengis.net/ogc/1.1', + '1.1.0': 'http://www.opengis.net/ogc', + '1.0.0': 'http://www.opengis.net/ogc', +}; /** - * @type {string} + * @type {Object} */ -const WFSNS = 'http://www.opengis.net/wfs'; +const WFSNS = { + '2.0.0': 'http://www.opengis.net/wfs/2.0', + '1.1.0': 'http://www.opengis.net/wfs', + '1.0.0': 'http://www.opengis.net/wfs', +}; /** * @type {string} @@ -182,6 +213,8 @@ const FESNS = 'http://www.opengis.net/fes'; * @type {Object} */ const SCHEMA_LOCATIONS = { + '2.0.0': + 'http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0.0/wfs.xsd', '1.1.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd', '1.0.0': @@ -212,6 +245,12 @@ class WFS extends XMLFeature { const options = opt_options ? opt_options : {}; + /** + * @private + * @type {string} + */ + this.version_ = options.version ? options.version : DEFAULT_VERSION; + /** * @private * @type {Array|string|undefined} @@ -236,7 +275,7 @@ class WFS extends XMLFeature { */ this.schemaLocation_ = options.schemaLocation ? options.schemaLocation - : SCHEMA_LOCATIONS[DEFAULT_VERSION]; + : SCHEMA_LOCATIONS[this.version_]; } /** @@ -406,9 +445,9 @@ class WFS extends XMLFeature { * @api */ writeGetFeature(options) { - const node = createElementNS(WFSNS, 'GetFeature'); + const node = createElementNS(WFSNS[this.version_], 'GetFeature'); node.setAttribute('service', 'WFS'); - node.setAttribute('version', '1.1.0'); + node.setAttribute('version', this.version_); let filter; if (options) { if (options.handle) { @@ -458,6 +497,7 @@ class WFS extends XMLFeature { node: node, }; assign(context, { + 'version': this.version_, 'srsName': options.srsName, 'featureNS': options.featureNS ? options.featureNS : this.featureNS_, 'featurePrefix': options.featurePrefix, @@ -487,8 +527,8 @@ class WFS extends XMLFeature { */ writeTransaction(inserts, updates, deletes, options) { const objectStack = []; - const node = createElementNS(WFSNS, 'Transaction'); - const version = options.version ? options.version : DEFAULT_VERSION; + const version = options.version ? options.version : this.version_; + const node = createElementNS(WFSNS[version], 'Transaction'); const gmlVersion = version === '1.0.0' ? 2 : 3; node.setAttribute('service', 'WFS'); node.setAttribute('version', version); @@ -501,11 +541,10 @@ class WFS extends XMLFeature { node.setAttribute('handle', options.handle); } } - const schemaLocation = SCHEMA_LOCATIONS[version]; node.setAttributeNS( XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', - schemaLocation + SCHEMA_LOCATIONS[version] ); const featurePrefix = options.featurePrefix ? options.featurePrefix @@ -514,6 +553,7 @@ class WFS extends XMLFeature { obj = assign( {node: node}, { + version, 'featureNS': options.featureNS, 'featureType': options.featureType, 'featurePrefix': featurePrefix, @@ -535,6 +575,7 @@ class WFS extends XMLFeature { obj = assign( {node: node}, { + version, 'featureNS': options.featureNS, 'featureType': options.featureType, 'featurePrefix': featurePrefix, @@ -555,7 +596,8 @@ class WFS extends XMLFeature { if (deletes) { pushSerializeAndPop( { - node: node, + node, + version, 'featureNS': options.featureNS, 'featureType': options.featureType, 'featurePrefix': featurePrefix, @@ -571,7 +613,8 @@ class WFS extends XMLFeature { if (options.nativeElements) { pushSerializeAndPop( { - node: node, + node, + version, 'featureNS': options.featureNS, 'featureType': options.featureType, 'featurePrefix': featurePrefix, @@ -644,6 +687,11 @@ const OGC_FID_PARSERS = { return node.getAttribute('fid'); }), }, + 'http://www.opengis.net/ogc/1.1': { + 'FeatureId': makeArrayPusher(function (node, objectStack) { + return node.getAttribute('fid'); + }), + }, }; /** @@ -662,6 +710,9 @@ const INSERT_RESULTS_PARSERS = { 'http://www.opengis.net/wfs': { 'Feature': fidParser, }, + 'http://www.opengis.net/wfs/2.0': { + 'Feature': fidParser, + }, }; /** @@ -698,8 +749,11 @@ function writeFeature(node, feature, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeOgcFidFilter(node, fid, objectStack) { - const filter = createElementNS(OGCNS, 'Filter'); - const child = createElementNS(OGCNS, 'FeatureId'); + const context = objectStack[objectStack.length - 1]; + const version = context['version']; + const ns = OGCNS[version]; + const filter = createElementNS(ns, 'Filter'); + const child = createElementNS(ns, 'FeatureId'); filter.appendChild(child); child.setAttribute('fid', /** @type {string} */ (fid)); node.appendChild(filter); @@ -749,6 +803,7 @@ function writeDelete(node, feature, objectStack) { function writeUpdate(node, feature, objectStack) { const context = objectStack[objectStack.length - 1]; assert(feature.getId() !== undefined, 27); // Features must have an id set + const version = context['version']; const featureType = context['featureType']; const featurePrefix = context['featurePrefix']; const featureNS = context['featureNS']; @@ -775,6 +830,7 @@ function writeUpdate(node, feature, objectStack) { } pushSerializeAndPop( /** @type {import("../xml.js").NodeStackItem} */ ({ + version, 'gmlVersion': context['gmlVersion'], node: node, 'hasZ': context['hasZ'], @@ -795,13 +851,15 @@ function writeUpdate(node, feature, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeProperty(node, pair, objectStack) { - const name = createElementNS(WFSNS, 'Name'); const context = objectStack[objectStack.length - 1]; + const version = context['version']; + const ns = WFSNS[version]; + const name = createElementNS(ns, 'Name'); const gmlVersion = context['gmlVersion']; node.appendChild(name); writeStringTextNode(name, pair.name); if (pair.value !== undefined && pair.value !== null) { - const value = createElementNS(WFSNS, 'Value'); + const value = createElementNS(ns, 'Value'); node.appendChild(value); if ( pair.value && @@ -843,6 +901,9 @@ const GETFEATURE_SERIALIZERS = { 'http://www.opengis.net/wfs': { 'Query': makeChildAppender(writeQuery), }, + 'http://www.opengis.net/wfs/2.0': { + 'Query': makeChildAppender(writeQuery), + }, 'http://www.opengis.net/ogc': { 'During': makeChildAppender(writeDuringFilter), 'And': makeChildAppender(writeLogicalFilter), @@ -862,6 +923,25 @@ const GETFEATURE_SERIALIZERS = { 'PropertyIsBetween': makeChildAppender(writeIsBetweenFilter), 'PropertyIsLike': makeChildAppender(writeIsLikeFilter), }, + 'http://www.opengis.net/ogc/1.1': { + 'During': makeChildAppender(writeDuringFilter), + 'And': makeChildAppender(writeLogicalFilter), + 'Or': makeChildAppender(writeLogicalFilter), + 'Not': makeChildAppender(writeNotFilter), + 'BBOX': makeChildAppender(writeBboxFilter), + 'Contains': makeChildAppender(writeContainsFilter), + 'Intersects': makeChildAppender(writeIntersectsFilter), + 'Within': makeChildAppender(writeWithinFilter), + 'PropertyIsEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsNotEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsLessThan': makeChildAppender(writeComparisonFilter), + 'PropertyIsLessThanOrEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsGreaterThan': makeChildAppender(writeComparisonFilter), + 'PropertyIsGreaterThanOrEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsNull': makeChildAppender(writeIsNullFilter), + 'PropertyIsBetween': makeChildAppender(writeIsBetweenFilter), + 'PropertyIsLike': makeChildAppender(writeIsLikeFilter), + }, }; /** @@ -871,6 +951,7 @@ const GETFEATURE_SERIALIZERS = { */ function writeQuery(node, featureType, objectStack) { const context = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const version = context['version']; const featurePrefix = context['featurePrefix']; const featureNS = context['featureNS']; const propertyNames = context['propertyNames']; @@ -903,7 +984,7 @@ function writeQuery(node, featureType, objectStack) { ); const filter = context['filter']; if (filter) { - const child = createElementNS(OGCNS, 'Filter'); + const child = createElementNS(OGCNS[version], 'Filter'); node.appendChild(child); writeFilterCondition(child, filter, objectStack); } @@ -915,8 +996,10 @@ function writeQuery(node, featureType, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeFilterCondition(node, filter, objectStack) { + const context = /** @type {Object} */ (objectStack[objectStack.length - 1]); /** @type {import("../xml.js").NodeStackItem} */ const item = {node: node}; + assign(item, {context: context}); pushSerializeAndPop( item, GETFEATURE_SERIALIZERS, @@ -932,10 +1015,12 @@ function writeFilterCondition(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeBboxFilter(node, filter, objectStack) { - const context = objectStack[objectStack.length - 1]; + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; context['srsName'] = filter.srsName; + const ns = OGCNS[context['version']]; - writeOgcPropertyName(node, filter.geometryName); + writeOgcPropertyName(ns, node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.extent, objectStack); } @@ -945,10 +1030,12 @@ function writeBboxFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeContainsFilter(node, filter, objectStack) { - const context = objectStack[objectStack.length - 1]; + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; context['srsName'] = filter.srsName; + const ns = OGCNS[context['version']]; - writeOgcPropertyName(node, filter.geometryName); + writeOgcPropertyName(ns, node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); } @@ -958,10 +1045,12 @@ function writeContainsFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeIntersectsFilter(node, filter, objectStack) { - const context = objectStack[objectStack.length - 1]; + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; context['srsName'] = filter.srsName; + const ns = OGCNS[context['version']]; - writeOgcPropertyName(node, filter.geometryName); + writeOgcPropertyName(ns, node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); } @@ -971,10 +1060,12 @@ function writeIntersectsFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeWithinFilter(node, filter, objectStack) { - const context = objectStack[objectStack.length - 1]; + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; context['srsName'] = filter.srsName; + const ns = OGCNS[context['version']]; - writeOgcPropertyName(node, filter.geometryName); + writeOgcPropertyName(ns, node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); } @@ -1007,8 +1098,11 @@ function writeDuringFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeLogicalFilter(node, filter, objectStack) { + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; /** @type {import("../xml.js").NodeStackItem} */ const item = {node: node}; + assign(item, {context}); const conditions = filter.conditions; for (let i = 0, ii = conditions.length; i < ii; ++i) { const condition = conditions[i]; @@ -1028,8 +1122,11 @@ function writeLogicalFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeNotFilter(node, filter, objectStack) { + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; /** @type {import("../xml.js").NodeStackItem} */ const item = {node: node}; + assign(item, {context}); const condition = filter.condition; pushSerializeAndPop( item, @@ -1046,11 +1143,14 @@ function writeNotFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeComparisonFilter(node, filter, objectStack) { + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; + const ns = OGCNS[context['version']]; if (filter.matchCase !== undefined) { node.setAttribute('matchCase', filter.matchCase.toString()); } - writeOgcPropertyName(node, filter.propertyName); - writeOgcLiteral(node, '' + filter.expression); + writeOgcPropertyName(ns, node, filter.propertyName); + writeOgcLiteral(ns, node, '' + filter.expression); } /** @@ -1059,7 +1159,10 @@ function writeComparisonFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeIsNullFilter(node, filter, objectStack) { - writeOgcPropertyName(node, filter.propertyName); + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; + const ns = OGCNS[context['version']]; + writeOgcPropertyName(ns, node, filter.propertyName); } /** @@ -1068,15 +1171,19 @@ function writeIsNullFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeIsBetweenFilter(node, filter, objectStack) { - writeOgcPropertyName(node, filter.propertyName); + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; + const ns = OGCNS[context['version']]; - const lowerBoundary = createElementNS(OGCNS, 'LowerBoundary'); + writeOgcPropertyName(ns, node, filter.propertyName); + + const lowerBoundary = createElementNS(ns, 'LowerBoundary'); node.appendChild(lowerBoundary); - writeOgcLiteral(lowerBoundary, '' + filter.lowerBoundary); + writeOgcLiteral(ns, lowerBoundary, '' + filter.lowerBoundary); - const upperBoundary = createElementNS(OGCNS, 'UpperBoundary'); + const upperBoundary = createElementNS(ns, 'UpperBoundary'); node.appendChild(upperBoundary); - writeOgcLiteral(upperBoundary, '' + filter.upperBoundary); + writeOgcLiteral(ns, upperBoundary, '' + filter.upperBoundary); } /** @@ -1085,41 +1192,47 @@ function writeIsBetweenFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeIsLikeFilter(node, filter, objectStack) { + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; + const ns = OGCNS[context['version']]; node.setAttribute('wildCard', filter.wildCard); node.setAttribute('singleChar', filter.singleChar); node.setAttribute('escapeChar', filter.escapeChar); if (filter.matchCase !== undefined) { node.setAttribute('matchCase', filter.matchCase.toString()); } - writeOgcPropertyName(node, filter.propertyName); - writeOgcLiteral(node, '' + filter.pattern); + writeOgcPropertyName(ns, node, filter.propertyName); + writeOgcLiteral(ns, node, '' + filter.pattern); } /** + * @param {string} ns Namespace. * @param {string} tagName Tag name. * @param {Node} node Node. * @param {string} value Value. */ -function writeOgcExpression(tagName, node, value) { - const property = createElementNS(OGCNS, tagName); +function writeOgcExpression(ns, tagName, node, value) { + const property = createElementNS(ns, tagName); writeStringTextNode(property, value); node.appendChild(property); } /** + * @param {string} ns Namespace. * @param {Node} node Node. * @param {string} value PropertyName value. */ -function writeOgcPropertyName(node, value) { - writeOgcExpression('PropertyName', node, value); +function writeOgcPropertyName(ns, node, value) { + writeOgcExpression(ns, 'PropertyName', node, value); } /** + * @param {string} ns Namespace. * @param {Node} node Node. * @param {string} value PropertyName value. */ -function writeOgcLiteral(node, value) { - writeOgcExpression('Literal', node, value); +function writeOgcLiteral(ns, node, value) { + writeOgcExpression(ns, 'Literal', node, value); } /** @@ -1139,12 +1252,20 @@ function writeTimeInstant(node, time) { * Encode filter as WFS `Filter` and return the Node. * * @param {import("./filter/Filter.js").default} filter Filter. + * @param {string} version Version. * @return {Node} Result. * @api */ -export function writeFilter(filter) { - const child = createElementNS(OGCNS, 'Filter'); - writeFilterCondition(child, filter, []); +export function writeFilter(filter, version) { + const child = createElementNS(OGCNS[version], 'Filter'); + const context = { + node: child, + }; + assign(context, { + 'version': version, + 'filter': filter, + }); + writeFilterCondition(child, filter, [context]); return child; } diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index 94fe9abe9e..058aab97af 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1376,7 +1376,8 @@ describe('ol.format.WFS', function () { andFilter( likeFilter('name', 'Mississippi*'), equalToFilter('waterway', 'riverbank') - ) + ), + '1.1.0' ); expect(serialized).to.xmleql(parse(text)); }); From c675ce5217be4ac1efa37f0178404e0aa9ca7568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Sun, 9 Aug 2020 22:47:03 +0200 Subject: [PATCH 02/10] Fix srsName wrong context --- src/ol/format/WFS.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index d8d277100b..4d317203e6 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -301,7 +301,7 @@ class WFS extends XMLFeature { readFeaturesFromNode(node, opt_options) { /** @type {import("../xml.js").NodeStackItem} */ const context = { - node: node, + node, }; assign(context, { 'featureType': this.featureType_, @@ -494,7 +494,7 @@ class WFS extends XMLFeature { ); /** @type {import("../xml.js").NodeStackItem} */ const context = { - node: node, + node, }; assign(context, { 'version': this.version_, @@ -551,7 +551,7 @@ class WFS extends XMLFeature { : FEATURE_PREFIX; if (inserts) { obj = assign( - {node: node}, + {node}, { version, 'featureNS': options.featureNS, @@ -573,7 +573,7 @@ class WFS extends XMLFeature { } if (updates) { obj = assign( - {node: node}, + {node}, { version, 'featureNS': options.featureNS, @@ -832,7 +832,7 @@ function writeUpdate(node, feature, objectStack) { /** @type {import("../xml.js").NodeStackItem} */ ({ version, 'gmlVersion': context['gmlVersion'], - node: node, + node, 'hasZ': context['hasZ'], 'srsName': context['srsName'], }), @@ -998,8 +998,8 @@ function writeQuery(node, featureType, objectStack) { function writeFilterCondition(node, filter, objectStack) { const context = /** @type {Object} */ (objectStack[objectStack.length - 1]); /** @type {import("../xml.js").NodeStackItem} */ - const item = {node: node}; - assign(item, {context: context}); + const item = {node}; + assign(item, {context}); pushSerializeAndPop( item, GETFEATURE_SERIALIZERS, @@ -1017,7 +1017,7 @@ function writeFilterCondition(node, filter, objectStack) { function writeBboxFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; - context['srsName'] = filter.srsName; + parent['srsName'] = filter.srsName; const ns = OGCNS[context['version']]; writeOgcPropertyName(ns, node, filter.geometryName); @@ -1032,7 +1032,7 @@ function writeBboxFilter(node, filter, objectStack) { function writeContainsFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; - context['srsName'] = filter.srsName; + parent['srsName'] = filter.srsName; const ns = OGCNS[context['version']]; writeOgcPropertyName(ns, node, filter.geometryName); @@ -1047,7 +1047,7 @@ function writeContainsFilter(node, filter, objectStack) { function writeIntersectsFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; - context['srsName'] = filter.srsName; + parent['srsName'] = filter.srsName; const ns = OGCNS[context['version']]; writeOgcPropertyName(ns, node, filter.geometryName); @@ -1062,7 +1062,7 @@ function writeIntersectsFilter(node, filter, objectStack) { function writeWithinFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; - context['srsName'] = filter.srsName; + parent['srsName'] = filter.srsName; const ns = OGCNS[context['version']]; writeOgcPropertyName(ns, node, filter.geometryName); @@ -1101,7 +1101,7 @@ function writeLogicalFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; /** @type {import("../xml.js").NodeStackItem} */ - const item = {node: node}; + const item = {node}; assign(item, {context}); const conditions = filter.conditions; for (let i = 0, ii = conditions.length; i < ii; ++i) { @@ -1125,7 +1125,7 @@ function writeNotFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; /** @type {import("../xml.js").NodeStackItem} */ - const item = {node: node}; + const item = {node}; assign(item, {context}); const condition = filter.condition; pushSerializeAndPop( From daa0824b17c585d5b9b48c1693e4a1fb35c3797d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Sun, 9 Aug 2020 23:28:22 +0200 Subject: [PATCH 03/10] Refactor transaction serialization --- src/ol/format/WFS.js | 127 ++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 73 deletions(-) diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index 4d317203e6..bf7f73f2ad 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -529,12 +529,11 @@ class WFS extends XMLFeature { const objectStack = []; const version = options.version ? options.version : this.version_; const node = createElementNS(WFSNS[version], 'Transaction'); - const gmlVersion = version === '1.0.0' ? 2 : 3; + node.setAttribute('service', 'WFS'); node.setAttribute('version', version); let baseObj; /** @type {import("../xml.js").NodeStackItem} */ - let obj; if (options) { baseObj = options.gmlOptions ? options.gmlOptions : {}; if (options.handle) { @@ -546,85 +545,23 @@ class WFS extends XMLFeature { 'xsi:schemaLocation', SCHEMA_LOCATIONS[version] ); - const featurePrefix = options.featurePrefix - ? options.featurePrefix - : FEATURE_PREFIX; + + const request = createTransactionRequest(node, baseObj, version, options); if (inserts) { - obj = assign( - {node}, - { - version, - 'featureNS': options.featureNS, - 'featureType': options.featureType, - 'featurePrefix': featurePrefix, - 'gmlVersion': gmlVersion, - 'hasZ': options.hasZ, - 'srsName': options.srsName, - } - ); - assign(obj, baseObj); - pushSerializeAndPop( - obj, - TRANSACTION_SERIALIZERS, - makeSimpleNodeFactory('Insert'), - inserts, - objectStack - ); + serializeTransactionRequest('Insert', inserts, objectStack, request); } if (updates) { - obj = assign( - {node}, - { - version, - 'featureNS': options.featureNS, - 'featureType': options.featureType, - 'featurePrefix': featurePrefix, - 'gmlVersion': gmlVersion, - 'hasZ': options.hasZ, - 'srsName': options.srsName, - } - ); - assign(obj, baseObj); - pushSerializeAndPop( - obj, - TRANSACTION_SERIALIZERS, - makeSimpleNodeFactory('Update'), - updates, - objectStack - ); + serializeTransactionRequest('Update', updates, objectStack, request); } if (deletes) { - pushSerializeAndPop( - { - node, - version, - 'featureNS': options.featureNS, - 'featureType': options.featureType, - 'featurePrefix': featurePrefix, - 'gmlVersion': gmlVersion, - 'srsName': options.srsName, - }, - TRANSACTION_SERIALIZERS, - makeSimpleNodeFactory('Delete'), - deletes, - objectStack - ); + serializeTransactionRequest('Delete', deletes, objectStack, request); } if (options.nativeElements) { - pushSerializeAndPop( - { - node, - version, - 'featureNS': options.featureNS, - 'featureType': options.featureType, - 'featurePrefix': featurePrefix, - 'gmlVersion': gmlVersion, - 'srsName': options.srsName, - }, - TRANSACTION_SERIALIZERS, - makeSimpleNodeFactory('Native'), + serializeTransactionRequest( + 'Native', options.nativeElements, - objectStack + objectStack, + request ); } return node; @@ -668,6 +605,50 @@ class WFS extends XMLFeature { } } +/** + * @param {Element} node Node. + * @param {*} baseObj Base object. + * @param {string} version Version. + * @param {WriteTransactionOptions} options Options. + * @return {Object} Request object. + */ +function createTransactionRequest(node, baseObj, version, options) { + const featurePrefix = options.featurePrefix + ? options.featurePrefix + : FEATURE_PREFIX; + const gmlVersion = version === '1.0.0' ? 2 : 3; + const obj = assign( + {node}, + { + version, + 'featureNS': options.featureNS, + 'featureType': options.featureType, + 'featurePrefix': featurePrefix, + 'gmlVersion': gmlVersion, + 'hasZ': options.hasZ, + 'srsName': options.srsName, + }, + baseObj + ); + return obj; +} + +/** + * @param {string} type Request type. + * @param {Array} features Features. + * @param {Array<*>} objectStack Object stack. + * @param {Element} request Transaction Request. + */ +function serializeTransactionRequest(type, features, objectStack, request) { + pushSerializeAndPop( + request, + TRANSACTION_SERIALIZERS, + makeSimpleNodeFactory(type), + features, + objectStack + ); +} + /** * @param {Element} node Node. * @param {Array<*>} objectStack Object stack. From a58bff09810b1d64f2eaab107678c853222d7138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Mon, 10 Aug 2020 03:50:39 +0200 Subject: [PATCH 04/10] Initial GetFeature verification --- src/ol/format/WFS.js | 48 +++++++++++++++++--- src/ol/format/filter.js | 5 ++ src/ol/format/filter/ResourceId.js | 25 ++++++++++ test/spec/ol/format/wfs.test.js | 25 ++++++++++ test/spec/ol/format/wfs/2.0.0/GetFeature.xml | 20 ++++++++ 5 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 src/ol/format/filter/ResourceId.js create mode 100644 test/spec/ol/format/wfs/2.0.0/GetFeature.xml diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index bf7f73f2ad..0c94a31819 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -205,16 +205,20 @@ const WFSNS = { }; /** - * @type {string} + * @type {Object} */ -const FESNS = 'http://www.opengis.net/fes'; +const FESNS = { + '2.0.0': 'http://www.opengis.net/fes/2.0', + '1.1.0': 'http://www.opengis.net/fes', + '1.0.0': 'http://www.opengis.net/fes', +}; /** * @type {Object} */ const SCHEMA_LOCATIONS = { '2.0.0': - 'http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0.0/wfs.xsd', + 'http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd', '1.1.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd', '1.0.0': @@ -904,7 +908,7 @@ const GETFEATURE_SERIALIZERS = { 'PropertyIsBetween': makeChildAppender(writeIsBetweenFilter), 'PropertyIsLike': makeChildAppender(writeIsLikeFilter), }, - 'http://www.opengis.net/ogc/1.1': { + 'http://www.opengis.net/fes/2.0': { 'During': makeChildAppender(writeDuringFilter), 'And': makeChildAppender(writeLogicalFilter), 'Or': makeChildAppender(writeLogicalFilter), @@ -912,6 +916,7 @@ const GETFEATURE_SERIALIZERS = { 'BBOX': makeChildAppender(writeBboxFilter), 'Contains': makeChildAppender(writeContainsFilter), 'Intersects': makeChildAppender(writeIntersectsFilter), + 'ResourceId': makeChildAppender(writeResourceIdFilter), 'Within': makeChildAppender(writeWithinFilter), 'PropertyIsEqualTo': makeChildAppender(writeComparisonFilter), 'PropertyIsNotEqualTo': makeChildAppender(writeComparisonFilter), @@ -944,7 +949,13 @@ function writeQuery(node, featureType, objectStack) { } else { typeName = featureType; } - node.setAttribute('typeName', typeName); + let typeNameAttr; + if (version === '2.0.0') { + typeNameAttr = 'typeNames'; + } else { + typeNameAttr = 'typeName'; + } + node.setAttribute(typeNameAttr, typeName); if (srsName) { node.setAttribute('srsName', srsName); } @@ -965,7 +976,7 @@ function writeQuery(node, featureType, objectStack) { ); const filter = context['filter']; if (filter) { - const child = createElementNS(OGCNS[version], 'Filter'); + const child = createElementNS(getFilterNS(version), 'Filter'); node.appendChild(child); writeFilterCondition(child, filter, objectStack); } @@ -1035,6 +1046,15 @@ function writeIntersectsFilter(node, filter, objectStack) { GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); } +/** + * @param {Element} node Element. + * @param {import("./filter/ResourceId.js").default} filter Filter. + * @param {Array<*>} objectStack Node stack. + */ +function writeResourceIdFilter(node, filter, objectStack) { + node.setAttribute('rid', /** @type {string} */ (filter.rid)); +} + /** * @param {Node} node Node. * @param {import("./filter/Within.js").default} filter Filter. @@ -1056,7 +1076,11 @@ function writeWithinFilter(node, filter, objectStack) { * @param {Array<*>} objectStack Node stack. */ function writeDuringFilter(node, filter, objectStack) { - const valueReference = createElementNS(FESNS, 'ValueReference'); + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; + const version = context['version']; + const ns = FESNS[version]; + const valueReference = createElementNS(ns, 'ValueReference'); writeStringTextNode(valueReference, filter.propertyName); node.appendChild(valueReference); @@ -1271,4 +1295,14 @@ function writeGetFeature(node, featureTypes, objectStack) { ); } +function getFilterNS(version) { + let ns; + if (version === '2.0.0') { + ns = FESNS[version]; + } else { + ns = OGCNS[version]; + } + return ns; +} + export default WFS; diff --git a/src/ol/format/filter.js b/src/ol/format/filter.js index c4d2c9615d..99490840f0 100644 --- a/src/ol/format/filter.js +++ b/src/ol/format/filter.js @@ -17,6 +17,7 @@ import LessThanOrEqualTo from './filter/LessThanOrEqualTo.js'; import Not from './filter/Not.js'; import NotEqualTo from './filter/NotEqualTo.js'; import Or from './filter/Or.js'; +import ResourceId from './filter/ResourceId.js'; import Within from './filter/Within.js'; /** @@ -260,3 +261,7 @@ export function like( export function during(propertyName, begin, end) { return new During(propertyName, begin, end); } + +export function resourceId(rid) { + return new ResourceId(rid); +} diff --git a/src/ol/format/filter/ResourceId.js b/src/ol/format/filter/ResourceId.js new file mode 100644 index 0000000000..d68a6bcf75 --- /dev/null +++ b/src/ol/format/filter/ResourceId.js @@ -0,0 +1,25 @@ +/** + * @module ol/format/filter/ResourceId + */ +import Filter from './Filter.js'; + +/** + * @classdesc + * + * @abstract + */ +class ResourceId extends Filter { + /** + * @param {!string} rid Resource ID. + */ + constructor(rid) { + super('ResourceId'); + + /** + * @type {!string} + */ + this.rid = rid; + } +} + +export default ResourceId; diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index 058aab97af..89f39d13cc 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -27,6 +27,7 @@ import { like as likeFilter, not as notFilter, or as orFilter, + resourceId as resourceIdFilter, within as withinFilter, } from '../../../../src/ol/format/filter.js'; import {parse} from '../../../../src/ol/xml.js'; @@ -1382,4 +1383,28 @@ describe('ol.format.WFS', function () { expect(serialized).to.xmleql(parse(text)); }); }); + + describe('WFS 2.0.0', function () { + let getFeatureXml; + before(function (done) { + afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature.xml', function (xml) { + getFeatureXml = xml; + done(); + }); + }); + + it('GetFeature', function () { + const wfs = new WFS({ + version: '2.0.0', + }); + const filter = resourceIdFilter('bugsites.3'); + const serialized = wfs.writeGetFeature({ + featureNS: 'http://www.openplans.org/spearfish', + featureTypes: ['bugsites'], + featurePrefix: 'sf', + filter, + }); + expect(serialized).to.xmleql(parse(getFeatureXml)); + }); + }); }); diff --git a/test/spec/ol/format/wfs/2.0.0/GetFeature.xml b/test/spec/ol/format/wfs/2.0.0/GetFeature.xml new file mode 100644 index 0000000000..20e1b43f8c --- /dev/null +++ b/test/spec/ol/format/wfs/2.0.0/GetFeature.xml @@ -0,0 +1,20 @@ + + + + + + + + + From 01f355c37f5e92649d9c752ed91a2043e8ba0620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Mon, 10 Aug 2020 21:30:06 +0200 Subject: [PATCH 05/10] Verify GetFeature with more complex filter --- src/ol/format/WFS.js | 108 ++++++++++++++---- src/ol/format/filter.js | 16 +++ src/ol/format/filter/Disjoint.js | 24 ++++ test/spec/ol/format/wfs.test.js | 56 ++++++++- test/spec/ol/format/wfs/2.0.0/GetFeature2.xml | 41 +++++++ 5 files changed, 217 insertions(+), 28 deletions(-) create mode 100644 src/ol/format/filter/Disjoint.js create mode 100644 test/spec/ol/format/wfs/2.0.0/GetFeature2.xml diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index 0c94a31819..a2985a97dd 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -3,6 +3,7 @@ */ import GML2 from './GML2.js'; import GML3 from './GML3.js'; +import GML32 from './GML32.js'; import GMLBase, {GMLNS} from './GMLBase.js'; import XMLFeature from './XMLFeature.js'; import { @@ -225,6 +226,15 @@ const SCHEMA_LOCATIONS = { 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd', }; +/** + * @type {Object} + */ +const GML_FORMATS = { + '2.0.0': GML32, + '1.1.0': GML3, + '1.0.0': GML2, +}; + /** * @const * @type {string} @@ -271,7 +281,9 @@ class WFS extends XMLFeature { * @private * @type {GMLBase} */ - this.gmlFormat_ = options.gmlFormat ? options.gmlFormat : new GML3(); + this.gmlFormat_ = options.gmlFormat + ? options.gmlFormat + : new GML_FORMATS[this.version_](); /** * @private @@ -620,7 +632,14 @@ function createTransactionRequest(node, baseObj, version, options) { const featurePrefix = options.featurePrefix ? options.featurePrefix : FEATURE_PREFIX; - const gmlVersion = version === '1.0.0' ? 2 : 3; + let gmlVersion; + if (version === '1.0.0') { + gmlVersion = 2; + } else if (version === '1.1.0') { + gmlVersion = 3; + } else if (version === '2.0.0') { + gmlVersion = 3.2; + } const obj = assign( {node}, { @@ -723,8 +742,10 @@ function writeFeature(node, feature, objectStack) { node.appendChild(child); if (gmlVersion === 2) { GML2.prototype.writeFeatureElement(child, feature, objectStack); - } else { + } else if (gmlVersion === 3) { GML3.prototype.writeFeatureElement(child, feature, objectStack); + } else { + GML32.prototype.writeFeatureElement(child, feature, objectStack); } } @@ -853,8 +874,10 @@ function writeProperty(node, pair, objectStack) { ) { if (gmlVersion === 2) { GML2.prototype.writeGeometryElement(value, pair.value, objectStack); - } else { + } else if (gmlVersion === 3) { GML3.prototype.writeGeometryElement(value, pair.value, objectStack); + } else { + GML32.prototype.writeGeometryElement(value, pair.value, objectStack); } } else { writeStringTextNode(value, pair.value); @@ -915,6 +938,7 @@ const GETFEATURE_SERIALIZERS = { 'Not': makeChildAppender(writeNotFilter), 'BBOX': makeChildAppender(writeBboxFilter), 'Contains': makeChildAppender(writeContainsFilter), + 'Disjoint': makeChildAppender(writeDisjointFilter), 'Intersects': makeChildAppender(writeIntersectsFilter), 'ResourceId': makeChildAppender(writeResourceIdFilter), 'Within': makeChildAppender(writeWithinFilter), @@ -1009,11 +1033,12 @@ function writeFilterCondition(node, filter, objectStack) { function writeBboxFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; + const version = context['version']; parent['srsName'] = filter.srsName; - const ns = OGCNS[context['version']]; + const format = GML_FORMATS[version]; - writeOgcPropertyName(ns, node, filter.geometryName); - GML3.prototype.writeGeometryElement(node, filter.extent, objectStack); + writePropertyName(version, node, filter.geometryName); + format.prototype.writeGeometryElement(node, filter.extent, objectStack); } /** @@ -1024,11 +1049,12 @@ function writeBboxFilter(node, filter, objectStack) { function writeContainsFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; + const version = context['version']; parent['srsName'] = filter.srsName; - const ns = OGCNS[context['version']]; + const format = GML_FORMATS[version]; - writeOgcPropertyName(ns, node, filter.geometryName); - GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); + writePropertyName(version, node, filter.geometryName); + format.prototype.writeGeometryElement(node, filter.geometry, objectStack); } /** @@ -1039,11 +1065,28 @@ function writeContainsFilter(node, filter, objectStack) { function writeIntersectsFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; + const version = context['version']; parent['srsName'] = filter.srsName; - const ns = OGCNS[context['version']]; + const format = GML_FORMATS[version]; - writeOgcPropertyName(ns, node, filter.geometryName); - GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); + writePropertyName(version, node, filter.geometryName); + format.prototype.writeGeometryElement(node, filter.geometry, objectStack); +} + +/** + * @param {Node} node Node. + * @param {import("./filter/Disjoint.js").default} filter Filter. + * @param {Array<*>} objectStack Node stack. + */ +function writeDisjointFilter(node, filter, objectStack) { + const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); + const context = parent['context']; + const version = context['version']; + parent['srsName'] = filter.srsName; + const format = GML_FORMATS[version]; + + writePropertyName(version, node, filter.geometryName); + format.prototype.writeGeometryElement(node, filter.geometry, objectStack); } /** @@ -1063,11 +1106,12 @@ function writeResourceIdFilter(node, filter, objectStack) { function writeWithinFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; + const version = context['version']; parent['srsName'] = filter.srsName; - const ns = OGCNS[context['version']]; + const format = GML_FORMATS[version]; - writeOgcPropertyName(ns, node, filter.geometryName); - GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); + writePropertyName(version, node, filter.geometryName); + format.prototype.writeGeometryElement(node, filter.geometry, objectStack); } /** @@ -1150,11 +1194,12 @@ function writeNotFilter(node, filter, objectStack) { function writeComparisonFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; + const version = context['version']; const ns = OGCNS[context['version']]; if (filter.matchCase !== undefined) { node.setAttribute('matchCase', filter.matchCase.toString()); } - writeOgcPropertyName(ns, node, filter.propertyName); + writePropertyName(version, node, filter.propertyName); writeOgcLiteral(ns, node, '' + filter.expression); } @@ -1166,8 +1211,8 @@ function writeComparisonFilter(node, filter, objectStack) { function writeIsNullFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; - const ns = OGCNS[context['version']]; - writeOgcPropertyName(ns, node, filter.propertyName); + const version = context['version']; + writePropertyName(version, node, filter.propertyName); } /** @@ -1178,9 +1223,10 @@ function writeIsNullFilter(node, filter, objectStack) { function writeIsBetweenFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; + const version = context['version']; const ns = OGCNS[context['version']]; - writeOgcPropertyName(ns, node, filter.propertyName); + writePropertyName(version, node, filter.propertyName); const lowerBoundary = createElementNS(ns, 'LowerBoundary'); node.appendChild(lowerBoundary); @@ -1199,14 +1245,15 @@ function writeIsBetweenFilter(node, filter, objectStack) { function writeIsLikeFilter(node, filter, objectStack) { const parent = /** @type {Object} */ (objectStack[objectStack.length - 1]); const context = parent['context']; - const ns = OGCNS[context['version']]; + const version = context['version']; + const ns = OGCNS[version]; node.setAttribute('wildCard', filter.wildCard); node.setAttribute('singleChar', filter.singleChar); node.setAttribute('escapeChar', filter.escapeChar); if (filter.matchCase !== undefined) { node.setAttribute('matchCase', filter.matchCase.toString()); } - writeOgcPropertyName(ns, node, filter.propertyName); + writePropertyName(version, node, filter.propertyName); writeOgcLiteral(ns, node, '' + filter.pattern); } @@ -1222,13 +1269,26 @@ function writeOgcExpression(ns, tagName, node, value) { node.appendChild(property); } +/** + * @param {string} version Version. + * @param {Node} node Node. + * @param {string} value PropertyName value. + */ +function writePropertyName(version, node, value) { + if (version === '2.0.0') { + writeFesValueReference(FESNS[version], node, value); + } else { + writeOgcExpression(OGCNS[version], 'PropertyName', node, value); + } +} + /** * @param {string} ns Namespace. * @param {Node} node Node. * @param {string} value PropertyName value. */ -function writeOgcPropertyName(ns, node, value) { - writeOgcExpression(ns, 'PropertyName', node, value); +function writeFesValueReference(ns, node, value) { + writeOgcExpression(ns, 'ValueReference', node, value); } /** diff --git a/src/ol/format/filter.js b/src/ol/format/filter.js index 99490840f0..05c8be7904 100644 --- a/src/ol/format/filter.js +++ b/src/ol/format/filter.js @@ -4,6 +4,7 @@ import And from './filter/And.js'; import Bbox from './filter/Bbox.js'; import Contains from './filter/Contains.js'; +import Disjoint from './filter/Disjoint.js'; import During from './filter/During.js'; import EqualTo from './filter/EqualTo.js'; import GreaterThan from './filter/GreaterThan.js'; @@ -100,6 +101,21 @@ export function intersects(geometryName, geometry, opt_srsName) { return new Intersects(geometryName, geometry, opt_srsName); } +/** + * Create a `` operator to test whether a geometry-valued property + * is disjoint to a given geometry. + * + * @param {!string} geometryName Geometry name to use. + * @param {!import("../geom/Geometry.js").default} geometry Geometry. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @returns {!Disjoint} `` operator. + * @api + */ +export function disjoint(geometryName, geometry, opt_srsName) { + return new Disjoint(geometryName, geometry, opt_srsName); +} + /** * Create a `` operator to test whether a geometry-valued property * is within a given geometry. diff --git a/src/ol/format/filter/Disjoint.js b/src/ol/format/filter/Disjoint.js new file mode 100644 index 0000000000..a3601c55a2 --- /dev/null +++ b/src/ol/format/filter/Disjoint.js @@ -0,0 +1,24 @@ +/** + * @module ol/format/filter/Disjoint + */ +import Spatial from './Spatial.js'; + +/** + * @classdesc + * Represents a `` operator to test whether a geometry-valued property + * is disjoint to a given geometry. + * @api + */ +class Disjoint extends Spatial { + /** + * @param {!string} geometryName Geometry name to use. + * @param {!import("../../geom/Geometry.js").default} geometry Geometry. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + */ + constructor(geometryName, geometry, opt_srsName) { + super('Disjoint', geometryName, geometry, opt_srsName); + } +} + +export default Disjoint; diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index 89f39d13cc..b8c5fd5e9b 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1,5 +1,6 @@ import Feature from '../../../../src/ol/Feature.js'; import GML2 from '../../../../src/ol/format/GML2.js'; +import GML32 from '../../../../src/ol/format/GML32.js'; import LineString from '../../../../src/ol/geom/LineString.js'; import MultiLineString from '../../../../src/ol/geom/MultiLineString.js'; import MultiPoint from '../../../../src/ol/geom/MultiPoint.js'; @@ -16,6 +17,7 @@ import { bbox as bboxFilter, between as betweenFilter, contains as containsFilter, + disjoint as disjointFilter, during as duringFilter, equalTo as equalToFilter, greaterThan as greaterThanFilter, @@ -1386,14 +1388,32 @@ describe('ol.format.WFS', function () { describe('WFS 2.0.0', function () { let getFeatureXml; + let getFeatureXml2; + before(function (done) { - afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature.xml', function (xml) { - getFeatureXml = xml; - done(); + proj4.defs( + 'http://www.opengis.net/def/crs/EPSG/0/26713', + '+proj=utm +zone=13 +ellps=clrk66 +datum=NAD27 +units=m +no_defs' + ); + register(proj4); + afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature2.xml', function (xml) { + getFeatureXml2 = xml; + afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature.xml', function ( + xml + ) { + getFeatureXml = xml; + done(); + }); }); }); - it('GetFeature', function () { + after(function () { + delete proj4.defs['http://www.opengis.net/def/crs/EPSG/0/26713']; + clearAllProjections(); + addCommon(); + }); + + it('can writeGetFeature query with simple resourceId filter', function () { const wfs = new WFS({ version: '2.0.0', }); @@ -1406,5 +1426,33 @@ describe('ol.format.WFS', function () { }); expect(serialized).to.xmleql(parse(getFeatureXml)); }); + + it('can writeGetFeature query with negated disjoint spatial filter', function () { + const wfs = new WFS({ + version: '2.0.0', + }); + const geometryNode = parse( + ` + + + + 590431 4915204 590430 + 4915205 590429 4915204 590430 + 4915203 590431 4915204 + + + ` + ); + const geometry = new GML32().readGeometryElement(geometryNode, [{}]); + const filter = notFilter(disjointFilter('sf:the_geom', geometry)); + const serialized = wfs.writeGetFeature({ + featureNS: 'http://www.openplans.org/spearfish', + featureTypes: ['bugsites'], + featurePrefix: 'sf', + filter, + }); + expect(serialized).to.xmleql(parse(getFeatureXml2)); + }); }); }); diff --git a/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml b/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml new file mode 100644 index 0000000000..2e7add1b68 --- /dev/null +++ b/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml @@ -0,0 +1,41 @@ + + + + + + + + sf:the_geom + + + + + + 590431 4915204 590430 + 4915205 590429 4915204 590430 + 4915203 590431 4915204 + + + + + + + + From 0484e45c892423af5c9af31101b8b066584afe5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Tue, 11 Aug 2020 15:46:40 +0200 Subject: [PATCH 06/10] Fix WFS 2.0.0 GetFeature response parsing --- src/ol/format/WFS.js | 14 +- test/spec/ol/format/wfs.test.js | 133 ++++++++++++++---- test/spec/ol/format/wfs/2.0.0/GetFeature.xml | 20 --- test/spec/ol/format/wfs/2.0.0/GetFeature2.xml | 41 ------ 4 files changed, 117 insertions(+), 91 deletions(-) delete mode 100644 test/spec/ol/format/wfs/2.0.0/GetFeature.xml delete mode 100644 test/spec/ol/format/wfs/2.0.0/GetFeature2.xml diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index a2985a97dd..b31fb5b120 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -40,6 +40,9 @@ const FEATURE_COLLECTION_PARSERS = { 'bounds' ), }, + 'http://www.opengis.net/wfs/2.0': { + 'member': makeArrayPusher(GMLBase.prototype.readFeaturesInternal), + }, }; /** @@ -326,12 +329,15 @@ class WFS extends XMLFeature { assign(context, this.getReadOptions(node, opt_options ? opt_options : {})); const objectStack = [context]; - this.gmlFormat_.FEATURE_COLLECTION_PARSERS[GMLNS][ - 'featureMember' - ] = makeArrayPusher(GMLBase.prototype.readFeaturesInternal); + let featuresNS; + if (this.version_ === '2.0.0') { + featuresNS = FEATURE_COLLECTION_PARSERS; + } else { + featuresNS = this.gmlFormat_.FEATURE_COLLECTION_PARSERS; + } let features = pushParseAndPop( [], - this.gmlFormat_.FEATURE_COLLECTION_PARSERS, + featuresNS, node, objectStack, this.gmlFormat_ diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index b8c5fd5e9b..c7aaf5fe89 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1387,28 +1387,113 @@ describe('ol.format.WFS', function () { }); describe('WFS 2.0.0', function () { - let getFeatureXml; - let getFeatureXml2; + const geometryXml = ` + + + + + 590431 4915204 590430 + 4915205 590429 4915204 590430 + 4915203 590431 4915204 + + + + `.trim(); + + const getFeatureSimpleXml = ` + + + + + + + + + + `.trim(); + + const getFeatureComplexXml = ` + + + + + + + + sf:the_geom + ${geometryXml} + + + + + + `.trim(); + + const getFeatureSimpleXmlResponse = ` + + + + + + + 590529 4914625 + + + 3 + Beetle site + + + + `.trim(); before(function (done) { proj4.defs( 'http://www.opengis.net/def/crs/EPSG/0/26713', '+proj=utm +zone=13 +ellps=clrk66 +datum=NAD27 +units=m +no_defs' ); + proj4.defs( + 'urn:ogc:def:crs:EPSG::26713', + '+proj=utm +zone=13 +ellps=clrk66 +datum=NAD27 +units=m +no_defs' + ); register(proj4); - afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature2.xml', function (xml) { - getFeatureXml2 = xml; - afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature.xml', function ( - xml - ) { - getFeatureXml = xml; - done(); - }); - }); + done(); }); after(function () { delete proj4.defs['http://www.opengis.net/def/crs/EPSG/0/26713']; + delete proj4.defs['urn:ogc:def:crs:EPSG::26713']; clearAllProjections(); addCommon(); }); @@ -1424,26 +1509,14 @@ describe('ol.format.WFS', function () { featurePrefix: 'sf', filter, }); - expect(serialized).to.xmleql(parse(getFeatureXml)); + expect(serialized).to.xmleql(parse(getFeatureSimpleXml)); }); it('can writeGetFeature query with negated disjoint spatial filter', function () { const wfs = new WFS({ version: '2.0.0', }); - const geometryNode = parse( - ` - - - - 590431 4915204 590430 - 4915205 590429 4915204 590430 - 4915203 590431 4915204 - - - ` - ); + const geometryNode = parse(geometryXml); const geometry = new GML32().readGeometryElement(geometryNode, [{}]); const filter = notFilter(disjointFilter('sf:the_geom', geometry)); const serialized = wfs.writeGetFeature({ @@ -1452,7 +1525,15 @@ describe('ol.format.WFS', function () { featurePrefix: 'sf', filter, }); - expect(serialized).to.xmleql(parse(getFeatureXml2)); + expect(serialized).to.xmleql(parse(getFeatureComplexXml)); + }); + + it('can parse a basic GetFeature response', function () { + const wfs = new WFS({ + version: '2.0.0', + }); + const features = wfs.readFeatures(parse(getFeatureSimpleXmlResponse)); + expect(features.length).to.be(1); }); }); }); diff --git a/test/spec/ol/format/wfs/2.0.0/GetFeature.xml b/test/spec/ol/format/wfs/2.0.0/GetFeature.xml deleted file mode 100644 index 20e1b43f8c..0000000000 --- a/test/spec/ol/format/wfs/2.0.0/GetFeature.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - diff --git a/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml b/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml deleted file mode 100644 index 2e7add1b68..0000000000 --- a/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - sf:the_geom - - - - - - 590431 4915204 590430 - 4915205 590429 4915204 590430 - 4915203 590431 4915204 - - - - - - - - From 1335937ddd23c8be3ca040c94be751a149900e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Tue, 11 Aug 2020 16:09:43 +0200 Subject: [PATCH 07/10] Verified fix --- src/ol/format/GMLBase.js | 8 ++++++-- test/spec/ol/format/wfs.test.js | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ol/format/GMLBase.js b/src/ol/format/GMLBase.js index 2c90cd2413..5ac3c3788e 100644 --- a/src/ol/format/GMLBase.js +++ b/src/ol/format/GMLBase.js @@ -150,7 +150,11 @@ class GMLBase extends XMLFeature { objectStack, this ); - } else if (localName == 'featureMembers' || localName == 'featureMember') { + } else if ( + localName == 'featureMembers' || + localName == 'featureMember' || + localName == 'member' + ) { const context = objectStack[0]; let featureType = context['featureType']; let featureNS = context['featureNS']; @@ -214,7 +218,7 @@ class GMLBase extends XMLFeature { } parsersNS[featureNS[p]] = parsers; } - if (localName == 'featureMember') { + if (localName == 'featureMember' || localName == 'member') { features = pushParseAndPop(undefined, parsersNS, node, objectStack); } else { features = pushParseAndPop([], parsersNS, node, objectStack); diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index c7aaf5fe89..fc589fc833 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1528,12 +1528,13 @@ describe('ol.format.WFS', function () { expect(serialized).to.xmleql(parse(getFeatureComplexXml)); }); - it('can parse a basic GetFeature response', function () { + it('can parse basic GetFeature response', function () { const wfs = new WFS({ version: '2.0.0', }); const features = wfs.readFeatures(parse(getFeatureSimpleXmlResponse)); expect(features.length).to.be(1); + expect(features[0]).to.be.an(Feature); }); }); }); From 8cddfa0d2264b4244d14fc1f0a71c43d235e613c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Tue, 11 Aug 2020 16:14:39 +0200 Subject: [PATCH 08/10] Refactor tests --- test/spec/ol/format/wfs.test.js | 132 ++++++++++++++++---------------- 1 file changed, 64 insertions(+), 68 deletions(-) diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index fc589fc833..59a33946d8 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1387,20 +1387,28 @@ describe('ol.format.WFS', function () { }); describe('WFS 2.0.0', function () { - const geometryXml = ` - - - - - 590431 4915204 590430 - 4915205 590429 4915204 590430 - 4915203 590431 4915204 - - - - `.trim(); + before(function (done) { + proj4.defs( + 'http://www.opengis.net/def/crs/EPSG/0/26713', + '+proj=utm +zone=13 +ellps=clrk66 +datum=NAD27 +units=m +no_defs' + ); + proj4.defs( + 'urn:ogc:def:crs:EPSG::26713', + '+proj=utm +zone=13 +ellps=clrk66 +datum=NAD27 +units=m +no_defs' + ); + register(proj4); + done(); + }); - const getFeatureSimpleXml = ` + after(function () { + delete proj4.defs['http://www.opengis.net/def/crs/EPSG/0/26713']; + delete proj4.defs['urn:ogc:def:crs:EPSG::26713']; + clearAllProjections(); + addCommon(); + }); + + it('can writeGetFeature query with simple resourceId filter', function () { + const getFeatureXml = ` + 590431 4915204 590430 + 4915205 590429 4915204 590430 + 4915203 590431 4915204 + + + + `.trim(); + const getFeatureXml = `