From 0243ce661244c45732cf5a9aa1cca18b66611de1 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Wed, 7 Jan 2015 11:33:42 +0100 Subject: [PATCH 1/3] Fix up parsing of OGR GML with ol.format.GML --- src/ol/format/gml/gml2format.js | 4 ++-- src/ol/format/gml/gml3format.js | 4 ++-- src/ol/format/gml/gmlbaseformat.js | 20 +++++++++++++------- src/ol/format/wfsformat.js | 3 +++ test/spec/ol/format/gml/ogr.xml | 26 ++++++++++++++++++++++++++ test/spec/ol/format/gmlformat.test.js | 20 ++++++++++++++++++++ 6 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 test/spec/ol/format/gml/ogr.xml diff --git a/src/ol/format/gml/gml2format.js b/src/ol/format/gml/gml2format.js index 4faea336ce..2dd3cfe3e7 100644 --- a/src/ol/format/gml/gml2format.js +++ b/src/ol/format/gml/gml2format.js @@ -43,8 +43,8 @@ goog.inherits(ol.format.GML2, ol.format.GMLBase); * @type {string} * @private */ -ol.format.GML2.schemaLocation_ = 'http://www.opengis.net/gml ' + - 'http://schemas.opengis.net/gml/2.1.2/feature.xsd'; +ol.format.GML2.schemaLocation_ = ol.format.GMLBase.GMLNS + + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd'; /** diff --git a/src/ol/format/gml/gml3format.js b/src/ol/format/gml/gml3format.js index ed9c0bba6f..e04ae9374b 100644 --- a/src/ol/format/gml/gml3format.js +++ b/src/ol/format/gml/gml3format.js @@ -84,8 +84,8 @@ goog.inherits(ol.format.GML3, ol.format.GMLBase); * @type {string} * @private */ -ol.format.GML3.schemaLocation_ = 'http://www.opengis.net/gml ' + - 'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' + +ol.format.GML3.schemaLocation_ = ol.format.GMLBase.GMLNS + + ' http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' + '1.0.0/gmlsf.xsd'; diff --git a/src/ol/format/gml/gmlbaseformat.js b/src/ol/format/gml/gmlbaseformat.js index 96111d0980..47090c868d 100644 --- a/src/ol/format/gml/gmlbaseformat.js +++ b/src/ol/format/gml/gmlbaseformat.js @@ -73,13 +73,19 @@ ol.format.GMLBase = function(opt_options) { goog.inherits(ol.format.GMLBase, ol.format.XMLFeature); +/** + * @const + * @type {string} + */ +ol.format.GMLBase.GMLNS = 'http://www.opengis.net/gml'; + + /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Array.} Features. - * @private */ -ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) { +ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); var localName = ol.xml.getLocalName(node); var features; @@ -117,10 +123,10 @@ ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) { */ ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = Object({ 'http://www.opengis.net/gml': { - 'featureMember': ol.xml.makeArrayPusher( - ol.format.GMLBase.prototype.readFeatures_), + 'featureMember': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readFeaturesInternal), 'featureMembers': ol.xml.makeReplacer( - ol.format.GMLBase.prototype.readFeatures_) + ol.format.GMLBase.prototype.readFeaturesInternal) } }); @@ -153,7 +159,7 @@ ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) { ol.format.GMLBase.prototype.readFeatureElement = function(node, objectStack) { var n; var fid = node.getAttribute('fid') || - ol.xml.getAttributeNS(node, 'http://www.opengis.net/gml', 'id'); + ol.xml.getAttributeNS(node, ol.format.GMLBase.GMLNS, 'id'); var values = {}, geometryName; for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { @@ -549,7 +555,7 @@ ol.format.GMLBase.prototype.readFeaturesFromNode = if (goog.isDef(opt_options)) { goog.object.extend(options, this.getReadOptions(node, opt_options)); } - return this.readFeatures_(node, [options]); + return this.readFeaturesInternal(node, [options]); }; diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 3f09348a5b..540d139506 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -125,6 +125,9 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) { goog.object.extend(context, this.getReadOptions(node, goog.isDef(opt_options) ? opt_options : {})); var objectStack = [context]; + this.gmlFormat_.FEATURE_COLLECTION_PARSERS[ol.format.GMLBase.GMLNS][ + 'featureMember'] = + ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readFeaturesInternal); var features = ol.xml.pushParseAndPop([], this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node, objectStack, this.gmlFormat_); diff --git a/test/spec/ol/format/gml/ogr.xml b/test/spec/ol/format/gml/ogr.xml new file mode 100644 index 0000000000..5ca69e4838 --- /dev/null +++ b/test/spec/ol/format/gml/ogr.xml @@ -0,0 +1,26 @@ + + + + + + + + + 115512.666 479836.28 + + + x2 + NL.IMGEO + L0001.A3C177B4105A4FFD82EB80084C8CA732 + 60 + 2014-02-14 + L0001 + fotogrammetrisch + + + diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 2ec050b3cb..d68aad6d27 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -1087,6 +1087,26 @@ describe('ol.format.GML3', function() { }); + describe('when parsing from OGR', function() { + + var features; + before(function(done) { + afterLoadText('spec/ol/format/gml/ogr.xml', function(xml) { + try { + features = new ol.format.GML().readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('reads all features', function() { + expect(features.length).to.be(1); + }); + + }); + }); From 5d70e617539982b3ca10bea2f0da7dfbbfe11fed Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 30 Jan 2015 21:00:04 +0100 Subject: [PATCH 2/3] Make FEATURE_COLLECTION_PARSERS an instance property --- src/ol/format/gml/gmlbaseformat.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ol/format/gml/gmlbaseformat.js b/src/ol/format/gml/gmlbaseformat.js index 47090c868d..be4378cd20 100644 --- a/src/ol/format/gml/gmlbaseformat.js +++ b/src/ol/format/gml/gmlbaseformat.js @@ -68,6 +68,18 @@ ol.format.GMLBase = function(opt_options) { */ this.schemaLocation = ''; + /** + * @type {Object.>} + */ + this.FEATURE_COLLECTION_PARSERS = Object({ + 'http://www.opengis.net/gml': { + 'featureMember': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readFeaturesInternal), + 'featureMembers': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readFeaturesInternal) + } + }); + goog.base(this); }; goog.inherits(ol.format.GMLBase, ol.format.XMLFeature); @@ -118,19 +130,6 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) { }; -/** - * @type {Object.>} - */ -ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = Object({ - 'http://www.opengis.net/gml': { - 'featureMember': ol.xml.makeReplacer( - ol.format.GMLBase.prototype.readFeaturesInternal), - 'featureMembers': ol.xml.makeReplacer( - ol.format.GMLBase.prototype.readFeaturesInternal) - } -}); - - /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. From 423c8761aa581a252cbad125ca2630b6e04d3619 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 2 Feb 2015 12:46:49 +0100 Subject: [PATCH 3/3] Use ol.format.GMLBase.GMLNS and get rid of unneeded Object --- src/ol/format/gml/gmlbaseformat.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ol/format/gml/gmlbaseformat.js b/src/ol/format/gml/gmlbaseformat.js index be4378cd20..9f4db2c16c 100644 --- a/src/ol/format/gml/gmlbaseformat.js +++ b/src/ol/format/gml/gmlbaseformat.js @@ -71,14 +71,13 @@ ol.format.GMLBase = function(opt_options) { /** * @type {Object.>} */ - this.FEATURE_COLLECTION_PARSERS = Object({ - 'http://www.opengis.net/gml': { - 'featureMember': ol.xml.makeReplacer( - ol.format.GMLBase.prototype.readFeaturesInternal), - 'featureMembers': ol.xml.makeReplacer( - ol.format.GMLBase.prototype.readFeaturesInternal) - } - }); + this.FEATURE_COLLECTION_PARSERS = {}; + this.FEATURE_COLLECTION_PARSERS[ol.format.GMLBase.GMLNS] = { + 'featureMember': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readFeaturesInternal), + 'featureMembers': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readFeaturesInternal) + }; goog.base(this); };