#17565·openlayers

Polygon Simplify can result in invalid Polygon

Author: sammaxwellxyzCreated Jul 16, 2026Updated Jul 16, 2026
Labelsbug

Describe the bug A valid polygon can be simplified to an invalid one. see reproduction example.

The docs include for the simplify method

Create a simplified version of this geometry. For linestrings, this uses the Douglas Peucker algorithm. For polygons, a quantization-based simplification is used to preserve topology."

I'm making some assumptions about what a Polygon is, one of those is that it should follow the GeoJSON spec for a Polygon which starts

To specify a constraint specific to Polygons, it is useful to introduce the concept of a linear ring:

  • A linear ring is a closed LineString with four or more positions. ...
  • For type "Polygon", the "coordinates" member MUST be an array of linear ring coordinate arrays.

My first though was this was a bug, based on assuming "preserve topology." to be a proxy for "preserve topology as defined in GeoJSON spec.

But then I realised that one is OK to create a Polygon with only a 2 coord "linear ring" and therefore the Polygon could start life as topologically incorrect (as I've interpreted).

To Reproduce

javascript
import Polygon from "ol/geom/Polygon.js";

const poly = new Polygon([
  [
    [0, 0],
    [0, 1],
    [1, 1],
    [1, 0],
    [0, 0],
  ],
]);
console.log(poly.getCoordinates());
console.log(poly.simplify(10).getCoordinates());

prooduces

[ [ [ 0, 0 ], [ 0, 1 ], [ 1, 1 ], [ 1, 0 ], [ 0, 0 ] ] ]
[ [ [ 0, 0 ], [ 0, 0 ] ] ]

Expected behaviour I think I'd expect one of two things:

1. Validation of Geometry

The geometry classes that align with GeoJSON to follow the GeoJSON spec and therefore methods like simplify to produce the same geometry also adhering to the GeoJSON spec. Cases where a new instance of a geometry are invalid, cause an error. Ideally simplify would be able to simplify while staying valid and therefore the new Geometry (polygon in my case) would not error.

2. Docs updated

I wasn't able to find any criteria in the docs or code for validation of geometries or specification and could consider it a userland problem to deal with.

For polygons, a quantization-based simplification is used to preserve topology."

I think is hard to understand correctly, perhaps "preserve topology" could be expanded on?

Thank you for reading :)