Merge pull request #4145 from tschaub/simplified-geom
API method for simplifying geometries.
This commit is contained in:
@@ -169,10 +169,27 @@ ol.geom.Geometry.prototype.getExtent = function(opt_extent) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a simplified version of this geometry. For linestrings, this uses
|
||||
* the the {@link
|
||||
* https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
||||
* Douglas Peucker} algorithm. For polygons, a quantization-based
|
||||
* simplification is used to preserve topology.
|
||||
* @function
|
||||
* @param {number} tolerance The tolerance distance for simplification.
|
||||
* @return {ol.geom.Geometry} A new, simplified version of the original
|
||||
* geometry.
|
||||
* @api
|
||||
*/
|
||||
ol.geom.Geometry.prototype.simplify = function(tolerance) {
|
||||
return this.getSimplifiedGeometry(tolerance * tolerance);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a simplified version of this geometry using the Douglas Peucker
|
||||
* algorithm.
|
||||
* @see http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
|
||||
* @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
||||
* @function
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {ol.geom.Geometry} Simplified geometry.
|
||||
|
||||
@@ -263,6 +263,29 @@ describe('ol.geom.LineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#simplify', function() {
|
||||
|
||||
it('returns a simplified geometry', function() {
|
||||
var simplified = lineString.simplify(1);
|
||||
expect(simplified).to.be.an(ol.geom.LineString);
|
||||
expect(simplified.getCoordinates()).to.eql(
|
||||
[[0, 0], [3, 3], [5, 1], [7, 5]]);
|
||||
});
|
||||
|
||||
it('does not modify the original', function() {
|
||||
lineString.simplify(1);
|
||||
expect(lineString.getCoordinates()).to.eql(
|
||||
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
|
||||
});
|
||||
|
||||
it('delegates to the internal method', function() {
|
||||
var simplified = lineString.simplify(2);
|
||||
var internal = lineString.getSimplifiedGeometry(4);
|
||||
expect(simplified.getCoordinates()).to.eql(internal.getCoordinates());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getSimplifiedGeometry', function() {
|
||||
|
||||
it('returns the expectedResult', function() {
|
||||
|
||||
Reference in New Issue
Block a user