Fix up parsing of OGR GML with ol.format.GML
This commit is contained in:
@@ -43,8 +43,8 @@ goog.inherits(ol.format.GML2, ol.format.GMLBase);
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GML2.schemaLocation_ = 'http://www.opengis.net/gml ' +
|
ol.format.GML2.schemaLocation_ = ol.format.GMLBase.GMLNS +
|
||||||
'http://schemas.opengis.net/gml/2.1.2/feature.xsd';
|
' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ goog.inherits(ol.format.GML3, ol.format.GMLBase);
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GML3.schemaLocation_ = 'http://www.opengis.net/gml ' +
|
ol.format.GML3.schemaLocation_ = ol.format.GMLBase.GMLNS +
|
||||||
'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' +
|
' http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' +
|
||||||
'1.0.0/gmlsf.xsd';
|
'1.0.0/gmlsf.xsd';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -73,13 +73,19 @@ ol.format.GMLBase = function(opt_options) {
|
|||||||
goog.inherits(ol.format.GMLBase, ol.format.XMLFeature);
|
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 {Node} node Node.
|
||||||
* @param {Array.<*>} objectStack Object stack.
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @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);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
var localName = ol.xml.getLocalName(node);
|
var localName = ol.xml.getLocalName(node);
|
||||||
var features;
|
var features;
|
||||||
@@ -117,10 +123,10 @@ ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) {
|
|||||||
*/
|
*/
|
||||||
ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = Object({
|
ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = Object({
|
||||||
'http://www.opengis.net/gml': {
|
'http://www.opengis.net/gml': {
|
||||||
'featureMember': ol.xml.makeArrayPusher(
|
'featureMember': ol.xml.makeReplacer(
|
||||||
ol.format.GMLBase.prototype.readFeatures_),
|
ol.format.GMLBase.prototype.readFeaturesInternal),
|
||||||
'featureMembers': ol.xml.makeReplacer(
|
'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) {
|
ol.format.GMLBase.prototype.readFeatureElement = function(node, objectStack) {
|
||||||
var n;
|
var n;
|
||||||
var fid = node.getAttribute('fid') ||
|
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;
|
var values = {}, geometryName;
|
||||||
for (n = node.firstElementChild; !goog.isNull(n);
|
for (n = node.firstElementChild; !goog.isNull(n);
|
||||||
n = n.nextElementSibling) {
|
n = n.nextElementSibling) {
|
||||||
@@ -549,7 +555,7 @@ ol.format.GMLBase.prototype.readFeaturesFromNode =
|
|||||||
if (goog.isDef(opt_options)) {
|
if (goog.isDef(opt_options)) {
|
||||||
goog.object.extend(options, this.getReadOptions(node, opt_options));
|
goog.object.extend(options, this.getReadOptions(node, opt_options));
|
||||||
}
|
}
|
||||||
return this.readFeatures_(node, [options]);
|
return this.readFeaturesInternal(node, [options]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -125,6 +125,9 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) {
|
|||||||
goog.object.extend(context, this.getReadOptions(node,
|
goog.object.extend(context, this.getReadOptions(node,
|
||||||
goog.isDef(opt_options) ? opt_options : {}));
|
goog.isDef(opt_options) ? opt_options : {}));
|
||||||
var objectStack = [context];
|
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([],
|
var features = ol.xml.pushParseAndPop([],
|
||||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||||
objectStack, this.gmlFormat_);
|
objectStack, this.gmlFormat_);
|
||||||
|
|||||||
26
test/spec/ol/format/gml/ogr.xml
Normal file
26
test/spec/ol/format/gml/ogr.xml
Normal 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>
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user