Support reading polygons with curve rings

This commit is contained in:
Andreas Hocevar
2022-06-10 18:17:26 +02:00
parent 2a8cc3d2f5
commit e863960599
3 changed files with 72 additions and 1 deletions

View File

@@ -134,6 +134,27 @@ class GML3 extends GMLBase {
}
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Array<number>|undefined} Polygon.
*/
readFlatCurveRing(node, objectStack) {
/** @type {Array<LineString>} */
const lineStrings = pushParseAndPop(
[],
this.MULTICURVE_PARSERS,
node,
objectStack,
this
);
const flatCoordinates = [];
for (let i = 0, ii = lineStrings.length; i < ii; ++i) {
extend(flatCoordinates, lineStrings[i].getFlatCoordinates());
}
return flatCoordinates;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -1162,6 +1183,17 @@ GML3.prototype.SEGMENTS_PARSERS = {
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
GMLBase.prototype.RING_PARSERS = {
'http://www.opengis.net/gml': {
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing),
'Ring': makeReplacer(GML3.prototype.readFlatCurveRing),
},
};
/**
* Encode an array of features in GML 3.1.1 Simple Features.
*

View File

@@ -4,7 +4,12 @@
import GML2 from './GML2.js';
import GML3 from './GML3.js';
import GMLBase from './GMLBase.js';
import {makeArrayPusher, makeChildAppender, makeReplacer} from '../xml.js';
import {
makeArrayExtender,
makeArrayPusher,
makeChildAppender,
makeReplacer,
} from '../xml.js';
import {writeStringTextNode} from '../format/xsd.js';
/**
@@ -249,6 +254,7 @@ GML32.prototype.POLYGONMEMBER_PARSERS = {
GML32.prototype.RING_PARSERS = {
'http://www.opengis.net/gml/3.2': {
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing),
'Ring': makeReplacer(GML32.prototype.readFlatCurveRing),
},
};