geos.js
Version:
an easy-to-use JavaScript wrapper over WebAssembly build of GEOS
1,257 lines (1,219 loc) • 103 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, GeometryCollection as GeometryCollection$1, Geometry as Geometry$1, Position, 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(): never;
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>;
}
/**
* 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(): Feature<GeometryCollection$1, P>;
clone(): GeometryCollection<P>;
}
interface CircularString<P = unknown> extends GeometryRef<P> {
readonly type: 'CircularString';
toJSON(): never;
clone(): CircularString<P>;
}
interface CompoundCurve<P = unknown> extends GeometryRef<P> {
readonly type: 'CompoundCurve';
toJSON(): never;
clone(): CompoundCurve<P>;
}
interface CurvePolygon<P = unknown> extends GeometryRef<P> {
readonly type: 'CurvePolygon';
toJSON(): never;
clone(): CurvePolygon<P>;
}
interface MultiCurve<P = unknown> extends GeometryRef<P> {
readonly type: 'MultiCurve';
toJSON(): never;
clone(): MultiCurve<P>;
}
interface MultiSurface<P = unknown> extends GeometryRef<P> {
readonly type: 'MultiSurface';
toJSON(): never;
clone(): MultiSurface<P>;
}
type GeometryType = 'Point' | 'LineString' | 'LinearRing' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'CircularString' | 'CompoundCurve' | 'CurvePolygon' | 'MultiCurve' | 'MultiSurface';
/**
* 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()`.
*
* @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(): Feature<Geometry$1, 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 GeometryOptions<P> {
/**
* Optional identifier to be assigned to the geometry instance.
*/
id?: number | string;
/**
* Optional data to be assigned to the geometry instance.
*/
properties?: P;
}
/**
* Creates a {@link Point} geometry from a position.
*
* @param pt - Point coordinates
* @param options - Optional geometry options
* @returns A new point Geometry object
*
* @example
* const a = point([ 0, 0 ]);
* const b = point([ 2, 0 ], { properties: { name: 'B' } });
* const wkt = toWKT(a); // 'POINT (0 0)'
*/
declare function point<P>(pt: Position, options?: GeometryOptions<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 Geometry object
* @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' } });
* const wkt = toWKT(a); // 'LINESTRING (0 0, 2 1, 0 2)'
*/
declare function lineString<P>(pts: Position[], options?: GeometryOptions<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 Geometry object
* @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, 6 ], [ 6, 2 ], [ 2, 2 ] ],
* ], { properties: { name: 'B' } });
* const wkt = toWKT(a); // 'POLYGON ((4 3, 5 4, 5 3, 4 3))'
*/
declare function polygon<P>(ppts: Position[][], options?: GeometryOptions<P>): Polygon<P>;
/**
* Creates a {@link MultiPoint} geometry from an array of positions.
*
* @param pts - MultiPoint coordinates
* @param options - Optional geometry options
* @returns A new Geometry object
*
* @example
* const a = multiPoint([ [ 0, 0 ], [ 2, 0 ], [ 4, 0 ] ]);
* const b = multiPoint([ [ 1, 0 ], [ 3, 0 ] ], { properties: { name: 'B' } });
* const wkt = toWKT(a); // 'MULTIPOINT ((0 0), (2 0), (4 0))'
*/
declare function multiPoint<P>(pts: Position[], options?: GeometryOptions<P>): MultiPoint<P>;
/**
* Creates a {@link MultiLineString} geometry from an array of line strings coordinates.
*
* Each line string must contain at least 2 positions.
* Empty line strings with 0 positions are allowed.
*
* @param ppts - MultiLineString coordinates
* @param options - Optional geometry options
* @returns A new Geometry object
* @throws {InvalidGeoJSONError} on line with 1 position
*
* @example
* 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' } });
* const wkt = toWKT(a); // 'MULTILINESTRING ((-10 3, 5 4), (-10 7, 5 6))'
*/
declare function multiLineString<P>(ppts: Position[][], options?: GeometryOptions<P>): MultiLineString<P>;
/**
* Creates a {@link MultiPolygon} geometry from an array of polygon coordinates.
*
* 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 pppts - MultiPolygon coordinates
* @param options - Optional geometry options
* @returns A new Geometry object
* @throws {InvalidGeoJSONError} if any ring is invalid (not closed or with 1 or 2 positions)
*
* @example
* 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' } });
* const wkt = toWKT(a); // 'MULTIPOLYGON (((1 0, 0 1, 1 1, 1 0)), ((1 1, 1 2, 2 1, 1 1)))'
*/
declare function multiPolygon<P>(pppts: Position[][][], options?: GeometryOptions<P>): MultiPolygon<P>;
/**
* Creates a {@link GeometryCollection} geometry from an array of geometries.
*
* The collection consumes the input geometries - after creating
* the collection, the input geometries become [detached]{@link GeometryRef#detached},
* are no longer valid and should **not** be used.
*
* @param geometries - Array of geometry objects to be included in the collection
* @param options - Optional geometry options
* @returns A new GeometryCollection containing all input geometries
*
* @example
* const a = polygon([ [ [ 4, 1 ], [ 4, 3 ], [ 8, 2 ], [ 4, 1 ] ] ]);
* const b = lineString([ [ 0, 2 ], [ 6, 2 ] ]);
* const c = geometryCollection([ a, b ]);
* const wkt = toWKT(c); // 'GEOMETRYCOLLECTION (POLYGON ((4 1, 4 3, 8 2, 4 1)), LINESTRING (0 2, 6 2))'
*/
declare function geometryCollection<P>(geometries: Geometry[], options?: GeometryOptions<P>): GeometryCollection<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 object
* @throws {GEOSError} when box is degenerated: width or height is `0`
*
* @see {@link bounds} calculates bounding box of an existing geometry
*
* @example
* const b1 = box([ 0, 0, 4, 4 ]); // <POLYGON ((0 0, 0 4, 4 4, 4 0, 0 0))>
* const b2 = box([ 5, 0, 8, 1 ]); // <POLYGON ((5 0, 5 1, 8 1, 8 0, 5 0))>
*/
declare function box<P>(bbox: number[], options?: GeometryOptions<P>): Polygon<P>;
declare class InvalidGeoJSONError extends GEOSError {
}
/**
* 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.
*
* GeoJSON `Feature` properties are saved in the [`props`]{@link GeometryRef#props}
* field of the created geometry object.
*
* Loading multiple geometries from a single `FeatureCollection` is faster
* than loading each geometry individually because it processes the data in bulk.
*
* @template P - The type of geometry/feature properties
* @param geojson - GeoJSON `Geometry`, `Feature` or `FeatureCollection`
* @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
*
* @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' }
*/
declare function fromGeoJSON<P>(geojson: Geometry$1 | Feature<Geometry$1, P>): Geometry<P>;
declare function fromGeoJSON<P>(geojson: FeatureCollection<Geometry$1, P>): Geometry<P>[];
/**
* Converts the geometry 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.
*
* Converting multiple geometries into a single `FeatureCollection` is faster
* than converting each geometry into `Feature` individually because it
* processes the data in bulk.
*
* @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
* @returns GeoJSON `Feature` or GeoJSON `FeatureCollection` object
* @throws {GEOSError} when called with an unsupported geometry type (not GeoJSON)
*
* @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: [ {...}, {...} ] }
*/
declare function toGeoJSON<P>(geometryies: Geometry<P>): Feature<Geometry$1, P>;
declare function toGeoJSON<P>(geometryies: Geometry<P>[]): FeatureCollection<Geometry$1, P>;
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 ], [ 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.0, 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 diff