Add support for gml:MultiSurface

This commit is contained in:
Bart van den Eijnden
2014-02-21 14:42:48 +01:00
parent e479bd142f
commit 9e44e79789
2 changed files with 200 additions and 0 deletions

View File

@@ -159,6 +159,28 @@ ol.format.GML.readMultiCurve_ = function(node, objectStack) {
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {ol.geom.MultiPolygon|undefined} MultiPolygon.
*/
ol.format.GML.readMultiSurface_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'MultiSurface');
var polygons = ol.xml.pushParseAndPop(
/** @type {Array.<ol.geom.Polygon>} */ ([]),
ol.format.GML.MULTISURFACE_PARSERS_, node, objectStack);
if (goog.isDefAndNotNull(polygons)) {
var multiPolygon = new ol.geom.MultiPolygon(null);
multiPolygon.setPolygons(polygons);
return multiPolygon;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -220,6 +242,19 @@ ol.format.GML.curveMemberParser_ = function(node, objectStack) {
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GML.surfaceMemberParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'surfaceMember' ||
node.localName == 'surfaceMembers');
ol.xml.parse(ol.format.GML.SURFACEMEMBER_PARSERS_, node, objectStack);
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -592,6 +627,7 @@ ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS(
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
'MultiPolygon': ol.xml.makeArrayPusher(ol.format.GML.readMultiPolygon_),
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_),
'MultiSurface': ol.xml.makeArrayPusher(ol.format.GML.readMultiSurface_),
'Curve': ol.xml.makeArrayPusher(ol.format.GML.readCurve_),
'MultiCurve': ol.xml.makeArrayPusher(ol.format.GML.readMultiCurve_),
'Envelope': ol.xml.makeArrayPusher(ol.format.GML.readEnvelope_)
@@ -662,6 +698,20 @@ ol.format.GML.MULTICURVE_PARSERS_ = ol.xml.makeParsersNS(
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML.MULTISURFACE_PARSERS_ = ol.xml.makeParsersNS(
ol.format.GML.NAMESPACE_URIS_, {
'surfaceMember': ol.xml.makeArrayPusher(
ol.format.GML.surfaceMemberParser_),
'surfaceMembers': ol.xml.makeArrayPusher(
ol.format.GML.surfaceMemberParser_)
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
@@ -712,6 +762,18 @@ ol.format.GML.CURVEMEMBER_PARSERS_ = ol.xml.makeParsersNS(
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML.SURFACEMEMBER_PARSERS_ = ol.xml.makeParsersNS(
ol.format.GML.NAMESPACE_URIS_, {
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_)
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}

View File

@@ -387,6 +387,144 @@ describe('ol.format.GML', function() {
});
describe('multisurface', function() {
it('can read a singular multisurface geometry', function() {
var text =
'<gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="foo">' +
' <gml:surfaceMember>' +
' <gml:Polygon>' +
' <gml:exterior>' +
' <gml:LinearRing>' +
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
' </gml:LinearRing>' +
' </gml:exterior>' +
' <gml:interior>' +
' <gml:LinearRing>' +
' <gml:posList>2 3 2 5 4 5 2 3</gml:posList>' +
' </gml:LinearRing>' +
' </gml:interior>' +
' <gml:interior>' +
' <gml:LinearRing>' +
' <gml:posList>3 4 3 6 5 6 3 4</gml:posList>' +
' </gml:LinearRing>' +
' </gml:interior>' +
' </gml:Polygon>' +
' </gml:surfaceMember>' +
' <gml:surfaceMember>' +
' <gml:Polygon>' +
' <gml:exterior>' +
' <gml:LinearRing>' +
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
' </gml:LinearRing>' +
' </gml:exterior>' +
' </gml:Polygon>' +
' </gml:surfaceMember>' +
'</gml:MultiSurface>';
var g = format.readGeometry(text);
expect(g).to.be.an(ol.geom.MultiPolygon);
expect(g.getCoordinates()).to.eql([
[[[1, 2, 0], [3, 2, 0], [3, 4, 0],
[1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]],
[[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]],
[[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]);
});
it('can read a plural multisurface geometry', function() {
var text =
'<gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="foo">' +
' <gml:surfaceMembers>' +
' <gml:Polygon>' +
' <gml:exterior>' +
' <gml:LinearRing>' +
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
' </gml:LinearRing>' +
' </gml:exterior>' +
' <gml:interior>' +
' <gml:LinearRing>' +
' <gml:posList>2 3 2 5 4 5 2 3</gml:posList>' +
' </gml:LinearRing>' +
' </gml:interior>' +
' <gml:interior>' +
' <gml:LinearRing>' +
' <gml:posList>3 4 3 6 5 6 3 4</gml:posList>' +
' </gml:LinearRing>' +
' </gml:interior>' +
' </gml:Polygon>' +
' </gml:surfaceMembers>' +
' <gml:surfaceMembers>' +
' <gml:Polygon>' +
' <gml:exterior>' +
' <gml:LinearRing>' +
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
' </gml:LinearRing>' +
' </gml:exterior>' +
' </gml:Polygon>' +
' </gml:surfaceMembers>' +
'</gml:MultiSurface>';
var g = format.readGeometry(text);
expect(g).to.be.an(ol.geom.MultiPolygon);
expect(g.getCoordinates()).to.eql([
[[[1, 2, 0], [3, 2, 0], [3, 4, 0],
[1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]],
[[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]],
[[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]);
});
it('can read a multisurface-surface geometry', function() {
var text =
'<gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="foo">' +
' <gml:surfaceMember>' +
' <gml:Surface>' +
' <gml:patches>' +
' <gml:PolygonPatch interpolation="planar">' +
' <gml:exterior>' +
' <gml:LinearRing>' +
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
' </gml:LinearRing>' +
' </gml:exterior>' +
' <gml:interior>' +
' <gml:LinearRing>' +
' <gml:posList>2 3 2 5 4 5 2 3</gml:posList>' +
' </gml:LinearRing>' +
' </gml:interior>' +
' <gml:interior>' +
' <gml:LinearRing>' +
' <gml:posList>3 4 3 6 5 6 3 4</gml:posList>' +
' </gml:LinearRing>' +
' </gml:interior>' +
' </gml:PolygonPatch>' +
' </gml:patches>' +
' </gml:Surface>' +
' </gml:surfaceMember>' +
' <gml:surfaceMember>' +
' <gml:Surface>' +
' <gml:patches>' +
' <gml:PolygonPatch interpolation="planar">' +
' <gml:exterior>' +
' <gml:LinearRing>' +
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
' </gml:LinearRing>' +
' </gml:exterior>' +
' </gml:PolygonPatch>' +
' </gml:patches>' +
' </gml:Surface>' +
' </gml:surfaceMember>' +
'</gml:MultiSurface>';
var g = format.readGeometry(text);
expect(g).to.be.an(ol.geom.MultiPolygon);
expect(g.getCoordinates()).to.eql([
[[[1, 2, 0], [3, 2, 0], [3, 4, 0],
[1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]],
[[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]],
[[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]);
});
});
});
});