Support reading polygons with curve rings
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2290,6 +2290,39 @@ describe('ol.format.GML32', function () {
|
||||
'</gml:Curve>';
|
||||
expect(serialized.firstElementChild).to.xmleql(parse(expected));
|
||||
});
|
||||
|
||||
it('can read a polygon with a ring of curves', function () {
|
||||
const text = `
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml/3.2" srsName="CRS:84">
|
||||
<gml:exterior>
|
||||
<gml:Ring>
|
||||
<gml:curveMember>
|
||||
<gml:Curve>
|
||||
<gml:segments>
|
||||
<gml:LineStringSegment interpolation="linear">
|
||||
<gml:posList>1 2 3 4</gml:posList>
|
||||
</gml:LineStringSegment>
|
||||
<gml:LineStringSegment interpolation="linear">
|
||||
<gml:posList>5 6 7 8</gml:posList>
|
||||
</gml:LineStringSegment>
|
||||
</gml:segments>
|
||||
</gml:Curve>
|
||||
</gml:curveMember>
|
||||
</gml:Ring>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
`;
|
||||
const g = readGeometry(format, text);
|
||||
expect(g).to.be.an(Polygon);
|
||||
expect(g.getCoordinates()).to.eql([
|
||||
[
|
||||
[1, 2, 0],
|
||||
[3, 4, 0],
|
||||
[5, 6, 0],
|
||||
[7, 8, 0],
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('envelope', function () {
|
||||
|
||||
Reference in New Issue
Block a user