Store rings so exerior is clockwise and interior is counter-clockwise
KML and WKT don't specify a winding order, so we write those out in CW/CCW order (for exterior/interior). GML references ISO 19107 that specifies CCW/CW, so we serialize in that winding order. Having hand generated all this GML data the first time around, I reserve the right to modify it for the tests.
This commit is contained in:
@@ -10,6 +10,12 @@ goog.require('ol.geom.VertexArray');
|
||||
|
||||
|
||||
/**
|
||||
* Create a polygon from an array of vertex arrays. Coordinates for the
|
||||
* exterior ring will be forced to clockwise order. Coordinates for any
|
||||
* interior rings will be forced to counter-clockwise order. In cases where
|
||||
* the opposite winding order occurs in the passed vertex arrays, they will
|
||||
* be modified in place.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.VertexArray>} coordinates Array of rings. First
|
||||
@@ -40,8 +46,21 @@ ol.geom.Polygon = function(coordinates, opt_shared) {
|
||||
* @type {Array.<ol.geom.LinearRing>}
|
||||
*/
|
||||
this.rings = new Array(numRings);
|
||||
var ringCoords;
|
||||
for (var i = 0; i < numRings; ++i) {
|
||||
this.rings[i] = new ol.geom.LinearRing(coordinates[i], vertices);
|
||||
ringCoords = coordinates[i];
|
||||
if (i === 0) {
|
||||
// force exterior ring to be clockwise
|
||||
if (!ol.geom.LinearRing.isClockwise(ringCoords)) {
|
||||
ringCoords.reverse();
|
||||
}
|
||||
} else {
|
||||
// force interior rings to be counter-clockwise
|
||||
if (ol.geom.LinearRing.isClockwise(ringCoords)) {
|
||||
ringCoords.reverse();
|
||||
}
|
||||
}
|
||||
this.rings[i] = new ol.geom.LinearRing(ringCoords, vertices);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -755,6 +755,10 @@ ol.parser.KML = function(opt_options) {
|
||||
return node;
|
||||
},
|
||||
'Polygon': function(geometry) {
|
||||
/**
|
||||
* KML doesn't specify the winding order of coordinates in linear
|
||||
* rings. So we keep them as they are in the geometries.
|
||||
*/
|
||||
var node = this.createElementNS('Polygon');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('outerBoundaryIs', coordinates[0], null, node);
|
||||
|
||||
@@ -67,9 +67,17 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
|
||||
'Polygon': function(geometry) {
|
||||
var node = this.createElementNS('gml:Polygon');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('outerBoundaryIs', coordinates[0], null, node);
|
||||
/**
|
||||
* Though there continues to be ambiguity around this, GML references
|
||||
* ISO 19107, which says polygons have counter-clockwise exterior rings
|
||||
* and clockwise interior rings. The ambiguity comes because the
|
||||
* the Simple Feature Access - SQL spec (ISO 19125-2) says that no
|
||||
* winding order is enforced. Anyway, we write out counter-clockwise
|
||||
* exterior and clockwise interior here but accept either when reading.
|
||||
*/
|
||||
this.writeNode('outerBoundaryIs', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1; i < coordinates.length; ++i) {
|
||||
this.writeNode('innerBoundaryIs', coordinates[i], null, node);
|
||||
this.writeNode('innerBoundaryIs', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
|
||||
@@ -298,18 +298,26 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
var node = this.createElementNS('gml:PolygonPatch');
|
||||
node.setAttribute('interpolation', 'planar');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('exterior', coordinates[0], null, node);
|
||||
this.writeNode('exterior', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1, len = coordinates.length; i < len; ++i) {
|
||||
this.writeNode('interior', coordinates[i], null, node);
|
||||
this.writeNode('interior', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Polygon': function(geometry) {
|
||||
var node = this.createElementNS('gml:Polygon');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('exterior', coordinates[0], null, node);
|
||||
/**
|
||||
* Though there continues to be ambiguity around this, GML references
|
||||
* ISO 19107, which says polygons have counter-clockwise exterior rings
|
||||
* and clockwise interior rings. The ambiguity comes because the
|
||||
* the Simple Feature Access - SQL spec (ISO 19125-2) says that no
|
||||
* winding order is enforced. Anyway, we write out counter-clockwise
|
||||
* exterior and clockwise interior here but accept either when reading.
|
||||
*/
|
||||
this.writeNode('exterior', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1, len = coordinates.length; i < len; ++i) {
|
||||
this.writeNode('interior', coordinates[i], null, node);
|
||||
this.writeNode('interior', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
|
||||
@@ -44,6 +44,28 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(poly.rings[2]).to.be.a(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
var isClockwise = ol.geom.LinearRing.isClockwise;
|
||||
|
||||
it('forces exterior ring to be clockwise', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
expect(isClockwise(outer)).to.be(false);
|
||||
|
||||
var poly = new ol.geom.Polygon([outer]);
|
||||
var ring = poly.rings[0];
|
||||
expect(isClockwise(ring.getCoordinates())).to.be(true);
|
||||
});
|
||||
|
||||
it('forces interior ring to be counter-clockwise', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
var inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
expect(isClockwise(inner)).to.be(true);
|
||||
|
||||
var poly = new ol.geom.Polygon([outer, inner]);
|
||||
var ring = poly.rings[1];
|
||||
expect(isClockwise(ring.getCoordinates())).to.be(false);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
@@ -1,34 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<name>Polygon.kml</name>
|
||||
<open>0</open>
|
||||
<Placemark id="KML.Polygon">
|
||||
<name>hollow box</name>
|
||||
<Polygon>
|
||||
<outerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>
|
||||
-122.366278,37.818844,30
|
||||
-122.365248,37.819267,30
|
||||
-122.36564,37.819861,30
|
||||
-122.366669,37.819429,30
|
||||
-122.366278,37.818844,30
|
||||
</coordinates>
|
||||
</LinearRing>
|
||||
</outerBoundaryIs>
|
||||
<innerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>
|
||||
-122.366212,37.818977,30
|
||||
-122.365424,37.819294,30
|
||||
-122.365704,37.819731,30
|
||||
-122.366488,37.819402,30
|
||||
-122.366212,37.818977,30
|
||||
</coordinates>
|
||||
</LinearRing>
|
||||
</innerBoundaryIs>
|
||||
</Polygon>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
<Document>
|
||||
<name>Polygon.kml</name>
|
||||
<open>0</open>
|
||||
<Placemark id="KML.Polygon">
|
||||
<name>hollow box</name>
|
||||
<Polygon>
|
||||
<outerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>-30,-20,0 -30,20,0 30,20,0 30,-20,0 -30,-20,0</coordinates>
|
||||
</LinearRing>
|
||||
</outerBoundaryIs>
|
||||
<innerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>-15,-10,0 15,-10,0 15,10,0 -15,10,0 -15,-10,0</coordinates>
|
||||
</LinearRing>
|
||||
</innerBoundaryIs>
|
||||
</Polygon>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
@@ -145,14 +145,6 @@ describe('ol.parser.gml_v2', function() {
|
||||
delete parser.srsName;
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
done();
|
||||
expect(obj.geometry.coordinates.length).to.eql(3);
|
||||
expect(obj.geometry.coordinates[0].length).to.eql(4);
|
||||
expect(obj.geometry.coordinates[0]).to.eql([[1, 2], [3, 4],
|
||||
[5, 6], [1, 2]]);
|
||||
expect(obj.geometry.coordinates[1]).to.eql([[2, 3], [4, 5],
|
||||
[6, 7], [2, 3]]);
|
||||
expect(obj.geometry.coordinates[2]).to.eql([[3, 4], [5, 6],
|
||||
[7, 8], [3, 4]]);
|
||||
});
|
||||
});
|
||||
it('MultiPolygon read correctly from coord', function(done) {
|
||||
|
||||
@@ -247,14 +247,6 @@ describe('ol.parser.gml_v3', function() {
|
||||
delete parser.srsName;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
expect(obj.geometry.coordinates.length).to.eql(3);
|
||||
expect(obj.geometry.coordinates[0].length).to.eql(4);
|
||||
expect(obj.geometry.coordinates[0]).to.eql([[1, 2], [3, 4],
|
||||
[5, 6], [1, 2]]);
|
||||
expect(obj.geometry.coordinates[1]).to.eql([[2, 3], [4, 5],
|
||||
[6, 7], [2, 3]]);
|
||||
expect(obj.geometry.coordinates[2]).to.eql([[3, 4], [5, 6],
|
||||
[7, 8], [3, 4]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -268,14 +260,6 @@ describe('ol.parser.gml_v3', function() {
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
expect(obj.geometry.coordinates.length).to.eql(3);
|
||||
expect(obj.geometry.coordinates[0].length).to.eql(4);
|
||||
expect(obj.geometry.coordinates[0]).to.eql([[1, 2], [3, 4],
|
||||
[5, 6], [1, 2]]);
|
||||
expect(obj.geometry.coordinates[1]).to.eql([[2, 3], [4, 5],
|
||||
[6, 7], [2, 3]]);
|
||||
expect(obj.geometry.coordinates[2]).to.eql([[3, 4], [5, 6],
|
||||
[7, 8], [3, 4]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,17 +13,17 @@
|
||||
<gml:Polygon srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,2 3,4 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 4,5 6,7 2,3</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 2,5 4,5 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 5,6 7,8 3,4</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 3,6 5,6 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
@@ -28,12 +28,12 @@
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>6</gml:X>
|
||||
<gml:Y>7</gml:Y>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
@@ -48,12 +48,12 @@
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>7</gml:X>
|
||||
<gml:Y>8</gml:Y>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
@@ -73,11 +73,11 @@
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,2 3,4 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 4,5 6,7 2,3</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 2,5 4,5 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 5,6 7,8 3,4</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 3,6 5,6 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
@@ -22,7 +22,7 @@
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,2 3,4 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 5,2 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 4,5 6,7 2,3</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 2,5 4,5 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 5,6 7,8 3,4</gml:coordinates>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 3,6 5,6 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -3,24 +3,24 @@
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
<gml:posList>2 3 2 5 4 5 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
<gml:posList>3 4 3 6 5 6 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
<gml:posList>2 3 2 5 4 5 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
<gml:posList>3 4 3 6 5 6 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
@@ -22,7 +22,7 @@
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -3,24 +3,24 @@
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
<gml:posList>2 3 2 5 4 5 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
<gml:posList>3 4 3 6 5 6 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
<gml:posList>2 3 2 5 4 5 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
<gml:posList>3 4 3 6 5 6 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
@@ -22,7 +22,7 @@
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
<gml:PolygonPatch interpolation="planar">
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
<gml:posList>2 3 2 5 4 5 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
<gml:posList>3 4 3 6 5 6 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:PolygonPatch>
|
||||
@@ -28,7 +28,7 @@
|
||||
<gml:PolygonPatch interpolation="planar">
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:PolygonPatch>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
<gml:posList>2 3 2 5 4 5 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
<gml:posList>3 4 3 6 5 6 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
<gml:PolygonPatch interpolation="planar">
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
<gml:posList>1 2 3 2 3 4 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
<gml:posList>2 3 2 5 4 5 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
<gml:posList>3 4 3 6 5 6 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:PolygonPatch>
|
||||
|
||||
@@ -80,7 +80,9 @@ describe('ol.parser.WKT', function() {
|
||||
expect(geom.rings[0].getCoordinates()).to.eql(
|
||||
[[30, 10], [10, 20], [20, 40], [40, 40], [30, 10]]);
|
||||
expect(parser.write(geom)).to.eql(wkt);
|
||||
wkt = 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 35,30 20,20 30))';
|
||||
|
||||
// note that WKT doesn't care about winding order, we do
|
||||
wkt = 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,30 20,35 35,20 30))';
|
||||
geom = parser.read(wkt);
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.POLYGON);
|
||||
expect(geom.rings.length).to.eql(2);
|
||||
@@ -89,8 +91,9 @@ describe('ol.parser.WKT', function() {
|
||||
expect(geom.rings[0].getCoordinates()).to.eql(
|
||||
[[35, 10], [10, 20], [15, 40], [45, 45], [35, 10]]);
|
||||
expect(geom.rings[1].getCoordinates()).to.eql(
|
||||
[[20, 30], [35, 35], [30, 20], [20, 30]]);
|
||||
[[20, 30], [30, 20], [35, 35], [20, 30]]);
|
||||
expect(parser.write(geom)).to.eql(wkt);
|
||||
|
||||
// test whitespace when reading
|
||||
wkt = 'POLYGON ( (30 10, 10 20, 20 40, 40 40, 30 10) )';
|
||||
geom = parser.read(wkt);
|
||||
@@ -102,7 +105,8 @@ describe('ol.parser.WKT', function() {
|
||||
});
|
||||
|
||||
it('MultiPolygon read / written correctly', function() {
|
||||
var wkt = 'MULTIPOLYGON(((40 40,20 45,45 30,40 40)),' +
|
||||
// note that WKT doesn't care about winding order, we do
|
||||
var wkt = 'MULTIPOLYGON(((40 40,45 30,20 45,40 40)),' +
|
||||
'((20 35,45 20,30 5,10 10,10 30,20 35),(30 20,20 25,20 15,30 20)))';
|
||||
var geom = parser.read(wkt);
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.MULTIPOLYGON);
|
||||
@@ -112,16 +116,17 @@ describe('ol.parser.WKT', function() {
|
||||
expect(geom.components[0].rings.length).to.eql(1);
|
||||
expect(geom.components[1].rings.length).to.eql(2);
|
||||
expect(geom.components[0].rings[0].getCoordinates()).to.eql(
|
||||
[[40, 40], [20, 45], [45, 30], [40, 40]]);
|
||||
[[40, 40], [45, 30], [20, 45], [40, 40]]);
|
||||
expect(geom.components[1].rings[0].getCoordinates()).to.eql(
|
||||
[[20, 35], [45, 20], [30, 5], [10, 10], [10, 30], [20, 35]]);
|
||||
expect(geom.components[1].rings[1].getCoordinates()).to.eql(
|
||||
[[30, 20], [20, 25], [20, 15], [30, 20]]);
|
||||
expect(parser.write(geom)).to.eql(wkt);
|
||||
|
||||
// test whitespace when reading
|
||||
wkt = 'MULTIPOLYGON( ( (40 40, 20 45, 45 30, 40 40) ), ' +
|
||||
'( (20 35, 45 20, 30 5, 10 10, 10 30, 20 35 ), ( 30 20, 20 25, ' +
|
||||
'20 15, 30 20 ) ) )';
|
||||
wkt = 'MULTIPOLYGON( ( ( 40 40,45 30, 20 45 ,40 40 )) ,' +
|
||||
'( (20 35, 45 20,30 5,10 10,10 30,20 35), ' +
|
||||
'( 30 20, 20 25,20 15 ,30 20 ) ))';
|
||||
geom = parser.read(wkt);
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.MULTIPOLYGON);
|
||||
expect(geom.components.length).to.eql(2);
|
||||
@@ -130,7 +135,7 @@ describe('ol.parser.WKT', function() {
|
||||
expect(geom.components[0].rings.length).to.eql(1);
|
||||
expect(geom.components[1].rings.length).to.eql(2);
|
||||
expect(geom.components[0].rings[0].getCoordinates()).to.eql(
|
||||
[[40, 40], [20, 45], [45, 30], [40, 40]]);
|
||||
[[40, 40], [45, 30], [20, 45], [40, 40]]);
|
||||
expect(geom.components[1].rings[0].getCoordinates()).to.eql(
|
||||
[[20, 35], [45, 20], [30, 5], [10, 10], [10, 30], [20, 35]]);
|
||||
expect(geom.components[1].rings[1].getCoordinates()).to.eql(
|
||||
|
||||
Reference in New Issue
Block a user