geos.js
Version:
an easy-to-use JavaScript wrapper over WebAssembly build of GEOS
2,949 lines • 122 kB
text/typescript
import { Feature, Point as Point$1, LineString as LineString$1, Polygon as Polygon$1, MultiPoint as MultiPoint$1, MultiLineString as MultiLineString$1, MultiPolygon as MultiPolygon$1, Position, Geometry as Geometry$1, FeatureCollection } from 'geojson';
/**
* Terminates the initialized `geos.js` module and releases associated resources.
*
* @returns A Promise that resolves when the termination is complete
*
* @see {@link initializeFromBase64}
* @see {@link initialize}
*/
declare function terminate(): Promise<void>;
/**
* Base error class for all `geos.js` errors.
*
* Errors that originate from C/C++/Wasm code are thrown as instances of this class.
* More specific errors are thrown as instances of one of the subclasses of this class.
*/
declare class GEOSError extends Error {
}
/**
* Point is an instance of {@link GeometryRef} that represents the point geometry.
*
* @see {@link point} creates a point geometry from a single coordinate
*
* @example
* const a = fromGeoJSON({ type: 'Point', coordinates: [ 0, 0 ] });
* const b = point([ 0, 0 ]); // shortcut to above
* const c = fromWKT('POINT (0 0)');
*/
interface Point<P = unknown> extends GeometryRef<P> {
readonly type: 'Point';
toJSON(): Feature<Point$1, P>;
clone(): Point<P>;
}
/**
* LineString is an instance of {@link GeometryRef} that represents the line string geometry.
*
* @see {@link lineString} creates a line string geometry from an array of positions
*
* @example
* const a = fromGeoJSON({
* type: 'LineString',
* coordinates: [ [ 0, 0 ], [ 1, 1 ], [ 2, 2 ] ],
* });
* const b = lineString([ [ 0, 0 ], [ 1, 1 ], [ 2, 2 ] ]); // shortcut to above
* const c = fromWKT('LINESTRING (0 0, 1 1, 2 2)');
*/
interface LineString<P = unknown> extends GeometryRef<P> {
readonly type: 'LineString';
toJSON(): Feature<LineString$1, P>;
clone(): LineString<P>;
}
interface LinearRing<P = unknown> extends GeometryRef<P> {
readonly type: 'LinearRing';
toJSON(): Feature<LineString$1, P>;
clone(): LinearRing<P>;
}
/**
* Polygon is an instance of {@link GeometryRef} that represents the polygon geometry.
*
* @see {@link polygon} creates a polygon geometry from an array of linear rings coordinates
*
* @example
* const a = fromGeoJSON({
* type: 'Polygon',
* coordinates: [
* [ [ 0, 0 ], [ 0, 1 ], [ 1, 0 ], [ 0, 0 ] ],
* ],
* });
* const b = polygon([ // shortcut to above
* [ [ 0, 0 ], [ 0, 1 ], [ 1, 0 ], [ 0, 0 ] ],
* ]);
* const c = fromWKT('POLYGON ((0 0, 0 1, 1 0, 0 0))');
* const d = polygon([
* [ [ 0, 0 ], [ 0, 8 ], [ 8, 0 ], [ 0, 0 ] ], // shell
* [ [ 2, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ], // hole 1
* [ [ 2, 2 ], [ 2, 3 ], [ 3, 2 ], [ 2, 2 ] ], // hole 2
* ]);
*/
interface Polygon<P = unknown> extends GeometryRef<P> {
readonly type: 'Polygon';
toJSON(): Feature<Polygon$1, P>;
clone(): Polygon<P>;
}
/**
* MultiPoint is an instance of {@link GeometryRef} that represents the multi point geometry.
*
* @see {@link multiPoint} creates a multi point geometry from an array of positions
*
* @example
* const a = fromGeoJSON({
* type: 'MultiPoint',
* coordinates: [ [ 0, 0 ], [ 1, 1 ], [ 2, 2 ] ],
* });
* const b = multiPoint([ [ 0, 0 ], [ 1, 1 ], [ 2, 2 ] ]); // shortcut to above
* const c = fromWKT('MULTIPOINT (0 0, 1 1, 2 2)');
*/
interface MultiPoint<P = unknown> extends GeometryRef<P> {
readonly type: 'MultiPoint';
toJSON(): Feature<MultiPoint$1, P>;
clone(): MultiPoint<P>;
}
/**
* MultiLineString is an instance of {@link GeometryRef} that represents the multi line string geometry.
*
* @see {@link multiLineString} creates a multi line string geometry from an array of line strings coordinates
*
* @example
* const a = fromGeoJSON({
* type: 'MultiLineString',
* coordinates: [
* [ [ 0, 0 ], [ 1, 1 ] ], // line 1
* [ [ 2, 2 ], [ 3, 3 ] ], // line 2
* ],
* });
* const b = multiLineString([ // shortcut to above
* [ [ 0, 0 ], [ 1, 1 ] ],
* [ [ 2, 2 ], [ 3, 3 ] ],
* ]);
* const c = fromWKT('MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))');
*/
interface MultiLineString<P = unknown> extends GeometryRef<P> {
readonly type: 'MultiLineString';
toJSON(): Feature<MultiLineString$1, P>;
clone(): MultiLineString<P>;
}
/**
* MultiPolygon is an instance of {@link GeometryRef} that represents the multi polygon geometry.
*
* @see {@link multiPolygon} creates a multi polygon geometry from an array of polygon coordinates
*
* @example
* const a = fromGeoJSON({
* type: 'MultiPolygon',
* coordinates: [
* [ [ [ 0, 1 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ] ] ], // polygon 1
* [ [ [ 1, 1 ], [ 1, 3 ], [ 3, 1 ], [ 1, 1 ] ] ], // polygon 2
* ],
* });
* const b = multiPolygon([ // shortcut to above
* [ [ [ 0, 1 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ] ] ],
* [ [ [ 1, 1 ], [ 1, 3 ], [ 3, 1 ], [ 1, 1 ] ] ],
* ]);
* const c = fromWKT('MULTIPOLYGON (((0 1, 1 0, 1 1, 0 1)), ((1 1, 1 3, 3 1, 1 1)))');
*/
interface MultiPolygon<P = unknown> extends GeometryRef<P> {
readonly type: 'MultiPolygon';
toJSON(): Feature<MultiPolygon$1, P>;
clone(): MultiPolygon<P>;
}
/**
* Similar to the [GeoJSON_GeometryCollection]{@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.8}
* but allows for more geometry types.
*
* @template G - The type of JSON geometry
*/
interface JSON_GeometryCollection<G extends JSON_Geometry = JSON_Geometry> {
type: 'GeometryCollection';
geometries: G[];
}
interface JSON_CircularString {
type: 'CircularString';
coordinates: Position[];
}
interface JSON_CompoundCurve {
type: 'CompoundCurve';
segments: (LineString$1 | JSON_CircularString)[];
}
interface JSON_CurvePolygon {
type: 'CurvePolygon';
rings: (LineString$1 | JSON_CircularString | JSON_CompoundCurve)[];
}
interface JSON_MultiCurve {
type: 'MultiCurve';
curves: (LineString$1 | JSON_CircularString | JSON_CompoundCurve)[];
}
interface JSON_MultiSurface {
type: 'MultiSurface';
surfaces: (Polygon$1 | JSON_CurvePolygon)[];
}
/**
* Union type of JSON representation of all geometry types supported by GEOS.
*/
type JSON_Geometry = Point$1 | LineString$1 | Polygon$1 | MultiPoint$1 | MultiLineString$1 | MultiPolygon$1 | JSON_GeometryCollection | JSON_CircularString | JSON_CompoundCurve | JSON_CurvePolygon | JSON_MultiCurve | JSON_MultiSurface;
/**
* Similar to the [GeoJSON_Feature]{@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.2}
* but allows for more geometry types.
*
* @template G - The type of JSON geometry
*/
interface JSON_Feature<G extends JSON_Geometry | null = JSON_Geometry, P = any> {
type: 'Feature';
geometry: G;
id?: string | number | undefined;
properties: P;
}
/**
* Similar to the [GeoJSON_FeatureCollection]{@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.3}
* but allows for more geometry types.
*
* @template G - The type of JSON geometry
*/
interface JSON_FeatureCollection<G extends JSON_Geometry | null = JSON_Geometry, P = any> {
type: 'FeatureCollection';
features: JSON_Feature<G, P>[];
}
/**
* GeometryCollection is an instance of {@link GeometryRef} that represents the geometry collection.
*
* @see {@link geometryCollection} creates a geometry collection from an array of geometries
*
* @example
* const a = fromGeoJSON({
* type: 'GeometryCollection',
* geometries: [
* { type: 'Point', coordinates: [ 0, 0 ] },
* { type: 'LineString', coordinates: [ [ 0, 1 ], [ 1, 0 ] ] },
* ],
* });
* const b = geometryCollection([
* point([ 0, 0 ]),
* lineString([ [ 0, 1 ], [ 1, 0 ] ]),
* ]);
*/
interface GeometryCollection<P = unknown> extends GeometryRef<P> {
readonly type: 'GeometryCollection';
toJSON(): JSON_Feature<JSON_GeometryCollection, P>;
clone(): GeometryCollection<P>;
}
interface CircularString<P = unknown> extends GeometryRef<P> {
readonly type: 'CircularString';
toJSON(): JSON_Feature<JSON_CircularString, P>;
clone(): CircularString<P>;
}
interface CompoundCurve<P = unknown> extends GeometryRef<P> {
readonly type: 'CompoundCurve';
toJSON(): JSON_Feature<JSON_CompoundCurve, P>;
clone(): CompoundCurve<P>;
}
interface CurvePolygon<P = unknown> extends GeometryRef<P> {
readonly type: 'CurvePolygon';
toJSON(): JSON_Feature<JSON_CurvePolygon, P>;
clone(): CurvePolygon<P>;
}
interface MultiCurve<P = unknown> extends GeometryRef<P> {
readonly type: 'MultiCurve';
toJSON(): JSON_Feature<JSON_MultiCurve, P>;
clone(): MultiCurve<P>;
}
interface MultiSurface<P = unknown> extends GeometryRef<P> {
readonly type: 'MultiSurface';
toJSON(): JSON_Feature<JSON_MultiSurface, P>;
clone(): MultiSurface<P>;
}
type GeometryType = 'Point' | 'LineString' | 'LinearRing' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'CircularString' | 'CompoundCurve' | 'CurvePolygon' | 'MultiCurve' | 'MultiSurface';
type CoordinateType = 'XY' | 'XYZ' | 'XYZM' | 'XYM';
interface GeometryExtras<P> {
/**
* Optional identifier to be assigned to the geometry instance.
*/
id?: number | string;
/**
* Optional data to be assigned to the geometry instance.
*/
properties?: P;
}
/**
* Union type of all possible geometry types.
*
* Each geometry type is an instance of {@link GeometryRef}.
*
* @template P - The type of optional data assigned to a geometry instance.
*/
type Geometry<P = unknown> = Point<P> | LineString<P> | LinearRing<P> | Polygon<P> | MultiPoint<P> | MultiLineString<P> | MultiPolygon<P> | GeometryCollection<P> | CircularString<P> | CompoundCurve<P> | CurvePolygon<P> | MultiCurve<P> | MultiSurface<P>;
/**
* Class representing a GEOS geometry that exists in the Wasm memory.
*
* @template P - The type of optional data assigned to a geometry instance.
* Similar to the type of GeoJSON `Feature` properties field.
*/
declare class GeometryRef<P = unknown> {
/**
* Geometry type
*
* @example
* const type1 = fromWKT('POINT (1 1)').type; // 'Point'
* const type2 = fromWKT('LINESTRING (0 0, 1 1)').type; // 'LineString'
* const type3 = fromWKT('CIRCULARSTRING (0 0, 1 1, 2 0)').type; // 'CircularString'
*/
readonly type: GeometryType;
/**
* Geometry identifier, either number or string.
*
* Equivalent of GeoJSON feature id.
*/
id?: number | string;
/**
* Geometry additional data.
*
* Equivalent of GeoJSON feature properties or GEOS geometry user data.
*/
props: P;
/**
* Geometry can become detached when passed to a function that consumes
* it, for example {@link geometryCollection}, or when manually
* [freed]{@link GeometryRef#free}. Although this Geometry object still exists, the GEOS
* object that it used to represent no longer exists.
*
* @example
* const pt = point([ 0, 0 ]);
* const before = pt.detached; // falsy (undefined)
* pt.free(); // `pt` is no longer usable as a geometry
* const after = pt.detached; // true
*/
detached?: boolean;
/**
* Organizes the elements, rings, and coordinate order of geometries in a
* consistent way, so that geometries that represent the same object can
* be easily compared.
*
* Modifies the geometry in-place.
*
* Normalization ensures the following:
* - Lines are oriented to have smallest coordinate first (apart from duplicate endpoints)
* - Rings start with their smallest coordinate (using XY ordering)
* - Polygon **shell** rings are oriented **CW**, and **holes CCW**
* - Collection elements are sorted by their first coordinate
*
* Note the Polygon winding order, OGC standard uses the opposite convention
* and so does GeoJSON. Polygon ring orientation could be changed via {@link orientPolygons}.
*
* @returns The same geometry but normalized, modified in-place
*/
normalize(): this;
/**
* Enforces a ring orientation on all polygonal elements in the input geometry.
* Polygon exterior ring can be oriented clockwise (CW) or counter-clockwise (CCW),
* interior rings (holes) are oriented in the opposite direction.
*
* Modifies the geometry in-place. Non-polygonal geometries will not be modified.
*
* @param [exterior='cw'] - Exterior ring orientation. Interior rings are
* always oriented in the opposite direction.
* @returns The same geometry but with oriented rings, modified in-place
*
* @example exterior ring CCW, holes CW (GeoJSON compliance)
* polygonal = // (Multi)Polygon or GeometryCollection with some (Multi)Polygons
* polygonal.orientPolygons('ccw');
*
* @example exterior ring CW, holes CCW
* polygonal.orientPolygons('cw');
*/
orientPolygons(exterior?: 'cw' | 'ccw'): this;
/**
* Creates a deep copy of this geometry object.
*
* @returns A new geometry that is a copy of this geometry
*
* @example
* const original = point([ 0, 0 ]); // some geometry
* const copy = original.clone();
* // copy can be modified without affecting the original
*/
clone(): GeometryRef<P>;
/**
* Converts the geometry to a GeoJSON `Feature` object.
*
* This method allows the geometry to be serialized to JSON
* and is automatically called by `JSON.stringify()`.
*
* `geom.toJSON()` is equivalent of calling
* `toGeoJSON(geom, { flavor: 'extended', layout: 'XYZM' })`
*
* @returns A GeoJSON `Feature` representation of this geometry
*
* @see {@link toGeoJSON} converts geometry to a GeoJSON `Feature`
* or a GeoJSON `FeatureCollection` object.
*
* @example
* const geom = point([ 1, 2, 3 ]);
* const geojson = geom.toJSON();
* // {
* // type: 'Feature',
* // geometry: { type: 'Point', coordinates: [ 1, 2, 3 ] },
* // properties: null,
* // }
* const geojsonStr = JSON.stringify(geom);
* // '{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2,3]},"properties":null}'
*/
toJSON(): JSON_Feature<JSON_Geometry, P>;
/**
* Frees the Wasm memory allocated for the GEOS geometry object.
*
* {@link GeometryRef} objects are automatically freed when they are out of scope.
* This mechanism is provided by the [`FinalizationRegistry`]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry}
* that binds the lifetime of the Wasm resources to the lifetime of the JS objects.
*
* This method exists as a backup for those who find `FinalizationRegistry`
* unreliable and want a way to free the memory manually.
*
* Use with caution, as when the object is manually freed, the underlying
* Wasm resource becomes invalid and cannot be used anymore.
*
* @see {@link GeometryRef#detached}
*/
free(): void;
}
declare const __PREPARED__: unique symbol;
/**
* Branded type representing one of [geometries]{@link Geometry} that was
* [prepared]{@link prepare}.
*
* Geometry preparation is especially useful when a certain geometry will be
* compared many times with other geometries when computing spatial predicates
* or calculating distances.
*
* @template G - The type of prepared geometry, for example, {@link Geometry}
* or more specific {@link Polygon}
*/
type Prepared<G extends Geometry> = G & {
[__PREPARED__]: true;
};
/**
* 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:
* - {@link distance}
* - {@link nearestPoints}
* - {@link distanceWithin}
* - {@link intersects}
* - {@link disjoint}
* - {@link contains}
* - {@link containsProperly}
* - {@link within}
* - {@link covers}
* - {@link coveredBy}
* - {@link crosses}
* - {@link overlaps}
* - {@link touches}
* - {@link relate}
* - {@link relatePattern}
*
* Modifies the geometry in-place.
*
* @template G - The type of prepared geometry, for example, {@link Geometry}
* or more specific {@link Polygon}
* @param geometry - Geometry to prepare
* @returns Exactly the same geometry object, but with prepared internal
* spatial indexes
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link unprepare} frees prepared indexes
* @see {@link isPrepared} checks whether a geometry is prepared
* @see {@link https://libgeos.org/usage/c_api/#prepared-geometry}
*
* @example 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);
*
* @example to improve performance of repeated calls against a single geometry
* const a = buffer(point([ 0, 0 ]), 10, { quadrantSegments: 1000 });
* // `a` is a polygon with many vertices (4000 in this example)
* prepare(a);
* // the preparation of geometry `a` will improve the performance of repeated
* // supported functions (see list above) calls, but only those where `a` is
* // the first geometry
* const d1 = distance(a, point([ 10, 0 ]));
* const d2 = distance(a, point([ 10, 1 ]));
* const d3 = distance(point([ 10, 2 ]), a); // no benefit from prepared geometry
* const i1 = intersects(a, lineString([ [ 0, 22 ], [ 11, 0 ] ]));
* const i2 = intersects(a, lineString([ [ 0, 24 ], [ 11, 0 ] ]));
* const i3 = intersects(lineString([ [ 0, 26 ], [ 11, 0 ] ]), a); // no benefit
*/
declare function prepare<G extends Geometry>(geometry: G): Prepared<G>;
/**
* Frees the prepared internal spatial indexes.
*
* Call this function when you no longer need a performance boost, but need
* the geometry itself and want to reclaim some memory.
*
* The prepared internal spatial indexes will be automatically freed alongside
* the geometry itself, either when released via [`free`]{@link GeometryRef#free}
* or when geometry goes out of scope.
*
* Modifies the geometry in-place.
*
* @template G - The type of prepared geometry, for example, {@link Geometry}
* or more specific {@link Polygon}
* @param geometry - Geometry to free its prepared indexes
* @returns Exactly the same geometry object, but without prepared internal
* spatial indexes
*
* @see {@link prepare} prepares geometry internal spatial indexes
* @see {@link isPrepared} checks whether a geometry is prepared
* @see {@link https://libgeos.org/usage/c_api/#prepared-geometry}
*
* @example 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);
*/
declare function unprepare<G extends Geometry>(geometry: Prepared<G>): G;
interface GeoJSONInputOptions {
/**
* Coordinate layout for interpreting GeoJSON coordinates.
*
* Defines how to interpret the coordinates of input geometries.
* This does **not** force the dimension of the resulting geometries -
* the actual geometry dimension will be determined from the parsed data.
*
* Use this to:
* - Trim unwanted Z or M ordinates from the input.
* - Treat the third ordinate as M instead of Z.
*
* @default 'XYZM'
*/
layout?: CoordinateType;
}
/**
* Creates a {@link Geometry} from GeoJSON representation.
*
* This function has 2 overloads, when called with:
* - GeoJSON `Geometry` or GeoJSON `Feature` it returns a **single** geometry,
* - GeoJSON `FeatureCollection` it returns an **array** of geometries.
*
* In addition to the 7 standard GeoJSON geometries, this reader also supports
* JSON representation of other geometries supported by GEOS like
* {@link JSON_CircularString}, {@link JSON_CompoundCurve} or {@link JSON_CurvePolygon}.
*
* Reader expects that all positions in an input geometry have the same number
* of elements. The geometry coordinate dimension is determined from the first
* encountered position.
*
* @template P - The type of geometry/feature properties
* @param geojson - GeoJSON `Geometry`, `Feature` or `FeatureCollection`
* @param options - Optional GeoJSON input configuration
* @returns A new geometry object or an array of new geometry objects
* @throws {InvalidGeoJSONError} on GeoJSON feature without geometry
* @throws {InvalidGeoJSONError} on invalid GeoJSON geometry
*
* @see {@link point} shortcut to create `Point` geometry
* @see {@link lineString} shortcut to create `LineString` geometry
* @see {@link polygon} shortcut to create `Polygon` geometry
* @see {@link multiPoint} shortcut to create `MultiPoint` geometry
* @see {@link multiLineString} shortcut to create `MultiLineString` geometry
* @see {@link multiPolygon} shortcut to create `MultiPolygon` geometry
* @see {@link circularString} shortcut to create `CircularString` geometry
*
* @example
* const a = fromGeoJSON({
* type: 'Point',
* coordinates: [ 0, 0 ],
* });
* const b = fromGeoJSON({
* type: 'Feature',
* geometry: { type: 'Point', coordinates: [ 1, 0, 10 ] },
* properties: { name: 'B' },
* });
* const [ c ] = fromGeoJSON({
* type: 'FeatureCollection',
* features: [ {
* type: 'Feature',
* geometry: { type: 'Point', coordinates: [ 2, 0 ] },
* properties: { name: 'C' },
* } ],
* });
*
* const c_properties = a.props; // undefined
* const b_properties = b.props; // { name: 'B' }
* const a_properties = c.props; // { name: 'C' }
*
* @example 'layout' option
* const json = { type: 'Point', coordinates: [ 1, 2, 3, 4 ] };
*
* const xyzm = toWKT(fromGeoJSON(json, { layout: 'XYZM' })); // 'POINT ZM (1 2 3 4)'
* const xyz = toWKT(fromGeoJSON(json, { layout: 'XYZ' })); // 'POINT Z (1 2 3)'
* const xym = toWKT(fromGeoJSON(json, { layout: 'XYM' })); // 'POINT M (1 2 3)'
* const xy = toWKT(fromGeoJSON(json, { layout: 'XY' })); // 'POINT (1 2)'
*
* // 'layout' can only map or reduce the dimension it cannot increase it
* const xyNOTxyz = toWKT(fromGeoJSON(
* { type: 'Point', coordinates: [ 1, 2 ] },
* { layout: 'XYZ' },
* )); // 'POINT (1 2)'
*/
declare function fromGeoJSON<P>(geojson: Geometry$1 | Feature<Geometry$1, P> | JSON_Geometry | JSON_Feature<JSON_Geometry, P>, options?: GeoJSONInputOptions): Geometry<P>;
declare function fromGeoJSON<P>(geojson: FeatureCollection<Geometry$1, P> | JSON_FeatureCollection<JSON_Geometry, P>, options?: GeoJSONInputOptions): Geometry<P>[];
interface GeoJSONOutputOptions {
/**
* Geometry types support mode.
*
* - `strict` mode: only allows the 7 standard GeoJSON geometry types:
* Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon,
* and GeometryCollection.
* When an input geometry is not one of these types, an error will be thrown.
* - `extended` mode: allows serialization of all geometry types that GEOS
* supports, including curved geometries like CircularString, CompoundCurve,
* CurvePolygon, etc.
* The JSON structure of these geometries is not standardized and may change
* in future versions.
*
* @default 'strict'
*/
flavor?: 'strict' | 'extended';
/**
* Coordinate layout for the output GeoJSON.
*
* Defines the coordinate structure of the output geometries.
*
* Use this to:
* - Force 2D output by specifying 'XY'
* - Drop M ordinates while keeping Z ordinates with 'XYZ'
* - Drop Z ordinates while keeping M ordinates with 'XYM'
* - Keep both Z and M ordinates with 'XYZM'
*
* ⚠️ **Warning:** M ordinates (measure values) are not part of the official
* GeoJSON specification and may not be interpreted correctly by other parsers.
* Use 'XY' or 'XYZ' layouts for maximum interoperability.
*
* @default 'XYZ'
*/
layout?: CoordinateType;
}
interface ExtendedGeoJSONOutputOptions extends GeoJSONOutputOptions {
flavor: 'extended';
}
/**
* Converts a geometry object to a GeoJSON `Feature` object or a GeoJSON
* `FeatureCollection` object.
*
* This function has 2 overloads, when called with:
* - a **single** geometry object it returns a GeoJSON `Feature` object,
* - an **array** of geometry objects it returns a GeoJSON `FeatureCollection`
* object.
*
* @template P - The type of geometry/feature properties
* @param geometryies - The geometry object or the array of geometry objects
* to be converted into a GeoJSON object
* @param options - Optional GeoJSON output configuration
* @returns GeoJSON `Feature` or GeoJSON `FeatureCollection` object
* @throws {GEOSError} (`strict` mode only) when called with not standard GeoJSON geometry
*
* @see {@link GeometryRef#toJSON} converts geometry to a GeoJSON `Feature` object
*
* @example
* const a = point([ 0, 0 ]);
* const feature = toGeoJSON(a); // or `a.toJSON();`
* // { type: 'Feature', geometry: {...}, properties: null }
*
* const b = point([ 1, 0 ]);
* const featureCollection = toGeoJSON([ a, b ]);
* // { type: 'FeatureCollection', features: [ {...}, {...} ] }
*
* @example 'flavor' option
* const curvedGeometry = fromWKT('CIRCULARSTRING (10 20, 20 30, 30 20)');
*
* // by default only the standard GeoJSON geometries are supported:
* // toGeoJSON(curvedGeometry); // this will throw
*
* const json = toGeoJSON(curvedGeometry, { flavor: 'extended' });
* // { type: 'Feature', geometry: {...}, properties: null }
*
* @example 'layout' option
* toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XYZM' }); // will extract [ 1, 2, 3, 4 ]
* toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XYZ' }); // [ 1, 2, 3 ]
* toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XYM' }); // [ 1, 2, 4 ]
* toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XY' }); // [ 1, 2 ]
* toGeoJSON(fromWKT('POINT M (1 2 4)'), { layout: 'XYZM' }); // [ 1, 2, NaN, 4 ]
* toGeoJSON(fromWKT('POINT M (1 2 4)'), { layout: 'XYZ' }); // [ 1, 2 ]
* toGeoJSON(fromWKT('POINT (1 2)'), { layout: 'XYZM' }); // [ 1, 2 ]
* toGeoJSON(fromWKT('POINT (1 2)'), { layout: 'XYZ' }); // [ 1, 2 ]
*/
declare function toGeoJSON<P>(geometryies: Geometry<P>, options: ExtendedGeoJSONOutputOptions): JSON_Feature<Geometry$1, P>;
declare function toGeoJSON<P>(geometryies: Geometry<P>, options?: GeoJSONOutputOptions): Feature<Geometry$1, P>;
declare function toGeoJSON<P>(geometryies: Geometry<P>[], options: ExtendedGeoJSONOutputOptions): JSON_FeatureCollection<Geometry$1, P>;
declare function toGeoJSON<P>(geometryies: Geometry<P>[], options?: GeoJSONOutputOptions): FeatureCollection<Geometry$1, P>;
interface JSONInputOptions<P> extends GeometryExtras<P>, GeoJSONInputOptions {
}
interface GEOSInputOptions<P> extends GeometryExtras<P> {
/**
* Whether to consume the input geometries - consumed geometries become
* [detached]{@link GeometryRef#detached}, are no longer valid and should
* **not** be used.
*
* When `true` the ownership of input geometries is passed to created
* collection geometry, no extra copies are made, but the input geometries
* can no longer be used on their own.
*
* When `false` the [clones]{@link GeometryRef#clone} of input geometries
* are used to create a collection geometry.
*
* @default false
*/
consume?: boolean;
}
/**
* Creates a {@link Point} geometry from a position.
*
* @param pt - Point coordinates
* @param options - Optional geometry options
* @returns A new Point geometry
*
* @example
* const a = point([ 0, 0 ]);
* const b = point([ 2, 0 ], { properties: { name: 'B' } });
*/
declare function point<P>(pt: Position, options?: JSONInputOptions<P>): Point<P>;
/**
* Creates a {@link LineString} geometry from an array of positions.
*
* Line string must contain at least 2 positions.
* Empty line strings with 0 positions are allowed.
*
* @param pts - LineString coordinates
* @param options - Optional geometry options
* @returns A new LineString geometry
* @throws {InvalidGeoJSONError} on line with 1 position
*
* @example
* const a = lineString([ [ 0, 0 ], [ 2, 1 ], [ 0, 2 ] ]);
* const b = lineString([ [ 2, 0 ], [ 4, 0 ] ], { properties: { name: 'B' } });
*/
declare function lineString<P>(pts: Position[], options?: JSONInputOptions<P>): LineString<P>;
/**
* Creates a {@link Polygon} geometry from an array of linear rings coordinates.
*
* The first ring represents the exterior ring (shell), subsequent rings
* represent interior rings (holes). Each ring must be a closed line string
* with first and last positions identical and contain at least 3 positions.
* Empty polygons without any rings are allowed.
*
* @param ppts - Polygon coordinates
* @param options - Optional geometry options
* @returns A new Polygon geometry
* @throws {InvalidGeoJSONError} if any ring is invalid (not closed or with 1 or 2 positions)
*
* @example
* const a = polygon([ [ [ 4, 3 ], [ 5, 4 ], [ 5, 3 ], [ 4, 3 ] ] ]);
* const b = polygon([
* [ [ 0, 0 ], [ 0, 8 ], [ 8, 8 ], [ 8, 0 ], [ 0, 0 ] ],
* [ [ 2, 2 ], [ 6, 2 ], [ 6, 6 ], [ 2, 2 ] ],
* ], { properties: { name: 'B' } });
*/
declare function polygon<P>(ppts: Position[][], options?: JSONInputOptions<P>): Polygon<P>;
/**
* Creates a {@link MultiPoint} geometry from an array of positions or an array
* of [Points]{@link Point}.
*
* @param data - MultiPoint coordinates or an array of Points
* @param options - Optional geometry options
* @returns A new MultiPoint geometry
* @throws {GEOSError} when any of the input geometries is not a {@link Point}
*
* @example
* // from coordinates
* const a = multiPoint([ [ 0, 0 ], [ 2, 0 ], [ 4, 0 ] ]);
* const b = multiPoint([ [ 1, 0 ], [ 3, 0 ] ], { properties: { name: 'B' } });
*
* // from point geometries
* const parts = [
* point([ 1, 1 ]),
* point([ 2, 1 ]),
* point([ 3, 1 ]),
* ];
* const c = multiPoint(parts, { id: 'C' });
* const consumableParts = [
* point([ 1, 2 ]),
* point([ 3, 2 ]),
* ];
* const d = multiPoint(consumableParts, { consume: true });
* // all `consumableParts` are detached
*/
declare function multiPoint<P>(pts: Position[], options?: JSONInputOptions<P>): MultiPoint<P>;
declare function multiPoint<P>(points: Point[], options?: GEOSInputOptions<P>): MultiPoint<P>;
/**
* Creates a {@link MultiLineString} geometry from an array of line strings coordinates
* or an array of [LineStrings]{@link LineString}.
*
* Each line string must contain at least 2 positions.
* Empty line strings with 0 positions are allowed.
*
* @param data - MultiLineString coordinates or an array of LineStrings
* @param options - Optional geometry options
* @returns A new MultiLineString geometry
* @throws {InvalidGeoJSONError} on line with 1 position
* @throws {GEOSError} when any of the input geometries is not a {@link LineString}
*
* @example
* // from coordinates
* const a = multiLineString([
* [ [ -10, 3 ], [ 5, 4 ] ],
* [ [ -10, 7 ], [ 5, 6 ] ],
* ]);
* const b = multiLineString([
* [ [ 0, 0 ], [ 10, 5 ], [ 0, 10 ] ],
* [ [ 1, 0 ], [ 12, 5 ], [ 1, 10 ] ],
* ], { properties: { name: 'B' } });
*
* // from line string geometries
* const parts = [
* lineString([ [ -14, 10 ], [ -14, -4 ], [ 16, -4 ] ]),
* lineString([ [ 16, 0 ], [ 16, 14 ], [ -14, 14 ] ]),
* ];
* const c = multiLineString(parts, { id: 'C' });
* const consumableParts = [
* lineString([ [ -15, 11 ], [ -15, -5 ], [ 17, -5 ] ]),
* lineString([ [ 17, -1 ], [ 17, 15 ], [ -15, 15 ] ]),
* ];
* const d = multiLineString(consumableParts, { consume: true });
* // all `consumableParts` are detached
*/
declare function multiLineString<P>(ppts: Position[][], options?: JSONInputOptions<P>): MultiLineString<P>;
declare function multiLineString<P>(lines: LineString[], options?: GEOSInputOptions<P>): MultiLineString<P>;
/**
* Creates a {@link MultiPolygon} geometry from an array of polygon coordinates
* or an array of [Polygons]{@link Polygon}.
*
* Each polygon must consist of an array of linear rings coordinates.
* The first ring represents the exterior ring (shell), subsequent rings
* represent interior rings (holes). Each ring must be a closed line string
* with first and last positions identical and contain at least 3 positions.
* Empty polygons without any rings are allowed.
*
* @param data - MultiPolygon coordinates or an array of Polygons
* @param options - Optional geometry options
* @returns A new MultiPolygon geometry
* @throws {InvalidGeoJSONError} if any ring is invalid (not closed or with 1 or 2 positions)
* @throws {GEOSError} when any of the input geometries is not a {@link Polygon}
*
* @example
* // from coordinates
* const a = multiPolygon([
* [ [ [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 1, 0 ] ] ],
* [ [ [ 1, 1 ], [ 1, 2 ], [ 2, 1 ], [ 1, 1 ] ] ],
* ]);
* const b = multiPolygon([
* [ [ [ 0, 1 ], [ 1, 2 ], [ 1, 1 ], [ 0, 1 ] ] ],
* [ [ [ 1, 0 ], [ 1, 1 ], [ 2, 1 ], [ 1, 0 ] ] ],
* ], { properties: { name: 'B' } });
*
* // from polygon geometries
* const parts = [
* polygon([ [ [ 0, 0 ], [ 0, 1 ], [ 1, 0 ], [ 0, 0 ] ] ]),
* polygon([ [ [ 1, 2 ], [ 2, 2 ], [ 2, 1 ], [ 1, 2 ] ] ]),
* ];
* const c = multiPolygon(parts, { id: 'C' });
* const consumableParts = [
* polygon([ [ [ 0, 1 ], [ 0, 2 ], [ 1, 2 ], [ 0, 1 ] ] ]),
* polygon([ [ [ 1, 0 ], [ 2, 1 ], [ 2, 0 ], [ 1, 0 ] ] ]),
* ];
* const d = multiPolygon(consumableParts, { consume: true });
* // all `consumableParts` are detached
*/
declare function multiPolygon<P>(pppts: Position[][][], options?: JSONInputOptions<P>): MultiPolygon<P>;
declare function multiPolygon<P>(polygons: Polygon[], options?: GEOSInputOptions<P>): MultiPolygon<P>;
/**
* Creates a {@link GeometryCollection} geometry from an array of [Geometries]{@link Geometry}.
*
* @param geometries - Array of geometry objects to be included in the collection
* @param options - Optional geometry options
* @returns A new GeometryCollection geometry containing all input geometries
*
* @example
* const parts = [
* polygon([ [ [ 4, 1 ], [ 4, 3 ], [ 8, 2 ], [ 4, 1 ] ] ]),
* lineString([ [ 0, 2 ], [ 5, 2 ] ]),
* ];
* const a = geometryCollection(parts);
* const consumableParts = [
* lineString([ [ 6, 3 ], [ 9, 2 ], [ 6, 1 ] ]),
* point([ 10, 2 ]),
* ];
* const b = geometryCollection(consumableParts, { consume: true });
* // all `consumableParts` are detached
*/
declare function geometryCollection<P>(geometries: Geometry[], options?: GEOSInputOptions<P>): GeometryCollection<P>;
/**
* Creates a {@link CircularString} geometry from an array of points.
*
* Circular string is a sequence of connected circular arcs, where circular arc
* is defined by 3 points:
* - start point,
* - some point on the arc,
* - end point.
*
* Circular string must have at least 3 points (one circular arc), each
* consecutive arc adds 2 points (arc start points is the end point from the
* previous arc), so the total number of points must be odd.
* Empty circular strings with 0 points are allowed.
*
* @param pts - CircularString coordinates
* @param options - Optional geometry options
* @returns A new CircularString geometry
* @throws {InvalidGeoJSONError} if total number of points is even or equal to 1
*
* @example
* const a = circularString([ [ 0, 0 ], [ 2, 8 ], [ 8, 0 ] ]);
* // the same arc but defined by different middle point:
* const b = circularString([ [ 0, 0 ], [ 6, 8 ], [ 8, 0 ] ]);
*
* // the first point of each arc (except the 1st) is the last point from prev arc
* const c = circularString([
* [ 12, 4 ], [ 14, 8 ], [ 16, 4 ], // arc 1: from [ 12, 4 ] via [ 14, 8 ] to [ 16, 4 ]
* [ 18, 0 ], [ 20, 4 ], // arc 2: from [ 16, 4 ] via [ 18, 0 ] to [ 20, 4 ]
* [ 22, 8 ], [ 24, 4 ], // arc 3: from [ 20, 4 ] via [ 22, 8 ] to [ 24, 4 ]
* [ 26, 0 ], [ 28, 4 ], // arc 4: from [ 24, 4 ] via [ 26, 0 ] to [ 28, 4 ]
* ]);
*/
declare function circularString<P>(pts: Position[], options?: JSONInputOptions<P>): CircularString<P>;
/**
* Creates a {@link CompoundCurve} geometry from an array of continuous segments.
*
* Each segment can be either {@link LineString} or {@link CircularString},
* they need to be connected - the first point of a segment is the same as the
* last point from the previous segment.
* Empty compound curves without any segments are allowed.
*
* @param geometries - Array of compound curve segments
* @param options - Optional geometry options
* @returns A new CompoundCurve geometry
* @throws {GEOSError} when any of the input geometries is not a {@link LineString},
* or {@link CircularString}
* @throws {GEOSError} when input segments are not continuous
* @throws {GEOSError} when input segments includes empty geometry
*
* @example
* const a = compoundCurve([
* lineString([ [ 0, 10 ], [ 0, 0 ], [ 5, 0 ], [5, 5] ]),
* circularString([ [ 5, 5], [ 10, 10 ], [ 10, 0 ] ]),
* ]);
*/
declare function compoundCurve<P>(geometries: (LineString | CircularString)[], options?: GEOSInputOptions<P>): CompoundCurve<P>;
/**
* Creates a {@link CurvePolygon} geometry from an array of rings.
*
* Each ring can be either {@link LineString}, {@link CircularString}
* or {@link CompoundCurve}, they need to be closed - the first and the last
* points are the same.
*
* Empty curve polygons without any rings are allowed.
*
* @param geometries - Array of curve polygon rings
* @param options - Optional geometry options
* @returns A new CurvePolygon geometry
* @throws {GEOSError} when any of the input geometries is not a {@link LineString},
* {@link CircularString} or {@link CompoundCurve}
*
* @example
* const a = curvePolygon([
* // shell (face)
* circularString([ [ 1, 5 ], [ 5, 9 ], [ 9, 5 ], [ 5, 1 ], [ 1, 5 ] ]),
* // hole 1 (mouth)
* compoundCurve([
* circularString([ [ 3, 5 ], [ 5, 2 ], [ 7, 5 ] ]),
* lineString([ [ 7, 5 ], [ 3, 5 ] ]),
* ]),
* // hole 2 (round eye)
* circularString([ [ 3, 7 ], [ 3, 6 ], [ 4, 6 ], [ 4, 7 ], [ 3, 7 ] ]),
* // hole 3 (square eye)
* lineString([ [ 6, 7 ], [ 6, 6 ], [ 7, 6 ], [ 7, 7 ], [ 6, 7 ] ]),
* ]);
*/
declare function curvePolygon<P>(geometries: (LineString | CircularString | CompoundCurve)[], options?: GEOSInputOptions<P>): CurvePolygon<P>;
/**
* Creates a {@link MultiCurve} geometry from an array of curves.
*
* Each curve can be either {@link LineString}, {@link CircularString}
* or {@link CompoundCurve}.
*
* @param geometries - Array of curve geometry objects to be included in the collection
* @param options - Optional geometry options
* @returns A new MultiCurve geometry
* @throws {GEOSError} when any of the input geometries is not a {@link LineString},
* {@link CircularString} or {@link CompoundCurve}
*
* @example
* const parts = [
* // G
* compoundCurve([
* circularString([ [ 20, 20 ], [ 10, 15 ], [ 20, 10 ] ]),
* lineString([ [ 20, 10 ], [ 20, 14 ], [ 16, 14 ] ]),
* ]),
* // E
* lineString([ [ 33, 20 ], [ 23, 20 ], [ 23, 10 ], [ 33, 10 ] ]),
* lineString([ [ 23, 15 ], [ 28, 15 ] ]),
* ]
* const a = multiCurve(parts);
* const consumableParts = [
* // O
* circularString([ [ 40, 20 ], [ 35, 15 ], [ 40, 10 ], [ 45, 15 ], [ 40, 20 ] ]),
* // S
* circularString([ [ 53, 20 ], [ 51, 21 ], [ 51, 17 ], [ 51, 9 ], [ 47, 11 ] ]),
* ]
* const b = multiCurve(consumableParts, { consume: true });
* // all `consumableParts` are detached
*/
declare function multiCurve<P>(geometries: (LineString | CircularString | CompoundCurve)[], options?: GEOSInputOptions<P>): MultiCurve<P>;
/**
* Creates a {@link MultiSurface} geometry from an array of surfaces.
*
* Each surface can be either {@link Polygon}, or {@link CurvePolygon}.
*
* @param geometries - Array of surface geometry objects to be included in the collection
* @param options - Optional geometry options
* @returns A new MultiSurface geometry
* @throws {GEOSError} when any of the input geometries is not a {@link Polygon}
* or {@link CurvePolygon}
*
* @example
* const kier = curvePolygon([
* circularString([
* [ 10, 0 ], [ 5, 13 ], [ 2, 17 ], [ 5, 25 ], [ 10, 21 ],
* [ 15, 25 ], [ 18, 17 ], [ 15, 13 ], [ 10, 0 ],
* ]),
* ]);
* const trefl = curvePolygon([
* circularString([
* [ 24, 0 ], [ 27, 4 ], [ 29, 13 ], [ 21, 13 ], [ 27, 18 ],
* [ 30, 25 ], [ 33, 18 ], [ 39, 13 ], [ 31, 13 ], [ 33, 4 ],
* [ 36, 0 ], [ 30, 1 ], [ 24, 0 ],
* ]),
* ]);
* const karo = curvePolygon([
* circularString([
* [ 43, 13 ], [ 47, 19 ], [ 50, 25 ], [ 53, 19 ], [ 57, 13 ],
* [ 53, 7 ], [ 50, 1 ], [ 47, 7 ], [ 43, 13 ],
* ]),
* ]);
* const suits = multiSurface([ kier, trefl, karo ]);
*/
declare function multiSurface<P>(geometries: (Polygon | CurvePolygon)[], options?: GEOSInputOptions<P>): MultiSurface<P>;
/**
* Creates a rectangular {@link Polygon} geometry from bounding box coordinates.
*
* Polygon is oriented clockwise.
*
* @param bbox - Array of four numbers `[ xMin, yMin, xMax, yMax ]`
* @param options - Optional geometry options
* @returns A new Polygon geometry
* @throws {GEOSError} when box is degenerated: width or height is `0`
*
* @see {@link bounds} calculates bounding box of an existing geometry
*
* @example
* const a = box([ 0, 0, 4, 4 ]); // <POLYGON ((0 0, 0 4, 4 4, 4 0, 0 0))>
* const b = box([ 5, 0, 8, 1 ]); // <POLYGON ((5 0, 5 1, 8 1, 8 0, 5 0))>
*/
declare function box<P>(bbox: number[], options?: GeometryExtras<P>): Polygon<P>;
declare class InvalidGeoJSONError extends GEOSError {
/** Invalid geometry */
geometry: unknown;
/** More detailed error reason */
details?: string;
}
interface WKTInputOptions {
/**
* Automatically repair structural errors in the input (currently just unclosed rings) while reading.
* @default false
*/
fix?: boolean;
}
/**
* Creates a {@link Geometry} from Well-Known Text (WKT) representation.
*
* @param wkt - String containing WKT representation of the geometry
* @param options - Optional WKT input configuration
* @returns A new geometry object created from the WKT string
* @throws {GEOSError} on invalid WKT string
*
* @see {@link https://libgeos.org/specifications/wkt}
*
* @example
* const pt = fromWKT('POINT(0 2)');
* const line = fromWKT('LINESTRING(1 2, 2 2, 2 0)');
* const poly = fromWKT('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))');
*
* @example will fix unclosed ring
* const poly = fromWKT('POLYGON((0 0, 1 0, 1 1))', { fix: true });
*/
declare function fromWKT(wkt: string, options?: WKTInputOptions): Geometry;
interface WKTOutputOptions {
/**
* Output dimensionality of the writer.
* @default 4
*/
dim?: 2 | 3 | 4;
/**
* Number places after the decimal to output in WKT.
* @default 16
*/
precision?: number;
/**
* Trim trailing 0's from the output coordinates.
* @default true
*/
trim?: boolean;
}
/**
* Converts a geometry object to its Well-Known Text (WKT) representation.
*
* @param geometry - The geometry object to be converted to WKT
* @param options - Optional WKT output configuration
* @returns String with WKT representation of the geometry
*
* @see {@link https://libgeos.org/specifications/wkt}
*
* @example
* const pt = point([ 1.1234, 1.9876, 10 ]);
* const wkt1 = toWKT(pt); // 'POINT Z (1.1234 1.9876 10)'
* const wkt2 = toWKT(pt, { dim: 2 }); // 'POINT (1.1234 1.9876)'
* const wkt3 = toWKT(pt, { precision: 2 }); // 'POINT Z (1.12 1.99 10)'
*/
declare function toWKT(geometry: Geometry, options?: WKTOutputOptions): string;
interface WKBInputOptions {
/**
* Automatically repair structural errors in the input (currently just unclosed rings) while reading.
* @default false
*/
fix?: boolean;
}
/**
* Creates a {@link Geometry} from Well-Known Binary (WKB) representation.
*
* @param wkb - Binary data containing WKB representation of the geometry
* @param options - Optional WKB input configuration
* @returns A new geometry object created from the WKB data
* @throws {GEOSError} on invalid WKB data
*
* @see {@link https://libgeos.org/specifications/wkb}
*
* @example
* const wkb = new Uint8Array([
* 1, // 1 - LE
* 1, 0, 0, 0, // 1 - point
* 105, 87, 20, 139, 10, 191, 5, 64, // Math.E - x
* 24, 45, 68, 84, 251, 33, 9, 64, // Math.PI - y
* ]);
* const pt = fromWKB(wkb); // point([ Math.E, Math.PI ]);
*/
declare function fromWKB(wkb: Uint8Array, options?: WKBInputOptions): Geometry;
interface WKBOutputOptions {
/**
* Output dimensionality of the writer.
* @default 4
*/
dim?: 2 | 3 | 4;
/**
* Output flavor of the writer.
* - [`extended`]{@link https://libgeos.org/specifications/wkb/#extended-wkb}
* - [`iso`]{@link https://libgeos.org/specifications/wkb/#iso-wkb}
* @default 'extended'
*/
flavor?: 'extended' | 'iso';
/**
* Output byte order of the writer.
* Little/Big Endian.
* @default 'le'
*/
byteOrder?: 'le' | 'be';
/**
* Whether SRID values should be output in WKB.
* Many WKB readers do not support SRID values, use with caution.
* @default false
*/
srid?: boolean;
}
/**
* Converts a geometry object to its Well-Known Binary (WKB) representation.
*
* @param geometry - The geometry object to be converted to WKB
* @param options - Optional WKB output configuration
* @returns A Uint8Array containing the WKB representation of the geometry
*
* @see {@link https://libgeos.org/specifications/wkb}
*
* @example
* const pt = point([ Math.E, Math.PI, 1 ]);
* const wkb1 = toWKB(pt); // Uint8Array([...])
* const wkb2 = toWKB(pt, { dim: 2 }); // Uint8Array([...])
*/
declare function toWKB(geometry: Geometry, options?: WKBOutputOptions): Uint8Array;
interface DensifyOptions {
/**
* Optional fraction by which densify each line segment.
*
* Each segment will be split into a number of equal-length subsegments, whose
* fraction of the total length is closest to the given fraction.
* Value of `0.25` means that each segment will be split into four equal length
* subsegments.
*
* The closer to `0` the better the approximation of the distance.
*/
densify?: number;
}
/**
* Calculates the bounds (also named bbox - bounding box or extent) of the geometry.
* The bounds are the minimum rectangle that contains the entire geometry.
*
* @param geometry - The geometry for which the bounds are calculated
* @returns An array of four numbers `[ xMin, yMin, xMax, yMax ]`
* @throws {GEOSError} when called on an empty geometry
*
* @see {@link box} creates Polygon geometry from the bounds array
*
* @example
* const pt = point([ 3, 1 ]);
* const ptExtent = bounds(pt); // [ 3, 1, 3, 1 ]
* const poly = polygon([ [ [ 3, 3 ], [ 9, 4 ], [ 5, 1 ], [ 3, 3 ] ] ]);
* const polyExtent = bounds(poly); // [ 3, 1, 9, 4 ]
*/
declare function bounds(geometry: Geometry): [xMin: number, yMin: number, xMax: number, yMax: number];
/**
* Calculates the area of a geometry.
*
* Areal geometries have a non-zero area.
* Others return 0.
*
* @param geometry - The geometry for which the area is calculated
* @returns The area of the geometry
*
* @example
* const pt = point([ 3, 1 ]);
* const ptArea = area(pt); // 0
* const line = lineString([ [ 8, 1 ], [ 9, 1 ] ]);
* const lineArea = area(pt); // 0
* const poly = polygon([ [ [ 3, 3 ], [ 9, 4 ], [ 5, 1 ], [ 3, 3 ] ] ]);
* const polyArea = area(poly); // 7
*/
declare function area(geometry: Geometry): number;
/**
* Calculates the length of a geometry.
*
* Linear geometries return their length.
* Areal geometries return their perimeter.
* Others return 0.
*
* @param geometry - The geometry for which the length is calculated
* @returns The length of the geometry
*
* @example
* const pt = point([ 0, 1 ]);
* const ptLength = length(pt); // 0
* const line = lineString([ [ 0, 0 ], [ 1, 1 ] ]);
* const lineLength = length(line); // 1.4142135623730951 = Math.sqrt(2)
* const poly = polygon([ [ [ 1, 0 ], [ 2, 1 ], [ 3, 0 ], [ 1, 0 ] ] ]);
* const polyLength = length(poly); // 4.82842712474619 = Math.sqrt(2) * 2 + 2
*/
declare function length(geometry: Geometry): number;
/**
* Computes the Cartesian distance between geometry `a` and geometry `b`.
*
* Distance is in input geometry units.
*
* @param a - First geometry
* @param b - Second geometry
* @returns The distance between geometries
* @throws {GEOSError} on unsupported geometry types (curved)
* @throws {GEOSError} when either geometry is empty
*
* @see {@link distanceWithin} returns `true` when two geometries are within a given distance
* @see {@link nearestPoints} finds the nearest points of two geometries
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example distance between point and line
* const a = point([ 0, 0 ]);
* const b = lineString([ [ 0, 1 ], [ 1, 0 ] ]);
* const ab_dist = distance(a, b); // 0.7071067811865476 = Math.sqrt(2) / 2
*
* @example distance between line and polygon
* const a = lineString([ [ -1, 1 ], [ 1, -1 ] ]);
* const b = polygon([ [ [ 1, 1 ], [ 1, 2 ], [ 2, 1 ], [ 1, 1 ] ] ]);
* const ab_dist = distance(a, b); // 1.4142135623730951 = Math.sqrt(2)
*
* @example distance between two polygons
* const a = polygon([ [ [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ], [ 0, 0 ] ] ]);
* const b = polygon([ [ [ 2, 2 ], [ 3, 2 ], [ 3, 3 ], [ 2, 2 ] ] ]);
* const ab_dist = distance(a, b); // 1.4142135623730951 = Math.sqrt(2)
*/
declare function distance(a: Geometry | Prepared<Geometry>, b: Geometry): number;
/**
* Computes the discrete Hausdorff distance between geometry `a` and geometry `b`.
* The [Hausdorff distance]{@link https://en.wikipedia.org/wiki/Hausdorff_distance}
* is a measure of similarity: it is the greatest distance between any point in
* `a` and the closest point in `b`.
*
* The discrete distance is an approximation of this metric: only vertices are
* considered. The parameter `options.densify` makes this approximation less coarse
* by splitting the line segments between vertices before computing the distance.
*
* @param a - First geometry
* @param b - Second geometry
* @param options - Optional options object
* @returns Approximation of Hausdorff distance between geometries
* @throws {GEOSError} on unsupported geometry types (curved)
* @throws {GEOSError} when either geometry is empty
* @throws {GEOSError} when `options.densify` is not in the range `(0.0, 1.0]`
*
* @see {@link frechetDistance}
*
* @example
* const a = lineString([ [ 0, 0 ], [ 100, 0 ], [ 10, 100 ] ]);
* const b = lineString([ [ 0, 100 ], [ 0, 10 ], [ 80, 10 ] ]);
* const ab_hDist = hausdorffDistance(a, b); // 22.360679774997898 - approximation is not close
* const ab_hDist_d = hausdorffDistance(a, b, { densify: 0.001 }); // 47.89
*/
declare function hausdorffDistance(a: Geometry, b: Geometry, options?: DensifyOptions): number;
/**
* Compute the discrete Fréchet distance between geometry `a` and geometry `b`.
* The [Fréchet distance]{@link https://en.wikipedia.org/wiki/Fr%C3%A9chet_distance}
* is a measure of similarity: it is the greatest distance between any point in
* `a` and the closest point in `b`.
*
* The discrete distance is an approximation of this metric: only vertices are
* considered. The parameter `options.densify` makes this approximation less coarse
* by splitting the line segments between vertices before computing the distance.
*
* Fréchet distance sweep continuously along their respective curves and the
* direction of curves is significant. This makes it a better measure of similarity
* than Hausdorff distance for curve or surface matching.
*
* @param a - First geometry
* @param b - Second geometry
* @param options - Optional options object
* @returns Approximation of Fréchet distance between geometries
* @throws {GEOSError} on unsupported geometry types (curved)
* @throws {GEOSError} when either geometry is empty
* @throws {GEOSError} when `options.densify` is not in the range `(0.001, 1.0]`
*
* @see {@link hausdorffDistance}
*
* @example
* const a = lineString([ [ 0, 0 ], [ 100, 0 ] ]);
* const b = lineString([ [ 0, 0 ], [ 50, 50 ], [ 100, 0 ] ]);
* const ab_fDist = frechetDistance(a, b); // 70.71067811865476
* const ab_fDist_d = frechetDistance(a, b, { densify: 0.5 }); // 50
*
* @example with a comparison to Hausdorff distance
* const a = lineString([ [ 0, 0 ], [ 50, 200 ], [ 100, 0 ], [ 150, 200 ], [ 200, 0 ] ]);
* const b1 = lineString([ [ 0, 200 ], [ 200, 150 ], [ 0, 100 ], [ 200, 50 ], [ 0, 0 ] ]);
* const b2 = lineString([ [ 0, 0 ], [ 200, 50 ], [ 0, 100 ], [ 200, 150 ], [ 0, 200 ] ]);
* const ab1_hDist = hausdorffDistance(a, b1); // 48.507125007266595
* const ab2_hDist = hausdorffDistance(a, b2); // 48.507125007266595
* const ab1_fDist = frechetDistance(a, b1); // 200
* const ab2_fDist = frechetDistance(a, b2); // 282.842712474619
*/
declare function frechetDistance(a: Geometry, b: Geometry, options?: DensifyOptions): number;
/**
* Finds the nearest points between geometry `a` and geometry `b`.
*
* The returned points can be points along a line segment, not necessarily
* one of the vertices of the input geometries.
*
* @param a - First geometry
* @param b - Second geometry
* @returns An array with two point geometries, first is the nearest point
* from the geometry `a` second from the geometry `b`
* @throws {GEOSError} on unsupported geometry types (curved)
* @throws {GEOSError} when either geometry is empty
*
* @see {@link distance} computes the distance between two geometries
* @see {@link distanceWithin} returns `true` when two geometries are within a given distance
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example nearest points between point and line
* const a = point([ 0, 0 ]);
* const b = lineString([ [ 0, 1 ], [ 1, 0 ] ]);
* const [ a_pt, b_pt ] = nearestPoints(a, b); // [ <POINT (0 0)>, <POINT (0.5 0.5)> ]
*
* @example nearest points between two polygons
* const a = polygon([ [ [ 0, 0 ], [ 0, 2 ], [ 1, 0 ], [ 0, 0 ] ] ]);
* const b = polygon([ [ [ 1, 1 ], [ 2, 1 ], [ 2, 2 ], [ 1, 2 ], [ 1, 1 ] ] ]);
* const [ a_pt, b_pt ] = nearestPoints(a, b); // [ <POINT (0.6 0.8)>, <POINT (1 1)> ]
*/
declare function nearestPoints(a: Geometry | Prepared<Geometry>, b: Geometry): [a: Point, b: Point];
interface PrecisionGridOptions {
/**
* Precision grid cell size for snapping vertices.
*
* If 0 or when not defined, the highest precision is used (IEE754 double),
* which provides _almost_ 16 decimal digits of precision.
*
* If nonzero, input as well as resulting coordinates will be snapped to
* a precision grid of that size.
*/
gridSize?: number;
}
interface BufferOptions {
/**
* The default number of facets into which to divide a fillet
* of 90 degrees.
*
* A value of 8 gives less than 2% max error in the buffer distance.
* For a max error of < 1%, use QS = 12.
* For a max error of < 0.1%, use QS = 18.
* The error is always less than the buffer distance.
* @default 8
*/
quadrantSegments?: number;
/**
* Cap styles control the ends of buffered lines.
* - `round` - End is rounded, with end point of original line in the center of the round cap.
* - `flat` - End is flat, with end point of original line at the end of the buffer.
* - `square` - End is flat, with end point of original line in the middle of a square enclosing that point.
* @default 'round'
*/
endCapStyle?: 'round' | 'flat' | 'square';
/**
* Join styles control the buffer shape at bends in a line.
* - `round` - Join is rounded, essentially each line is terminated in a round cap. Form round corner.
* - `mitre` - Join is flat, with line between buffer edges, through the join point. Forms flat corner.
* - `bevel` - Join is the point at which the two buffer edges intersect. Forms sharp corner.
* @default 'round'
*/
joinStyle?: 'round' | 'mitre' | 'bevel';
/**
* For acute angles, a mitre join can extend very very far from the input geometry,
* which is probably not desired. The mitre limit places an upper bound on that.
* @default 5.0
*/
mitreLimit?: number;
/**
* Sets whether the computed buffer should be single-sided.
* A single-sided buffer is constructed on only one side of each input line.
*
* The side used is determined by the sign of the buffer distance:
* - a positive distance indicates the left-hand side
* - a negative distance indicates the right-hand side
*
* The single-sided buffer of point geometries is the same as the regular buffer.
*
* The `endCapStyle` for single-sided buffers is always
* ignored and forced to the equivalent of `flat`.
* @default false
*/
singleSided?: boolean;
}
/**
* Creates a buffer around a geometry with a specified distance.
* Distance is in input geometry units.
*
* @param geometry - The geometry to buffer
* @param distance - The buffer distance. Positive values expand the geometry, negative values shrink it
* @param options - Optional parameters to control buffer generation
* @returns A new, buffered, geometry
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @example create a simple buffer around a point
* const pt = point([ 0, 0 ]);
* const circle = buffer(pt, 10);
*
* @example create a buffer around a line
* const line = lineString([ [ 0, 0 ], [ 10, 10 ], [ 25, 10 ] ]);
* const path1 = buffer(line, 2, { endCapStyle: 'square' });
* const path2 = buffer(line, 4, { endCapStyle: 'flat' });
*
* @example create a buffer that shrinks the geometry
* const poly = polygon([ [ [ 0, 0 ], [ 0, 8 ], [ 8, 8 ], [ 8, 0 ], [ 0, 0 ] ] ]);
* const shrunken = buffer(poly, -2);
* // shrunk to nothing
* const empty1 = buffer(polygon([ [ [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 0 ] ] ]), -5); // 'POLYGON EMPTY'
* // negative or zero-distance buffer of point or line - always empty
* const empty2 = buffer(lineString([ [ 0, 0 ], [ 10, 10 ] ]), 0); // 'POLYGON EMPTY'
* const empty3 = buffer(point([ 0, 0 ]), 0); // 'POLYGON EMPTY'
*/
declare function buffer(geometry: Geometry, distance: number, options?: BufferOptions): Polygon | MultiPolygon;
/**
* Computes the difference of geometry `a` with geometry `b`.
* The result is a geometry that contains all points that are in
* geometry `a` but not in geometry `b`.
*
* @param a - First geometry
* @param b - Second geometry
* @param options - Optional options object
* @returns A new geometry representing the difference
*
* @example difference of two polygons
* const a = polygon([ [ [ 0, 4 ], [ 5, 5 ], [ 4, 0 ], [ 0, 4 ] ] ]);
* const b = polygon([ [ [ 0, 0 ], [ 5, 6 ], [ 9, 5 ], [ 0, 0 ] ] ]);
* const ab_diff = difference(a, b);
* const ab_diff_pg = difference(a, b, { gridSize: 0.1 });
* const ba_diff = difference(b, a);
*
* @example difference of two lines
* const a = lineString([ [ 2, 8 ], [ 10, 8 ] ]);
* const b = lineString([ [ 4.123456789, 8 ], [ 10, 8 ] ]);
* const ab_diff = difference(a, b); // 'LINESTRING (2 8, 4.123456789 8)'
* const ab_diff_pg = difference(a, b, { gridSize: 1e-6 }); // 'LINESTRING (2 8, 4.123457 8)'
*/
declare function difference(a: Geometry, b: Geometry, options?: PrecisionGridOptions): Geometry;
/**
* Computes the intersection of geometry `a` with geometry `b`.
* The result is a geometry that contains all points that are both
* in geometry `a` and geometry `b`.
*
* @param a - First geometry
* @param b - Second geometry
* @param options - Optional options object
* @returns A new geometry representing the intersection
*
* @example intersection of two polygons
* const a = polygon([ [ [ 0, 4 ], [ 5, 5 ], [ 4, 0 ], [ 0, 4 ] ] ]);
* const b = polygon([ [ [ 0, 0 ], [ 5, 6 ], [ 9, 5 ], [ 0, 0 ] ] ]);
* const ab_int = intersection(a, b);
* const ab_int_pg = intersection(a, b, { gridSize: 0.1 });
* const ba_int = intersection(b, a);
*
* @example intersection of two lines
* const a = fromWKT('LINESTRING (0 0, 10 10)');
* const b = fromWKT('LINESTRING (0 1, 10 4)');
* const ab_int = intersection(a, b); // 'POINT (1.4285714285714286 1.4285714285714286)'
* const ab_int_pg = intersection(a, b, { gridSize: 1e-6 }); // 'POINT (1.428571 1.428571)'
*/
declare function intersection(a: Geometry, b: Geometry, options?: PrecisionGridOptions): Geometry;
/**
* Computes the symmetric difference of geometry `a` with geometry `b`.
* The result is a geometry that contains all points that are in either
* geometry but not in both geometries (the union minus the intersection).
*
* @param a - First geometry
* @param b - Second geometry
* @param options - Optional options object
* @returns A new geometry representing the symmetric difference
*
* @example symmetric difference of two lines
* const a = lineString([ [ 50, 100 ], [ 50, 200 ] ]);
* const b = lineString([ [ 50, 50 ], [ 50, 150 ] ]);
* const ab_sDiff = symmetricDifference(a, b); // 'MULTILINESTRING ((50 150, 50 200), (50 50, 50 100))'
* const ab_sDiff_pg = symmetricDifference(a, b, { gridSize: 15 }); // 'MULTILINESTRING ((45 150, 45 195), (45 45, 45 105))'
* const ba_sDiff = symmetricDifference(b, a); // 'MULTILINESTRING ((50 50, 50 100), (50 150, 50 200))'
*/
declare function symmetricDifference(a: Geometry, b: Geometry, options?: PrecisionGridOptions): Geometry;
/**
* Computes the (self) union of all components of geometry `a`.
* This is particularly useful for reducing MultiGeometries or
* GeometryCollections into their minimal representation, merging
* overlapping elements and removing duplicates.
*
* @param a - Geometry
* @param options - Optional options object
* @returns A new geometry representing the union of all components
*
* @example dissolving overlapping polygons in a MultiPolygon
* const a = fromWKT('MULTIPOLYGON (((0 0, 0 10, 10 10, 10 0, 0 0), (1 9, 8 8, 9 1, 1 9)), ((5 10, 15 15, 10 5, 5 10)))');
* const a_uUnion = unaryUnion(a);
* // 'POLYGON ((0 10, 5 10, 15 15, 10 5, 10 0, 0 0, 0 10), (1 9, 9 1, 8.166666666666666 6.833333333333333, 6.833333333333333 8.166666666666666, 1 9))'
* const a_uUnion_pg = unaryUnion(a, { gridSize: 1e-4 });
* // 'POLYGON ((0 10, 5 10, 15 15, 10 5, 10 0, 0 0, 0 10), (1 9, 9 1, 8.1667 6.8333, 6.8333 8.1667, 1 9))'
*
* @example should remove duplicated points
* const a = multiPoint([ [ 4, 5 ], [ 6, 7 ], [ 4, 5 ], [ 6, 5 ], [ 6, 7 ] ]);
* const a_uUnion = unaryUnion(a); // 'MULTIPOINT ((4 5), (6 5), (6 7))'
* const a_uUnion_pg = unaryUnion(a, { gridSize: 2 }); // 'MULTIPOINT ((4 6), (6 6), (6 8))'
*/
declare function unaryUnion(a: Geometry, options?: PrecisionGridOptions): Geometry;
/**
* Computes the union of geometry `a` with geometry `b`.
* The result is a geometry that contains all points that
* are in either geometry `a` or geometry `b`.
*
* @param a - First geometry
* @param b - Second geometry
* @param options - Optional options object
* @returns A new geometry representing the union
*
* @example union of two polygons
* const a = fromWKT('POLYGON ((10.01 10, 10 5, 5 5, 5 10, 10.01 10))');
* const b = fromWKT('POLYGON ((10 15, 15 15, 15 7, 10.01 7, 10 15))');
* const ab_union = union(a, b);
* // 'POLYGON ((10 5, 5 5, 5 10, 10.00625 10, 10 15, 15 15, 15 7, 10.01 7, 10.007692307692308 8.846153846153847, 10 5))'
* const ab_union_pg = union(a, b, { gridSize: 0.1 });
* // 'POLYGON ((10 5, 5 5, 5 10, 10 10, 10 15, 15 15, 15 7, 10 7, 10 5))'
*/
declare function union(a: Geometry, b: Geometry, options?: PrecisionGridOptions): Geometry;
interface MakeValidOptions {
/**
* 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
* @default 'linework'
*/
method?: 'linework' | 'structure';
/**
* Only 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.
* @default false
*/
keepCollapsed?: boolean;
}
/**
* 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.
*
* @param geometry - The geometry to repair
* @param options - Optional parameters to control the algorithm
* @returns A new repaired geometry
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link isValid} checks whether a geometry is already valid
*
* @example
* const poly = fromWKT('POLYGON ((2.22 2.28, 7.67 2.06, 10.98 7.7, 9.39 5, 7.96 7.12, 6.77 5.16, 7.43 6.24, 3.7 7.22, 5.72 5.77, 4.18 10.74, 2.2 6.83, 2.22 2.28))');
* const valid1 = makeValid(poly);
* const valid2 = makeValid(poly, { method: 'structure' });
*
* @example polygon with hole partially outside shell
* const poly = polygon([ [ [ 0, 0 ], [ 0, 2 ], [ 2, 0 ], [ 0, 0 ] ], [ [ 0.5, 0.5 ], [ 2, 1 ], [ 2, 0.5 ], [ 0.5, 0.5 ] ] ]);
* const valid1 = makeValid(poly);
* const valid2 = makeValid(poly, { method: 'structure' });
*
* @example
* const lineInDisguise = polygon([ [ [ 0, 0 ], [ 1, 1 ], [ 1, 2 ], [ 1, 1 ], [ 0, 0 ] ] ]);
* const valid1 = makeValid(lineInDisguise);
* // MULTILINESTRING ((0 0, 1 1), (1 1, 1 2))
* const valid2 = makeValid(lineInDisguise, { method: 'structure', keepCollapsed: true });
* // LINESTRING (0 0, 1 1, 1 2, 1 1, 0 0)
* const valid3 = makeValid(lineInDisguise, { method: 'structure' });
* // POLYGON EMPTY
*/
declare function makeValid(geometry: Geometry, options?: MakeValidOptions): Geometry;
interface SimplifyOptions {
/**
* Whether to preserve the original topology during simplification.
*
* When `true`, a topology‐preserving variant of the Douglas–Peucker
* algorithm is used. The output will be [valid]{@link isValid} and
* [simple]{@link isSimple} if the input is.
* This option is computationally more expensive.
*
* When `false`, the standard Douglas–Peucker simplification is used,
* which may produce invalid or self‐intersecting geometries.
*
* @default true
*/
preserveTopology?: boolean;
}
/**
* Computes a simplified representation of a geometry using the [Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm).
*
* Simplification reduces the number of vertices by removing those which are
* within the tolerance distance of the simplified linework.
*
* The simplification tolerance is in input geometry units.
*
* @param geometry - The geometry to simplify
* @param tolerance - The maximum allowed deviation - any vertex within this distance
* of the simplified linework is removed
* @param options - Optional options object
* @returns A new, simplified, geometry without "unnecessary" vertices
* @throws {GEOSError} when `tolerance` is negative
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @example
* const o1 = multiLineString([
* [ [ 10, 60 ], [ 39, 50 ], [ 70, 60 ], [ 90, 53 ] ],
* [ [ 35, 55 ], [ 46, 55 ] ],
* [ [ 65, 55 ], [ 75, 55 ] ],
* [ [ 10, 40 ], [ 40, 30 ], [ 70, 40 ], [ 90, 30 ] ],
* ]);
* const s1 = simplify(o1, 10);
*
* const o2 = multiLineString([
* [ [ 110, 60 ], [ 139, 50 ], [ 170, 60 ], [ 190, 53 ] ],
* [ [ 135, 55 ], [ 146, 55 ] ],
* [ [ 165, 55 ], [ 175, 55 ] ],
* [ [ 110, 40 ], [ 140, 30 ], [ 170, 40 ], [ 190, 30 ] ],
* ]);
* const s2 = simplify(o2, 10, { preserveTopology: false });
*
* @example
* const o1 = multiPolygon([
* [
* [ [ 10, 10 ], [ 10, 20 ], [ 20, 70 ], [ 10, 80 ], [ 20, 80 ], [ 50, 90 ], [ 70, 80 ], [ 90, 80 ], [ 85, 20 ], [ 90, 10 ], [ 50, 0 ], [ 10, 10 ] ],
* [ [ 80, 20 ], [ 20, 20 ], [ 50, 90 ], [ 80, 20 ] ],
* [ [ 30, 9 ], [ 70, 9 ], [ 50, 0 ], [ 30, 9 ] ],
* ],
* [ [ [ 0, 50 ], [ 0, 75 ], [ 15, 65 ], [ 5, 30 ], [ 0, 50 ] ] ],
* [ [ [ 90, 20 ], [ 95, 60 ], [ 95, 10 ], [ 90, 20 ] ] ],
* ]);
* const s1 = simplify(o1, 10);
*
* const o2 = multiPolygon([
* [
* [ [ 130, 10 ], [ 130, 20 ], [ 140, 70 ], [ 130, 80 ], [ 140, 80 ], [ 170, 90 ], [ 190, 80 ], [ 210, 80 ], [ 205, 20 ], [ 210, 10 ], [ 170, 0 ], [ 130, 10 ] ],
* [ [ 200, 20 ], [ 140, 20 ], [ 170, 90 ], [ 200, 20 ] ],
* [ [ 150, 9 ], [ 190, 9 ], [ 170, 0 ], [ 150, 9 ] ],
* ],
* [ [ [ 120, 50 ], [ 120, 75 ], [ 135, 65 ], [ 125, 30 ], [ 120, 50 ] ] ],
* [ [ [ 210, 20 ], [ 215, 60 ], [ 215, 10 ], [ 210, 20 ] ] ],
* ]);
* const s2 = simplify(o2, 10, { preserveTopology: false });
*
*/
declare function simplify(geometry: Geometry, tolerance: number, options?: SimplifyOptions): Geometry;
/**
* Checks whether a `value` is a [geometry]{@link Geometry} object created
* by the `geos.js`.
*
* @param value - The value to check
* @returns `true` if value is a geometry object created by the `geos.js`
*
* @example
* const t1 = isGeometry(fromWKT('POINT EMPTY')); // true
* const t2 = isGeometry(point([ 0, 0 ])); // true
*
* const f1 = isGeometry('POINT (0 0)'); // false
* const f2 = isGeometry({ type: 'Point', coordinates: [ 0, 0 ] }); // false
*/
declare function isGeometry(value: unknown): value is Geometry;
/**
* Checks whether a geometry is [prepared]{@link prepare}.
*
* @template G - The type of geometry, for example, {@link Geometry}
* or more specific {@link Polygon}
* @param geometry - The geometry to check
* @returns `true` if geometry is prepared
*
* @see {@link prepare} prepares geometry internal spatial indexes
* @see {@link unprepare} frees prepared indexes
*
* @example
* const p = buffer(point([ 0, 0 ]), 10, { quadrantSegments: 1000 });
* const before = isPrepared(p); // false
* prepare(p);
* const after = isPrepared(p); // true
* unprepare(p);
* const afterer = isPrepared(p); // false
*/
declare function isPrepared<G extends Geometry>(geometry: G): geometry is Prepared<G>;
/**
* Returns whether the geometry is empty.
* If the geometry or any component is non-empty, the geometry is non-empty.
* An empty geometry has no boundary or interior.
*
* @param geometry - The geometry to check
* @returns `true` when geometry is empty, `false` otherwise
*
* @example
* const a = point([]);
* const a_empty = isEmpty(a); // true
* const b = point([ 0, 0 ]);
* const b_empty = isEmpty(b); // false
*/
declare function isEmpty(geometry: Geometry): boolean;
/**
* Returns `true` when the geometry is simple as defined by the OGC SFS
* (Simple Feature Specification).
* Simple means that any self-intersections are only at boundary points.
* Mostly relevant for line strings.
*
* Simplicity is defined for each Geometry type as follows:
* - Point geometries are simple
* - MultiPoint geometries are simple if every point is unique
* - LineString geometries are simple if they do not self-intersect at interior
* points (i.e. points other than the endpoints). LinearRings - closed line
* strings which intersect only at their endpoints are simple
* - MultiLineString geometries are simple if their elements are simple and
* they intersect only at points which are boundary points of both elements
* - Polygonal geometries have no definition of simplicity.
* The `isSimple` code checks if all polygon rings are simple.
* This means that isSimple cannot be used to test for ALL self-intersections
* in Polygons. Use {@link isValid} to check polygonal geometries for
* self-intersections
* - GeometryCollection geometries are simple if all their elements are simple
* - Empty geometries are simple
*
* @param geometry - The geometry to check
* @returns `true` when geometry is simple, `false` otherwise
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link isValid} checks whether a geometry is well-formed
*
* @example
* const a = lineString([ [ 0, 0 ], [ 2, 2 ], [ 1, 2 ], [ 1, 0 ] ]);
* const a_simple = isSimple(a); // false - self-intersection
*
* const b = multiLineString([ [ [ 2, 0 ], [ 4, 2 ] ], [ [ 3, 2 ], [ 4, 2 ] ] ]);
* const b_simple = isSimple(b); // true - intersection at endpoints is ok
*
* const c = lineString([ [ 4, 0 ], [ 5, 1 ], [ 5, 2 ], [ 6, 1 ], [ 5, 1 ] ]);
* const c_simple = isSimple(c); // false - intersection not at the endpoints
*
* const d = lineString([ [ 7, 1 ], [ 7, 2 ], [ 8, 1 ], [ 7, 1 ] ]);
* const d_simple = isSimple(d); // true - ring
*/
declare function isSimple(geometry: Geometry): boolean;
declare class TopologyValidationError extends GEOSError {
/** Array with X and Y coordinates of the point at which the error occurred. */
location: [x: number, y: number];
}
interface IsValidOptions {
/**
* Sets how to treat a polygon with self-touching rings.
*
* If set to `true` the following self-touching conditions are treated
* as being valid (ESRI SDE model):
* - **inverted shell** - the shell ring self-touches to create a hole
* touching the shell
* - **exverted hole** - a hole ring self-touches to create two holes
* touching at a point
*
* If set to `false` the above conditions, following the OGC SFS standard,
* are treated as not valid.
*
* @default false
*/
isInvertedRingValid?: boolean;
}
/**
* Returns `true` when the geometry is well-formed and valid in 2D according to
* the OGC rules. For geometries with 3 and 4 dimensions, the validity is still
* only tested in 2 dimensions.
*
* Validity is defined for each Geometry type as follows:
* - Point coordinates must be finite (not `NaN` or `Infinity`)
* - MultiPoint points must all be valid
* - LineString must have at least 2 unique points
* - MultiLineString lines must all be valid
* - LinearRing must have at lest 4 unique points, be closed (first and last
* point must be equal), be [simple]{@link isSimple} i.e. must not self-intersect
* except at endpoints
* - Polygon interior must be connected (some hole cannot split interior into parts)
* - Shell (exterior ring) must be a valid LinearRing, not be self-touching
* (could be configured by `options.isInvertedRingValid` parameter),
* not be exverted ("bow-tie" configuration)
* - Holes (interior rings) each must be a valid LinearRing, be completely
* inside the shell, not be nested inside other holes, not self-touch
* to create disconnected interiors, not be "C-shaped" with self-touching
* that creates islands
* - MultiPolygon polygons must all be valid, no polygon can be in the interior
* of another polygon, shells cannot partially overlap or touch along an edge
* - GeometryCollection geometries must all be valid
* - Empty geometries are valid
*
* @param geometry - The geometry to check
* @param options - Optional options object
* @returns `true` when geometry is valid, `false` otherwise
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link isValidOrThrow} throws an error when geometry is not valid
* @see {@link makeValid} repairs invalid geometries
*
* @example
* const line = lineString([ [ 1, 1 ], [ 2, 2 ] ]);
* const line_valid = isValid(line); // true
*
* const poly = polygon([ // self-touching exterior ring forming hole
* [ [ 0, 0 ], [ 0, 10 ], [ 10, 0 ], [ 0, 0 ], [ 4, 2 ], [ 2, 4 ], [ 0, 0 ] ],
* ]);
* const poly_valid1 = isValid(poly); // false
* const poly_valid2 = isValid(poly, { isInvertedRingValid: true }); // true
*/
declare function isValid(geometry: Geometry, options?: IsValidOptions): boolean;
/**
* Asserts whether the geometry is valid.
* Same as {@link isValid} but when geometry is not valid instead
* of returning `false` throws an error with the reason of invalidity
* and with the XY location of the point at which the error occurred.
* When geometry is valid, it does nothing.
*
* @param geometry - The geometry to check
* @param options - Optional options object
* @throws {GEOSError} on unsupported geometry types (curved)
* @throws {TopologyValidationError} on invalid geometry
*
* @see {@link isValid} checks whether a geometry is valid (`true`/`false`)
* @see {@link makeValid} repairs invalid geometries
*
* @example
* isValidOrThrow(lineString([ [ 0, 0 ], [ 1, 1 ] ])); // pass
* const selfTouchingExteriorRingFormingHole = polygon([
* [ [ 0, 0 ], [ 0, 10 ], [ 10, 0 ], [ 0, 0 ], [ 4, 2 ], [ 2, 4 ], [ 0, 0 ] ],
* ]);
* isValidOrThrow(selfTouchingExteriorRingFormingHole, { isInvertedRingValid: true }); // pass
* isValidOrThrow(selfTouchingExteriorRingFormingHole); // throw
* // TopologyValidationError { message: 'Ring Self-intersection', location: [ 0, 0 ] }
*
* isValidOrThrow(polygon([ [ [ 0, 0 ], [ 1, 1 ], [ 1, 0 ], [ 0, 1 ], [ 0, 0 ] ] ])); // throw
* // TopologyValidationError { message: 'Self-intersection', location: [ 0.5, 0.5 ] }
*/
declare function isValidOrThrow(geometry: Geometry, options?: IsValidOptions): void;
/**
* Returns `true` if geometries `a` and `b` are of the same type and have the
* same vertices in the same order on the XY plane.
*
* Vertices are checked by index so any additional midpoint or reversed order
* results in the geometries not being considered equal.
*
* Vertices are compared only by their X and Y values, Z and M values are
* ignored.
*
* @param a - First geometry
* @param b - Second geometry
* @param tolerance - Tolerance to determine vertex equality
* @returns `true` if geometries `a` and `b` are of the same type and have
* matching vertices
*
* @see {@link equals} checks if two geometries are topologically equal
* @see {@link equalsIdentical} checks whether two geometries are of the same
* type and have exactly the same vertices in the same order on the XYZM plane
* @see {@link GeometryRef#normalize} normalized geometries are easier to compare
*
* @example
* const a = lineString([ [ 0, 0, 100 ], [ 8, 0, 101 ] ]);
*
* // only XY are compared
* const t1 = equalsExact(a, lineString([ [ 0, 0 ], [ 8, 0 ] ]), 0);
* // Z and M are ignored
* const t2 = equalsExact(a, lineString([ [ 0, 0, 100 ], [ 8, 0, 102 ] ]), 0);
* // with a tolerance
* const t3 = equalsExact(a, lineString([ [ 0, 0 ], [ 7.9999, 0 ] ]), 0.001);
*
* // wrong type
* const f1 = equalsExact(a, multiLineString([ [ [ 0, 0 ], [ 8, 0 ] ] ]), 0)
* // extra midpoint
* const f2 = equalsExact(a, lineString([ [ 0, 0 ], [ 4, 0 ], [ 8, 0 ] ]), 0)
* // reversed order -> wrong first point
* const f3 = equalsExact(a, lineString([ [ 8, 0 ], [ 0, 0 ] ]), 0);
*/
declare function equalsExact(a: Geometry, b: Geometry, tolerance: number): boolean;
/**
* Returns `true` if geometries `a` and `b` are of the same type and have
* exactly the same vertices in the same order on the XYZM plane.
*
* Vertices are checked by index so any additional midpoint or reversed order
* results in the geometries not being considered equal.
*
* `NaN` values are considered to be equal to other `NaN` values.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometries `a` and `b` are of the same type and have
* matching vertices
*
* @see {@link equals} checks if two geometries are topologically equal
* @see {@link equalsExact} checks whether two geometries are of the same type
* and have the same vertices in the same order on the XY plane
* @see {@link GeometryRef#normalize} normalized geometries are easier to compare
*
* @example
* const a = lineString([ [ 0, 0, 100 ], [ 8, 0, 101 ] ]);
*
* const t1 = equalsIdentical(a, lineString([ [ 0, 0, 100 ], [ 8, 0, 101 ] ]));
*
* // wrong type
* const f1 = equalsIdentical(a, multiLineString([ [ [ 0, 0, 100 ], [ 8, 0, 101 ] ] ]));
* // missing Z value
* const f2 = equalsIdentical(a, lineString([ [ 0, 0 ], [ 8, 0 ] ]));
* // wrong Z value
* const f3 = equalsIdentical(a, lineString([ [ 0, 0, 100 ], [ 8, 0, 102 ] ]));
* // extra midpoint
* const f4 = equalsIdentical(a, lineString([ [ 0, 0 ], [ 4, 0 ], [ 8, 0 ] ]));
* // reversed order -> wrong first point
* const f5 = equalsIdentical(a, lineString([ [ 8, 0, 101 ], [ 0, 0, 100 ] ]));
*/
declare function equalsIdentical(a: Geometry, b: Geometry): boolean;
/**
* Returns `true` when the distance between two geometries is within the given
* distance, `false` otherwise.
*
* Returns `false` when negative distance is given or when either geometry is empty.
*
* Distance is in input geometry units.
*
* @param a - First geometry
* @param b - Second geometry
* @param maxDistance - The maximum distance
* @returns `true` when the distance between the geometries is less than or equal
* to the given distance, `false` otherwise
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link distance} computes the distance between two geometries
* @see {@link nearestPoints} finds the nearest points of two geometries
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example
* const a = point([ 0, 0 ]);
* const b = lineString([ [ 0, 10 ], [ 10, 0 ] ]);
* const d = distance(a, b); // 7.0710678118654755 = 5 * Math.sqrt(2)
* const dwithin_70 = distanceWithin(a, b, 7.0); // false
* const dwithin_71 = distanceWithin(a, b, 7.1); // true
*/
declare function distanceWithin(a: Geometry | Prepared<Geometry>, b: Geometry, maxDistance: number): boolean;
/**
* Returns `true` if geometries `a` and `b` are topologically equal.
*
* Geometry `a` is topologically equal to geometry `b` if their interiors
* intersect and no part of the interior or boundary of one geometry intersects
* the exterior of the other.
*
* That means that the geometries must have the same dimension, and they
* occupy the same space. They do not need to have the same vertices or even
* the same type (MultiLine can be equal to Line, GeometryCollection to Polygon
* etc).
*
* Like other spatial predicates, `equals` operates in 2D only; it ignores any
* Z or M ordinates.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometry `a` is topologically equal to geometry `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link equalsExact} checks whether two geometries are of the same type
* and have the same vertices in the same order on the XY plane
* @see {@link equalsIdentical} checks whether two geometries are of the same
* type and have exactly the same vertices in the same order on the XYZM plane
*
* @example
* const a = lineString([ [ 0, 0 ], [ 8, 0 ] ]);
* const b = lineString([ [ 8, 0 ], [ 0, 0 ] ]);
* const c = lineString([ [ 0, 0, 100 ], [ 8, 0, 101 ] ]);
* const d = multiLineString([
* [ [ 0, 0 ], [ 5, 0 ] ],
* [ [ 8, 0 ], [ 3, 0 ] ],
* ]);
* const e = geometryCollection([
* lineString([ [ 0, 0 ], [ 5, 0 ] ]),
* lineString([ [ 5, 0 ], [ 8, 0 ] ]),
* ]);
* const ab_equal = equals(a, b); // true
* const ac_equal = equals(a, c); // true (Z and M are ignored)
* const ad_equal = equals(a, d); // true
* const ae_equal = equals(a, e); // true
* const emptyEmpty = equals(point([]), polygon([])); // true
*/
declare function equals(a: Geometry, b: Geometry): boolean;
/**
* Returns `true` if geometries `a` and `b` have at least one point in common.
*
* Intersects implies that {@link disjoint} is `false`.\
* Intersects is implied by {@link contains}, {@link containsProperly},
* {@link within}, {@link covers}, {@link coveredBy}, {@link crosses},
* {@link overlaps} and {@link touches}.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if the intersection of geometry `a` and `b` is **not** an
* empty set
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link disjoint} returns whether geometries **not** intersect; `intersects(a, b) === !disjoint(a, b)`
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example
* const a = lineString([ [ 0, 2 ], [ 2, 0 ] ]);
* const b = point([ 0, 0 ]);
* const ab_intersect = intersects(a, b); // false
*
* const c = lineString([ [ 4, 2 ], [ 6, 0 ] ]);
* const d = point([ 5, 1 ]);
* const cd_intersect = intersects(c, d); // true
*/
declare function intersects(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometries `a` and `b` have no points in common.
*
* Disjoint implies that {@link intersects} and ({@link contains},
* {@link containsProperly}, {@link within}, {@link covers}, {@link coveredBy},
* {@link crosses}, {@link overlaps} and {@link touches}) are all `false`.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if the intersection of geometry `a` and `b` is an empty set
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link intersects} returns whether geometries intersect; `disjoint(a, b) === !intersects(a, b)`
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example
* const a = lineString([ [ 0, 2 ], [ 2, 0 ] ]);
* const b = point([ 0, 0 ]);
* const ab_disjoint = disjoint(a, b); // true
*
* const c = lineString([ [ 4, 2 ], [ 6, 0 ] ]);
* const d = point([ 5, 1 ]);
* const cd_disjoint = disjoint(c, d); // false
*/
declare function disjoint(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometry `b` lies in geometry `a` and their interiors intersect.
*
* Geometry `a` contains geometry `b` if all points of `b` are in the interior
* or at the boundary of `a` and the interiors of `a` and `b` have at least one
* point in common.
*
* Note:
* According to the definition above, a **geometry does not contain its
* boundary**, so for example, a LineString that is completely contained in
* the boundary of a Polygon is not considered to be contained in that Polygon.
*
* In most cases {@link covers} should be used, as it has a simpler definition
* and allows for additional optimizations.
*
* `contains` is the converse of {@link within}: `contains(a, b) === within(b, a)`.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometry `a` contains geometry `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link within} converse of `contains`
* @see {@link covers} more inclusive `contains`
* @see {@link containsProperly} less inclusive `contains`
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example contains: true
* const a = lineString([ [ 0, 13 ], [ 4, 15 ], [ 2, 10 ] ]);
* const b = multiPoint([ [ 2, 10 ], [ 4, 15 ] ]);
* const ab_contain = contains(a, b); // true
*
* const c = polygon([ [ [ 10, 13 ], [ 14, 15 ], [ 15, 10 ], [ 10, 13 ] ] ]);
* const d = multiPoint([ [ 12, 14 ], [ 13, 14 ] ]);
* const cd_contain = contains(c, d); // true
*
* const e = polygon([ [ [ 0, 0 ], [ 0, 5 ], [ 5, 5 ], [ 5, 0 ], [ 0, 0 ] ] ]);
* const f = lineString([ [ 0, 5 ], [ 5, 5 ], [ 0, 0 ] ]);
* const ef_contain = contains(e, f); // true
*
* const g = polygon([ [ [ 10, 0 ], [ 10, 5 ], [ 15, 5 ], [ 15, 0 ], [ 10, 0 ] ] ]);
* const h = polygon([ [ [ 11, 2 ], [ 14, 5 ], [ 15, 1 ], [ 11, 2 ] ] ]);
* const gh_contain = contains(g, h); // true
*
* @example contains: false
* const a = lineString([ [ 0, 13 ], [ 4, 15 ], [ 2, 10 ] ]);
* const b = point([ 2, 10 ]);
* const ab_contain = contains(a, b); // false - no interior point in common
*
* const c = polygon([ [ [ 10, 13 ], [ 14, 15 ], [ 15, 10 ], [ 10, 13 ] ] ]);
* const d = lineString([ [ 10, 13 ], [ 14, 15 ], [ 15, 10 ] ]);
* const cd_contain = contains(c, d); // false - no interior point in common
*
* const e = polygon([
* [ [ 0, 0 ], [ 0, 5 ], [ 5, 5 ], [ 5, 0 ], [ 0, 0 ] ],
* [ [ 2, 2 ], [ 2, 4 ], [ 4, 4 ], [ 4, 2 ], [ 2, 2 ] ],
* ]);
* const f = multiPoint([ [ 1, 1 ], [ 3, 3 ] ]);
* const ef_contain = contains(e, f); // false
*
* const g = polygon([ [ [ 10, 0 ], [ 10, 5 ], [ 15, 5 ], [ 15, 0 ], [ 10, 0 ] ] ]);
* const h = lineString([ [ 12, 1 ], [ 16, 1 ] ]);
* const gh_contain = contains(g, h); // false
*/
declare function contains(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometry `b` lies in the interior of geometry `a`.
*
* Geometry `a` contains geometry `b` properly if all points of `b` are in the
* interior of `a`.
*
* Info:
* This function needs the geometry `a` to be prepared.\
* If geometry `a` is not prepared this function will {@link prepare} it.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometry `a` contains geometry `b` properly
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link contains} more inclusive `containsProperly`
* @see {@link covers} more inclusive `contains`
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example differences with 'contains'
* const a = lineString([ [ 0, 13 ], [ 4, 15 ], [ 2, 10 ] ]);
* const b = multiPoint([ [ 2, 10 ], [ 4, 15 ] ]);
* const ab_contain = contains(a, b); // true
* const ab_containsProperly = containsProperly(a, b); // false - `b` intersect boundary of `a`
*
* const c = polygon([ [ [ 10, 13 ], [ 14, 15 ], [ 15, 10 ], [ 10, 13 ] ] ]);
* const d = multiPoint([ [ 12, 14 ], [ 13, 14 ] ]);
* const cd_contain = contains(c, d); // true
* const cd_containsProperly = containsProperly(c, d); // false - `b` intersect boundary of `a`
*
* const e = polygon([ [ [ 0, 0 ], [ 0, 5 ], [ 5, 5 ], [ 5, 0 ], [ 0, 0 ] ] ]);
* const f = lineString([ [ 0, 5 ], [ 5, 5 ], [ 0, 0 ] ]);
* const ef_contain = contains(e, f); // true
* const ef_containsProperly = containsProperly(e, f); // false - `b` intersect boundary of `a`
*
* const g = polygon([ [ [ 10, 0 ], [ 10, 5 ], [ 15, 5 ], [ 15, 0 ], [ 10, 0 ] ] ]);
* const h = polygon([ [ [ 11, 2 ], [ 14, 5 ], [ 15, 1 ], [ 11, 2 ] ] ]);
* const gh_contain = contains(g, h); // true
* const gh_containsProperly = containsProperly(g, h); // false - `b` intersect boundary of `a`
*
* @example above example, but adjusted to 'containsProperly'
* const a = lineString([ [ 0, 13 ], [ 4, 15 ], [ 2, 10 ] ]);
* const b = multiPoint([ [ 3, 12.5 ], [ 4, 15 ] ]);
* const ab_containsProperly = containsProperly(a, b); // true
*
* const c = polygon([ [ [ 10, 13 ], [ 14, 15 ], [ 15, 10 ], [ 10, 13 ] ] ]);
* const d = multiPoint([ [ 12, 13 ], [ 13, 14 ] ]);
* const cd_containsProperly = containsProperly(c, d); // true
*
* const e = polygon([ [ [ 0, 0 ], [ 0, 5 ], [ 5, 5 ], [ 5, 0 ], [ 0, 0 ] ] ]);
* const f = lineString([ [ 1, 4 ], [ 4, 4 ], [ 1, 1 ] ]);
* const ef_containsProperly = containsProperly(e, f); // true
*
* const g = polygon([ [ [ 10, 0 ], [ 10, 5 ], [ 15, 5 ], [ 15, 0 ], [ 10, 0 ] ] ]);
* const h = polygon([ [ [ 11, 2 ], [ 14, 4 ], [ 14, 1 ], [ 11, 2 ] ] ]);
* const gh_containsProperly = containsProperly(g, h); // true
*/
declare function containsProperly(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometry `a` lies in geometry `b` and their interiors intersect.
*
* Geometry `a` is within geometry `b` if all points of `a` are in the interior
* or at the boundary of `b` and the interiors of `a` and `b` have at least one
* point in common.
*
* Note:
* According to the definition above, a **geometry does not contain its
* boundary**, so for example, a LineString that is completely contained in
* the boundary of a Polygon is not considered to be within that Polygon.
*
* In most cases {@link coveredBy} should be used, as it has a simpler
* definition and allows for additional optimizations.
*
* `within` is the converse of {@link contains}: `within(a, b) === contains(b, a)`.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometry `a` is within geometry `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link contains} converse of `within`
* @see {@link coveredBy} more inclusive `within`
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example
* const a = point([ 2, 10 ]);
* const b = lineString([ [ 0, 13 ], [ 4, 15 ], [ 2, 10 ] ]);
* const ab_within = within(a, b); // false
*
* const c = lineString([ [ 10, 13 ], [ 14, 15 ] ]);
* const d = lineString([ [ 10, 13 ], [ 14, 15 ], [ 12, 10 ] ]);
* const cd_within = within(c, d); // true
*
* const e = point([ 3, 3 ]);
* const f = polygon([
* [ [ 0, 0 ], [ 0, 5 ], [ 5, 5 ], [ 5, 0 ], [ 0, 0 ] ],
* [ [ 2, 2 ], [ 4, 2 ], [ 4, 4 ], [ 2, 4 ], [ 2, 2 ] ],
* ]);
* const ef_within = within(e, f); // false
*
* const g = polygon([ [ [ 13, 0 ], [ 13, 2 ], [ 15, 2 ], [ 15, 0 ], [ 13, 0 ] ] ]);
* const h = polygon([
* [ [ 10, 0 ], [ 10, 5 ], [ 15, 5 ], [ 15, 0 ], [ 10, 0 ] ],
* [ [ 12, 2 ], [ 14, 2 ], [ 14, 4 ], [ 12, 4 ], [ 12, 2 ] ],
* ]);
* const gh_within = within(g, h); // true
*/
declare function within(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometry `b` lies in geometry `a`.
*
* Geometry `a` contains geometry `b` if all points of `b` are in the interior
* or at the boundary of `a`.
*
* If either geometry is empty, returns `false`.
*
* `covers` is the converse of {@link coveredBy}: `covers(a, b) === coveredBy(b, a)`.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometry `a` covers geometry `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link coveredBy} converse of `covers`
* @see {@link contains} less inclusive `covers`
* @see {@link containsProperly} less inclusive `contains`
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example differences with 'contains'
* const a = lineString([ [ 0, 13 ], [ 4, 15 ], [ 2, 10 ] ]);
* const b = point([ 2, 10 ]);
* const ab_contain = contains(a, b); // false - no interior point in common
* const ab_cover = covers(a, b); // true
*
* const c = polygon([ [ [ 10, 13 ], [ 14, 15 ], [ 15, 10 ], [ 10, 13 ] ] ]);
* const d = lineString([ [ 10, 13 ], [ 14, 15 ], [ 15, 10 ] ]);
* const cd_contain = contains(c, d); // false - no interior point in common
* const cd_cover = covers(c, d); // true
*/
declare function covers(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometry `a` lies in geometry `b`.
*
* Geometry `a` is covered by geometry `b` if all points of `a` are in the
* interior or at the boundary of `b`.
*
* If either geometry is empty, returns `false`.
*
* `coveredBy` is the converse of {@link covers}: `coveredBy(a, b) === covers(b, a)`.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometry `a` is covered by geometry `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link covers} converse of `coveredBy`
* @see {@link within} less inclusive `coveredBy`
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example differences with 'within'
* const a = point([ 2, 0 ]);
* const b = lineString([ [ 0, 3 ], [ 4, 5 ], [ 2, 0 ] ]);
* const ab_within = within(a, b); // false
* const ab_coveredBy = coveredBy(a, b); // true
*
* const g = lineString([ [ 12, 2 ], [ 14, 2 ], [ 14, 4 ] ]);
* const h = polygon([
* [ [ 10, 0 ], [ 10, 5 ], [ 15, 5 ], [ 15, 0 ], [ 10, 0 ] ],
* [ [ 12, 2 ], [ 14, 2 ], [ 14, 4 ], [ 12, 4 ], [ 12, 2 ] ],
* ]);
* const gh_within = within(g, h); // false
* const gh_coveredBy = coveredBy(g, h); // true
*/
declare function coveredBy(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometries `a` and `b` spatially cross.
*
* Geometry `a` crosses geometry `b` if both geometries have some, but not all
* interior points in common, and the dimension of their intersection must be
* lower than the maximum dimension of either `a` or `b`.
*
* Operation is valid for the following situations:
* - Point/Line and Line/Point (Point intersection),
* - Point/Area and Area/Point (Point intersection),
* - Line/Area and Area/Line (Line intersection),
* - Line/Line (Point intersection).
*
* Always returns `false` for Point/Point and Area/Area situations.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometries `a` and `b` spatially cross
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example crosses: true
* const a = lineString([ [ 0, 13 ], [ 3, 14 ], [ 5, 10 ] ]);
* const b = multiPoint([ [ 2, 16 ], [ 3, 14 ], [ 6, 14 ], [ 1, 10 ] ]);
* const ab_cross = crosses(a, b); // true
*
* const c = polygon([ [ [ 11, 13 ], [ 14, 16 ], [ 15, 12 ], [ 11, 13 ] ] ]);
* const d = multiPoint([ [ 12, 16 ], [ 13, 14 ], [ 16, 14 ], [ 11, 10 ] ]);
* const cd_cross = crosses(c, d); // true
*
* const e = polygon([ [ [ 1, 1 ], [ 1, 4 ], [ 4, 4 ], [ 4, 1 ], [ 1, 1 ] ] ]);
* const f = lineString([ [ 0, 3 ], [ 4, 5 ], [ 2, 0 ] ]);
* const ef_cross = crosses(e, f); // true
*
* const g = lineString([ [ 10, 3 ], [ 14, 5 ], [ 12, 0 ] ]);
* const h = lineString([ [ 11, 5 ], [ 15, 0 ] ]);
* const gh_cross = crosses(g, h); // true
*
* @example crosses: false
* const a = lineString([ [ 0, 13 ], [ 3, 14 ], [ 5, 10 ] ]);
* const b = point([ 3, 14 ]);
* const ab_cross = crosses(a, b); // false - all interior points in common
*
* const c = polygon([ [ [ 11, 13 ], [ 14, 16 ], [ 15, 12 ], [ 11, 13 ] ] ]);
* const d = multiPoint([ [ 13, 14 ], [ 14, 13 ] ]);
* const cd_cross = crosses(c, d); // false - all interior points in common
*
* const e = polygon([ [ [ 1, 1 ], [ 1, 4 ], [ 4, 4 ], [ 4, 1 ], [ 1, 1 ] ] ]);
* const f = lineString([ [ 1, 3 ], [ 4, 4 ], [ 2, 1 ] ]);
* const ef_cross = crosses(e, f); // false - all interior points in common
*
* const g = lineString([ [ 10, 5 ], [ 15, 0 ] ]);
* const h = lineString([ [ 10, 2 ], [ 12, 3 ], [ 13, 2 ], [ 15, 3 ] ]);
* const gh_cross = crosses(g, h); // false - intersection is line not a point
*/
declare function crosses(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if geometries `a` and `b` spatially overlap.
*
* Geometry `a` overlaps geometry `b` if both geometries have some, but not all
* points in common, they have the same dimension and the intersection of their
* interiors has the same dimension as the geometries themselves.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if geometry `a` overlaps geometry `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example overlaps: true
* const a = multiPoint([ [ 2, 6 ], [ 3, 4 ], [ 6, 4 ], [ 1, 0 ] ]);
* const b = multiPoint([ [ 0, 3 ], [ 3, 4 ], [ 4, 2 ], [ 5, 5 ] ]);
* const ab_overlap = overlaps(a, b); // true
*
* const c = lineString([ [ 10, 5 ], [ 15, 0 ] ]);
* const d = lineString([ [ 10, 2 ], [ 12, 3 ], [ 13, 2 ], [ 15, 3 ] ]);
* const cd_overlap = overlaps(c, d); // true
*
* const e = polygon([ [ [ 18, 0 ], [ 18, 7 ], [ 22, 7 ], [ 22, 0 ], [ 18, 0 ] ] ]);
* const f = polygon([ [ [ 20, 1 ], [ 20, 4 ], [ 26, 4 ], [ 26, 1 ], [ 20, 1 ] ] ]);
* const ef_overlap = overlaps(e, f); // true
*
* @example overlaps: false
* const a = multiPoint([ [ 2, 6 ], [ 3, 4 ], [ 6, 4 ], [ 1, 0 ] ]);
* const b = multiPoint([ [ 1, 0 ], [ 3, 4 ] ]);
* const ab_overlap = overlaps(a, b); // false - all points from `b` are within `a`
*
* const c = lineString([ [ 13, 5 ], [ 12, 0 ] ]);
* const d = lineString([ [ 10, 2 ], [ 12, 3 ], [ 13, 2 ], [ 15, 3 ] ]);
* const cd_overlap = overlaps(c, d); // false - intersection has lower dimension (point instead of line)
*
* const e = polygon([ [ [ 18, 0 ], [ 18, 7 ], [ 22, 7 ], [ 22, 0 ], [ 18, 0 ] ] ]);
* const f = polygon([ [ [ 22, 1 ], [ 22, 4 ], [ 26, 4 ], [ 26, 1 ], [ 22, 1 ] ] ]);
* const ef_overlap = overlaps(e, f); // false - intersection has lower dimension (line instead of polygon)
*
* const g = polygon([ [ [ 30, 0 ], [ 30, 5 ], [ 35, 5 ], [ 35, 0 ], [ 30, 0 ] ] ]);
* const h = lineString([ [ 29, 2 ], [ 36, 3 ] ]);
* const gh_overlap = overlaps(g, h); // false - different dimensions cannot overlap
*/
declare function overlaps(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Returns `true` if the only points in common between geometry `a` and `b`
* are on their boundaries.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns `true` if `a` intersect with `b`, but their interiors do not intersect
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example touches: true
* const a = lineString([ [ 0, 10 ], [ 2, 14 ], [ 5, 15 ] ]);
* const b = point([ 0, 10 ]);
* const ab_touch = touches(a, b); // true
*
* const c = lineString([ [ 10, 10 ], [ 12, 14 ], [ 15, 15 ] ]);
* const d = lineString([ [ 13, 10 ], [ 11, 12 ] ]);
* const cd_touch = touches(c, d); // true
*
* const e = lineString([ [ 20, 10 ], [ 22, 14 ], [ 25, 15 ] ]);
* const f = polygon([ [ [ 22, 10 ], [ 21, 12 ], [ 25, 13 ], [ 25, 10 ], [ 22, 10 ] ] ]);
* const ef_touch = touches(e, f); // true
*
* const g = polygon([ [ [ 2, 0 ], [ 1, 2 ], [ 5, 3 ], [ 5, 0 ], [ 2, 0 ] ] ]);
* const h = point([ 1, 2 ]);
* const gh_touch = touches(g, h); // true
*
* const i = polygon([ [ [ 12, 0 ], [ 11, 2 ], [ 15, 3 ], [ 15, 0 ], [ 12, 0 ] ] ]);
* const j = polygon([ [ [ 11, 3 ], [ 12, 5 ], [ 15, 3 ], [ 11, 3 ] ] ]);
* const ij_touch = touches(i, j); // true
*
* const k = polygon([ [ [ 22, 0 ], [ 21, 2 ], [ 25, 3 ], [ 25, 0 ], [ 22, 0 ] ] ]);
* const l = polygon([ [ [ 21, 2 ], [ 22, 5 ], [ 25, 3 ], [ 21, 2 ] ] ]);
* const kl_touch = touches(k, l); // true
*
* @example touches: false
* const a = lineString([ [ 0, 10 ], [ 2, 14 ], [ 5, 15 ] ]);
* const b = point([ 1, 12 ]);
* const ab_touch = touches(a, b); // false
*
* const c = lineString([ [ 10, 10 ], [ 12, 14 ], [ 15, 15 ] ]);
* const d = lineString([ [ 9, 13 ], [ 15, 15 ] ]);
* const cd_touch = touches(c, d); // false
*
* const e = lineString([ [ 22, 11 ], [ 22, 14 ], [ 25, 15 ] ]);
* const f = polygon([ [ [ 22, 10 ], [ 21, 12 ], [ 25, 13 ], [ 25, 10 ], [ 22, 10 ] ] ]);
* const ef_touch = touches(e, f); // false
*
* const g = polygon([ [ [ 2, 0 ], [ 1, 2 ], [ 5, 3 ], [ 5, 0 ], [ 2, 0 ] ] ]);
* const h = point([ 3, 1 ]);
* const gh_touch = touches(g, h); // false
*
* const i = polygon([ [ [ 12, 0 ], [ 11, 2 ], [ 15, 3 ], [ 15, 0 ], [ 12, 0 ] ] ]);
* const j = polygon([ [ [ 11, 3 ], [ 12, 5 ], [ 14, 2 ], [ 11, 3 ] ] ]);
* const ij_touch = touches(i, j); // false
*
* const k = polygon([ [ [ 22, 0 ], [ 21, 2 ], [ 25, 3 ], [ 25, 0 ], [ 22, 0 ] ] ]);
* const l = polygon([ [ [ 21, 2 ], [ 23, 1 ], [ 25, 3 ], [ 21, 2 ] ] ]);
* const kl_touch = touches(k, l); // false
*/
declare function touches(a: Geometry | Prepared<Geometry>, b: Geometry): boolean;
/**
* Computes the [DE-9IM]{@link https://en.wikipedia.org/wiki/DE-9IM} string for
* a pair of geometries `a` and `b`.
*
* The result is a 9-character string described by the regular expression
* `/^[F012]{9}$/`.\
* Each character represents a dimension of intersection:
* - `F` - no intersection (-1 dimension)
* - `0` - point
* - `1` - line
* - `2` - area
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @returns DE-9IM matrix string for the spacial relationship between
* geometries `a` and `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link relatePattern} returns `true` if spatial relationship between
* two geometries matches the specified pattern
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example
* const a = point([ 0, 0 ]);
* const b = lineString([ [ 0, 0 ], [ 1, 0 ] ]);
* const ab_relate = relate(a, b); // 'F0FFFF102'
* const ba_relate = relate(b, a); // 'FF10F0FF2'
*/
declare function relate(a: Geometry | Prepared<Geometry>, b: Geometry): string;
/**
* Returns `true` if the spatial relationship between geometries `a` and `b`
* matches the specified [DE-9IM]{@link https://en.wikipedia.org/wiki/DE-9IM}
* pattern.
*
* DE-9IM pattern is a 9-character string described by the regular expression
* `/^[F012T*]{9}$/`.\
* Each character represents a dimension of intersection:
* - `F` - no intersection (-1 dimension)
* - `0` - point
* - `1` - line
* - `2` - area
* - `T` - any intersection (`0`, `1` or `2`)
* - `*` - wildcard (`F`, `0`, `1` or `2`)
*
* If possible it is better to use a named relationship functions like
* {@link overlaps} or {@link covers}.
*
* Warning:
* Do not use this function with [invalid]{@link isValid} geometries.
* You will get unexpected results.
*
* @param a - First geometry
* @param b - Second geometry
* @param pattern - DE-9IM pattern, 9-character string where each character is
* one of `F`,`0`,`1`,`2`,`T`,`*`
* @returns `true` if the specified pattern matches the spatial relationship
* between geometries `a` and `b`
* @throws {GEOSError} on unsupported geometry types (curved)
*
* @see {@link relate} returns the exact DE-9IM matrix string for two geometries
* @see {@link prepare} improves performance of repeated calls against a single geometry
*
* @example
* const a = polygon([ [ [ 0, 0 ], [ 0, 7 ], [ 4, 7 ], [ 4, 0 ], [ 0, 0 ] ] ]);
* const b = polygon([ [ [ 2, 1 ], [ 2, 4 ], [ 8, 4 ], [ 8, 1 ], [ 2, 1 ] ] ]);
* const ab_relation = relate(a, b); // '212101212'
* const ab_overlaps = relatePattern(a, b, 'T*T***T**'); // true - `a` overlaps `b`, probably
* const ab_contains = relatePattern(a, b, 'T*****FF*'); // false - `a` do not contain `b`
*/
declare function relatePattern(a: Geometry | Prepared<Geometry>, b: Geometry, pattern: string): boolean;
interface STRTreeOptions {
/**
* The maximum number of child nodes that a tree node may have.\
* The minimum recommended capacity value is 4.
* @default 10
*/
nodeCapacity?: number;
}
/**
* Constructs a 2D [R-tree](https://en.wikipedia.org/wiki/R-tree) spatial index
* using Sort-Tile-Recursive (STR) packing algorithm.
*
* The index is query-only; once constructed, geometries cannot be added or
* removed from the index.
*
* The tree indexes the [bounding boxes]{@link bounds} of each geometry.
* Geometries of any type can be indexed, types can mix within one index.
* Empty geometries are ignored during indexing and will never be returned by
* queries.
*
* @template G - The type of indexed geometry
* @param geometries - The array of geometries to be indexed
* @param options - Optional options object
* @returns A new {@link STRTreeRef} instance
* @throws {GEOSError} when `options.nodeCapacity` is less than 2
*
* @example
* const geometriesToIndex = [
* point([ 0, 0 ]), point([ 0, 2 ]), point([ 0, 4 ]),
* point([ 2, 0 ]), point([ 2, 2 ]), point([ 2, 4 ]),
* point([ 4, 0 ]), point([ 4, 2 ]), point([ 4, 4 ]),
* point([ 6, 0 ]), lineString([ [ 6, 2 ], [ 6, 4 ] ]),
* ];
* const tree = strTreeIndex(geometriesToIndex);
*
* // index can now be queried by geometry bbox:
* const g1 = box([ 3, 1, 7, 3 ]); // <POLYGON ((3 1, 3 3, 7 3, 7 1, 3 1))>
* // note that not the geometry but just its bbox will be used by the query
* // any geometry type could be used to query index, including points and lines
* const queryMatches = tree.query(g1);
* // [ <POINT (4 2)>, <LINESTRING (6 2, 6 4)> ]
*
* // or used to find the nearest tree geometry:
* const g2 = point([ 1.5, 1.75 ]);
* // `nearest` uses Cartesian distance not between bboxes but actual geometries
* const nearestMatch = tree.nearest(g2);
* // <POINT (2 2)>
*/
declare function strTreeIndex<G extends Geometry>(geometries: G[], options?: STRTreeOptions): STRTreeRef<G>;
/**
* Class representing a (STR) [R-tree](https://en.wikipedia.org/wiki/R-tree)
* that exists in the Wasm memory.
*
* STRTree is a query-only R-tree spatial index structure for two-dimensional
* data that uses Sort-Tile-Recursive packing algorithm.
*
* To create new index use {@link strTreeIndex} function.
*
* @template G - The type of indexed geometry
*/
declare class STRTreeRef<G extends Geometry = Geometry> {
/**
* The original geometries that were indexed by the tree.
* This array is readonly and should not be modified.
*/
readonly geometries: G[];
/**
* Object becomes detached when manually [freed]{@link STRTreeRef#free}.
* Detached objects are no longer valid and should not be used.
*/
detached?: boolean;
/**
* Returns all geometries whose [bounding box]{@link bounds} intersects
* with the query geometry's bounding box.
*
* @param geometry - The geometry whose bounding box will be used in the
* query
* @returns An array of geometries whose bounding box intersects with the
* query geometry's bounding box.
*
* @see {@link box} creates Polygon geometry that can be used by the query
* when starting from bounds array
*
* @example
* const geometries = [
* point([ 0, 2 ]), lineString([ [ 4, 2 ], [ 8, 2 ] ]),
* point([ 0, 4 ]), point([ 4, 4 ]), point([ 8, 4 ]),
* ];
* const selector = box([ 2, 0, 6, 6 ]);
* // <POLYGON ((2 0, 2 6, 6 6, 6 0, 2 0))>
*
* const tree = strTreeIndex(geometries);
* const queryMatches = tree.query(selector);
* // [ <LINESTRING (4 2, 8 2)>, <POINT (4 4)> ]
*
* // the results can be freely processed further
* // for example, to get geometries that are fully inside `selector`:
* const inside = queryMatches.filter(g => covers(selector, g));
* // [ <POINT (4 4)> ]
*/
query(geometry: Geometry): G[];
/**
* Returns the geometry with the minimum distance to the query geometry.
*
* Cartesian distance is calculated between the actual geometries, not
* their bounding boxes.
*
* If there are multiple equidistant geometries, this function will return
* only one of them. To return all such geometries, use {@link nearestAll}.
*
* @param geometry - Geometry for which the nearest neighbor is queried
* @returns The nearest geometry or `undefined` if the tree is empty
* @throws {GEOSError} if any of the considered candidates for the nearest
* geometry is one of unsupported geometry types (curved)
*
* @example
* const geometries = [
* point([ 0, 2 ]), lineString([ [ 4, 2 ], [ 8, 2 ] ]),
* point([ 0, 4 ]), point([ 4, 4 ]), point([ 8, 4 ]),
* ];
* const target = lineString([ [ 1, 0 ], [ 1, 5 ], [ 3, 6 ] ]);
*
* const tree = strTreeIndex(geometries);
* const nearestMatch = tree.nearest(target);
* // <POINT (0 2)>
* const nearestAllMatches = tree.nearestAll(target);
* // [ <POINT (0 2)>, <POINT (0 4)> ]
*/
nearest(geometry: Geometry): G | undefined;
/**
* Returns all geometries with the minimum distance to the query geometry.
*
* Cartesian distance is calculated between the actual geometries, not
* their bounding boxes.
*
* @param geometry - Geometry for which the nearest neighbors are queried
* @returns An array of all nearest geometries with the same minimum
* distance to the query geometry, or an empty array if the tree is empty
* @throws {GEOSError} if any of the considered candidates for the nearest
* geometry is one of unsupported geometry types (curved)
*
* @example
* const geometries = [
* point([ 0, 5 ]), lineString([ [ 3, 4 ], [ 5, 5 ], [ 4, 3 ] ]),
* point([ 5, 0 ]), lineString([ [ 4, -3 ], [ 5, -5 ], [ 3, -4 ] ]),
* point([ 0, -5 ]), lineString([ [ -3, -4 ], [ -5, -5 ], [ -4, -3 ] ]),
* point([ -5, 0 ]), lineString([ [ -3, 4 ], [ -5, 5 ], [ -4, 3 ] ]),
* ];
* const tree = strTreeIndex(geometries);
*
* const g1 = point([ 0, 0 ]);
* const matches1 = tree.nearestAll(g1);
* // all geometries as they are all 5 units away from the `g1`
*
* const g2 = point([ 4.5, 1.5 ]);
* const matches2 = tree.nearestAll(g2);
* // [ <POINT (5 0)>, <LINESTRING (3 4, 5 5, 4 3)> ]
*
* const g3 = point([ 3, 3 ]);
* const matches3 = tree.nearestAll(g3);
* // [ <LINESTRING (3 4, 5 5, 4 3)> ]
*/
nearestAll(geometry: Geometry): G[];
/**
* Frees the Wasm memory allocated for the STRTree object.
*
* This method exists as a backup for those who find [`FinalizationRegistry`]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry}
* unreliable and want a way to free the memory manually.
*
* Manually freed object is marked as [detached]{@link STRTreeRef#detached}.
*/
free(): void;
}
/**
* For performance optimization.
* Increases the size of the `WebAssembly.Memory` _by_ or _to_ a specified
* number of bytes.
*
* Internally, the number of bytes will be rounded up to the closest multiple
* of 64KB - WebAssembly page size.
*
* When you know you will need a larger chunk of memory, 500MB for example,
* you can reserve it in advance. Otherwise, Wasm memory would increase
* dynamically in multiple steps, which could affect performance
* as with each step `WebAssembly.Memory` views must be recreated -
* [detachment upon growing]{@link https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/Memory/grow#detachment_upon_growing}.
*
* The initial `WebAssembly.Memory` size is 16MB and grows dynamically
* up to the 4GB limit.
*
* @param options - Object with either `by` or `to` property
* @param options.by - By how many bytes the memory will grow; incremental step
* @param options.to - To how many bytes the memory will grow; target value
* @returns The new size of the memory, in bytes
*
* @example grow memory by 512MB
* growMemory({ by: 512 * 1024 * 1024 });
*
* @example grow memory to 1GB
* growMemory({ to: 1024 * 1024 * 1024 });
*
* @example reserve all available memory (limited to 4GB for wasm32 target)
* growMemory({ to: Infinity });
*
* @example get current memory size
* growMemory({ by: 0 });
*/
declare function growMemory(options: {
by: number;
} | {
to: number;
}): number;
/**
* Returns GEOS version.
*
* @returns string with the version of GEOS and GEOS C-API
*
* @example
* const v = version(); // '3.13.1-CAPI-1.19.2'
*/
declare function version(): string;
/**
* The most convenient way to initialize `geos.js` module.
*
* The .wasm file is embedded directly into the .js file as a base64 string.
* Although convenient, this causes a certain penalty during initial initialization
* due to base64 to binary conversion and ~33% overhead of .wasm file size.
*
* Note that the returned module is just stateless, compiled WebAssembly code.
* `WebAssembly.Module` could be shared with another worker or window via `postMessage`.
*
* @returns A Promise that resolves with the `WebAssembly.Module`
*
* @see {@link initialize} initializes `geos.js` module from a fetch request
* or already compiled module
* @see {@link terminate} terminates initialized `geos.js` instance
*
* @example in any environment
* await initializeFromBase64();
*/
declare function initializeFromBase64(): Promise<WebAssembly.Module>;
/**
* Initializes `geos.js` module using `fetch` request or already compiled module.
*
* Note that the returned module is just stateless, compiled WebAssembly code.
* `WebAssembly.Module` could be shared with another worker or window via `postMessage`.
*
* @param source - Either a .wasm file fetch or already compiled module
* @returns A Promise that resolves with the `WebAssembly.Module`
*
* @see {@link terminate} terminates initialized `geos.js` instance
*
* @example browser; directly from fetch request
* await initialize(fetch('geos_js.wasm'));
*
* @example browser; from compiled module
* const module = await WebAssembly.compileStreaming(fetch('geos_js.wasm'));
* await initialize(module);
*
* @example node; from a local file
* const wasmData = await readFile('./geos_js.wasm');
* const module = await WebAssembly.compile(wasmData);
* await initialize(module);
*/
declare function initialize(source: Response | Promise<Response> | WebAssembly.Module): Promise<WebAssembly.Module>;
export { GEOSError, GeometryRef, InvalidGeoJSONError, STRTreeRef, TopologyValidationError, area, bounds, box, buffer, circularString, compoundCurve, contains, containsProperly, coveredBy, covers, crosses, curvePolygon, difference, disjoint, distance, distanceWithin, equals, equalsExact, equalsIdentical, frechetDistance, fromGeoJSON, fromWKB, fromWKT, geometryCollection, growMemory, hausdorffDistance, initialize, initializeFromBase64, intersection, intersects, isEmpty, isGeometry, isPrepared, isSimple, isValid, isValidOrThrow, length, lineString, makeValid, multiCurve, multiLineString, multiPoint, multiPolygon, multiSurface, nearestPoints, overlaps, point, polygon, prepare, relate, relatePattern, simplify, strTreeIndex, symmetricDifference, terminate, toGeoJSON, toWKB, toWKT, touches, unaryUnion, union, unprepare, version, within };
export type { BufferOptions, CircularString, CompoundCurve, CoordinateType, CurvePolygon, DensifyOptions, ExtendedGeoJSONOutputOptions, GEOSInputOptions, GeoJSONInputOptions, GeoJSONOutputOptions, Geometry, GeometryCollection, GeometryExtras, GeometryType, IsValidOptions, JSONInputOptions, JSON_CircularString, JSON_CompoundCurve, JSON_CurvePolygon, JSON_Feature, JSON_FeatureCollection, JSON_Geometry, JSON_GeometryCollection, JSON_MultiCurve, JSON_MultiSurface, LineString, LinearRing, MakeValidOptions, MultiCurve, MultiLineString, MultiPoint, MultiPolygon, MultiSurface, Point, Polygon, PrecisionGridOptions, Prepared, STRTreeOptions, SimplifyOptions, WKBInputOptions, WKBOutputOptions, WKTInputOptions, WKTOutputOptions };