Skip to main content

makeValid

Repairs an invalid geometry, returns a repaired, valid geometry. Input geometries are always processed, so even valid inputs may have some minor alterations. The output is always a new geometry object.

Parameters

NameTypeDefaultDescription
geometryGeometryThe geometry to repair
options?objectOptional parameters to control the algorithm
options.method?'linework' | 'structure''linework'Method used for fixing invalid geometries.
  • linework - builds valid geometries by first extracting all lines, noding that linework together, then building a value output from the linework
  • structure - is an algorithm that distinguishes between interior and exterior rings, building new geometry by unioning exterior rings, and then differencing all interior rings
options.keepCollapsed?booleanfalseOnly valid for the structure method. When set to false, geometry components that collapse to a lower dimensionality, for example, a one-point linestring would be dropped.

Returns

Geometry

A new repaired geometry

Throws

  • GEOSError on unsupported geometry types (curved)

See also

  • isValid checks whether a geometry is already valid

Examples

polygon with hole partially outside shell