Skip to main content

prepare

Prepares geometry to optimize the performance of repeated calls to specific geometric operations.

The "prepared geometry" is conceptually similar to a database "prepared statement": by doing up-front work to create an optimized object, you reap a performance benefit when executing repeated function calls on that object.

List of functions that benefit from geometry preparation:

Modifies the geometry in-place.

Type Parameters

  • G - The type of prepared geometry, for example, Geometry or more specific Polygon

Parameters

NameTypeDescription
geometryGGeometry to prepare

Returns

Prepared<G>

Exactly the same geometry object, but with prepared internal spatial indexes

See also

Examples

lifecycle of the prepared geometry
const regularPolygon = buffer(point([ 0, 0 ]), 10, { quadrantSegments: 1000 });
const preparedPolygon = prepare(regularPolygon);
const regularPolygonAgain = unprepare(preparedPolygon);
// `regularPolygon`, `preparedPolygon` and `regularPolygonAgain` are exactly the same object
// so if you do not care about TypeScript, the above can be simplified to:
const p = buffer(point([ 0, 0 ]), 10, { quadrantSegments: 1000 });
prepare(p);
unprepare(p);