Merge pull request #3099 from bartvde/ogr-gml2

Fix up parsing of OGR GML with ol.format.GML
This commit is contained in:
Bart van den Eijnden
2015-02-02 13:16:12 +01:00
6 changed files with 74 additions and 21 deletions

View File

@@ -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';
/**

View File

@@ -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';

View File

@@ -68,18 +68,35 @@ ol.format.GMLBase = function(opt_options) {
*/
this.schemaLocation = '';
/**
* @type {Object.<string, Object.<string, Object>>}
*/
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);
};
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.<ol.Feature>} 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;
@@ -112,19 +129,6 @@ ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) {
};
/**
* @type {Object.<string, Object.<string, Object>>}
*/
ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = Object({
'http://www.opengis.net/gml': {
'featureMember': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.readFeatures_),
'featureMembers': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readFeatures_)
}
});
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -153,7 +157,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 +553,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]);
};

View File

@@ -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_);

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<wfs:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wfs="http://www.opengis.net/wfs"
xsi:schemaLocation="http://ogr.maptools.org/ test.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:featureMember>
<ogr:Plaatsbepalingspunt fid="Plaatsbepalingspunt.0">
<ogr:geometryProperty>
<gml:Point>
<gml:pos srsDimension="2">115512.666 479836.28</gml:pos>
</gml:Point>
</ogr:geometryProperty>
<ogr:gml_id>x2</ogr:gml_id>
<ogr:namespace>NL.IMGEO</ogr:namespace>
<ogr:lokaalID>L0001.A3C177B4105A4FFD82EB80084C8CA732</ogr:lokaalID>
<ogr:nauwkeurigheid>60</ogr:nauwkeurigheid>
<ogr:datumInwinning>2014-02-14</ogr:datumInwinning>
<ogr:inwinnendeInstantie>L0001</ogr:inwinnendeInstantie>
<ogr:inwinningsmethode>fotogrammetrisch</ogr:inwinningsmethode>
</ogr:Plaatsbepalingspunt>
</gml:featureMember>
</wfs:FeatureCollection>

View File

@@ -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);
});
});
});