validateGeometry
Checks that input is a well-formed GeoJSON geometry, or a feature holding
one, and returns the geometry itself (the same object, not a copy).
This is a function exported by @mapcairn/core, checked against version 0.2.0.
Signature
import { validateGeometry } from "@mapcairn/core";
function validateGeometry(input: unknown, options?: ValidateOptions): Geometry;
Description
It accepts empty geometries (a Point with [] for coordinates, a
GeometryCollection with no members) because they are legal GeoJSON; the
operations that cannot work on nothing refuse them with an empty error.
It refuses a position that is not two or three finite numbers, a line with
fewer than two positions, a ring that is open or shorter than four
positions, positions of different sizes inside one shape, and a collection
nested more than MAX_COLLECTION_DEPTH deep. By default it also
refuses a longitude or latitude outside the globe, which is how a shape
that runs past the antimeridian shows up: GeoJSON wants such a shape split
at 180 degrees.
Parameters
input(unknown)options?(ValidateOptions)
Returns
Geometry
Throws
GeometryErrorof kindinvalidfor a malformed shape,emptyfor a feature with no geometry,unsupportedfor a feature collection.