UNPKG

@terrestris/ol-util

Version:

A set of helper classes for working with openLayers

170 lines (169 loc) 9.48 kB
import { Extent as OlExtent } from 'ol/extent'; import OlFeature from 'ol/Feature'; import OlGeometry from 'ol/geom/Geometry'; import OlGeomLineString from 'ol/geom/LineString'; import OlGeomMultiLineString from 'ol/geom/MultiLineString'; import OlGeomMultiPoint from 'ol/geom/MultiPoint'; import OlGeomMultiPolygon from 'ol/geom/MultiPolygon'; import OlGeomPolygon from 'ol/geom/Polygon'; import { ProjectionLike } from 'ol/proj'; /** * Helper class for the geospatial analysis. Makes use of * [Turf.js](http://turfjs.org/). * * @class GeometryUtil */ declare class GeometryUtil { /** * The prefix used to detect multi geometries. * @ignore */ static MULTI_GEOM_PREFIX: string; /** * Splits an OlFeature with/or ol.geom.Polygon by an OlFeature with/or ol.geom.LineString * into an array of instances of OlFeature with/or ol.geom.Polygon. * If the target polygon (first param) is of type ol.Feature it will return an * array with ol.Feature. If the target polygon (first param) is of type * ol.geom.Geometry it will return an array with ol.geom.Geometry. * * @param {OlFeature<OlGeomPolygon> | OlGeomPolygon} polygon The polygon geometry to split. * @param {OlFeature<OlGeomLineString> | OlGeomLineString} line The line geometry to split the polygon * geometry with. * @param {import("ol/proj").ProjectionLike} projection The EPSG code of the input features. * Default is to EPSG:3857. * @returns {OlFeature[] | OlGeomPolygon[]} An array of instances of OlFeature * with/or ol.geom.Polygon */ static splitByLine(polygon: OlFeature<OlGeomPolygon> | OlGeomPolygon, line: OlFeature<OlGeomLineString>, projection?: ProjectionLike): OlGeomPolygon[] | OlFeature<OlGeomPolygon>[]; /** * Splits an ol.geom.Polygon by an ol.geom.LineString * into an array of instances of ol.geom.Polygon. * * @param {OlGeomPolygon} polygon The polygon geometry to split. * @param {OlGeomLineString} line The line geometry to split the polygon * geometry with. * @param {ProjectionLike} projection The EPSG code of the input features. * Default is to EPSG:3857. * @returns {OlGeomPolygon[]} An array of instances of ol.geom.Polygon */ static splitGeometryByLine(polygon: OlGeomPolygon, line: OlGeomLineString, projection?: ProjectionLike): OlGeomPolygon[]; /** * Adds a buffer to a given geometry. * * If the target is of type ol.Feature it will return an ol.Feature. * If the target is of type ol.geom.Geometry it will return ol.geom.Geometry. * * @param {OlGeometry | OlFeature} geometryOrFeature The geometry. * @param {number} radius The buffer to add in meters. * @param {string} projection The projection of the input geometry as EPSG code. * Default is to EPSG:3857. * * @returns {OlGeometry | OlFeature} The geometry or feature with the added buffer. */ static addBuffer(geometryOrFeature: OlFeature<OlGeometry> | OlGeometry, radius?: number, projection?: ProjectionLike): OlGeometry | OlFeature<OlGeometry, { [x: string]: any; }> | undefined; /** * Adds a buffer to a given geometry. * * @param {OlGeometry} geometry The geometry. * @param {number} radius The buffer to add in meters. * @param {string} projection The projection of the input geometry as EPSG code. * Default is to EPSG:3857. * * @returns {OlGeometry} The geometry with the added buffer. */ static addGeometryBuffer(geometry: OlGeometry, radius?: number, projection?: ProjectionLike): OlGeometry | undefined; /** * Merges multiple geometries into one MultiGeometry. * * @param {(OlGeomMultiPoint|OlGeomPoint)[]|(OlGeomMultiPolygon|OlGeomPolygon)[]| * (OlGeomMultiLineString|OlGeomLineString)[]} geometries An array of ol.geom.geometries; * @returns {OlGeomMultiPoint|OlGeomMultiPolygon|OlGeomMultiLineString} A Multigeometry. */ static mergeGeometries<Geom extends OlGeometry>(geometries: Geom[]): OlGeomMultiPolygon | OlGeomMultiLineString | OlGeomMultiPoint; /** * Splits an array of geometries (and multi geometries) or a single MultiGeom * into an array of single geometries. * * @param {} geometry An (array of) ol.geom.geometries; * @returns {(OlGeomPoint|OlGeomLineString|OlGeomPolygon)[]} An array of geometries. */ static separateGeometries(geometry: OlGeometry | OlGeometry[]): OlGeometry[]; /** * Takes two or more polygons and returns a combined (Multi-)polygon. * * @param {OlFeature<OlGeomPolygon>[] | OlFeature<OlGeomPolygon | OlGeomMultiPolygon>>[]} inputPolygonalObjects An * array of ol.Feature or ol.geom.Geometry instances of type (Multi)-Polygon. * @param {ProjectionLike} projection The projection of the input polygons as EPSG code. * Default is to EPSG:3857. * @returns {OlGeomMultiPolygon|OlGeomPolygon|OlFeature<OlGeomMultiPolygon|OlGeomPolygon>} A Feature or Geometry with * the combined area of the (Multi-)polygons. */ static union(inputPolygonalObjects: OlGeomPolygon[] | OlFeature<OlGeomPolygon | OlGeomMultiPolygon>[], projection?: ProjectionLike): OlGeomMultiPolygon | OlGeomPolygon | OlFeature<OlGeomMultiPolygon | OlGeomPolygon>; /** * Takes two or more polygons and returns a combined (Multi-)polygon. * * @param {OlGeomPolygon[]} polygons An array of ol.geom.Geometry instances of type (Multi-)polygon. * @param {string} projection The projection of the input polygons as EPSG code. * Default is to EPSG:3857. * @returns {OlGeomMultiPolygon|OlGeomPolygon} A FGeometry with the combined area of the (Multi-)polygons. */ static unionGeometries(polygons: OlGeomPolygon[] | OlGeomMultiPolygon[], projection?: ProjectionLike): OlGeomMultiPolygon | OlGeomPolygon; /** * Finds the difference between two polygons by clipping the second polygon from the first. * * If both polygons are of type ol.Feature it will return an ol.Feature. * Else it will return an ol.geom.Geometry. * * @param {OlGeomPolygon|OlGeomMultiPolygon|OlFeature<OlGeomPolygon|OlGeomMultiPolygon>} polygon1 * @param {OlGeomPolygon|OlGeomMultiPolygon|OlFeature<OlGeomPolygon|OlGeomMultiPolygon>} polygon2 * @param {string} projection The projection of the input polygons as EPSG code. * Default is to EPSG:3857. * * @returns {OlGeomPolygon|OlGeomMultiPolygon|OlFeature<OlGeomPolygon|OlGeomMultiPolygon>} A Feature or geometry * with the area of polygon1 excluding the area of polygon2. */ static difference(polygon1: OlFeature<OlGeomPolygon> | OlGeomPolygon, polygon2: OlFeature<OlGeomPolygon> | OlGeomPolygon, projection?: ProjectionLike): OlGeomMultiPolygon | OlGeomPolygon | OlFeature<OlGeomMultiPolygon | OlGeomPolygon>; /** * Finds the difference between two polygons by clipping the second polygon from the first. * * @param {OlGeomPolygon|OlGeomMultiPolygon} polygon1 An ol.geom.Geometry * @param {OlGeomPolygon|OlGeomMultiPolygon} polygon2 An ol.geom.Geometry * @param {string} projection The projection of the input polygons as EPSG code. * Default is to EPSG:3857. * * @returns {OlGeomPolygon|OlGeomMultiPolygon} A with the area * of polygon1 excluding the area of polygon2. */ static geometryDifference(polygon1: OlGeomPolygon, polygon2: OlGeomPolygon, projection?: ProjectionLike): OlGeomMultiPolygon | OlGeomPolygon; /** * Takes two polygons and finds their intersection. * * If both polygons are of type ol.Feature it will return an ol.Feature. * Else it will return an ol.geom.Geometry. * * @param {OlGeomPolygon|OlGeomMultiPolygon|OlFeature<OlGeomPolygon|OlGeomMultiPolygon>} polygon1 * @param {OlGeomPolygon|OlGeomMultiPolygon|OlFeature<OlGeomPolygon|OlGeomMultiPolygon>} polygon2 * @param {string} projection The projection of the input polygons as EPSG code. * Default is to EPSG:3857. * * @returns {OlGeomPolygon|OlGeomMultiPolygon|OlFeature<OlGeomPolygon|OlGeomMultiPolygon>|null} A Feature or Geometry * with the shared area of the two polygons or null if the polygons don't intersect. */ static intersection(polygon1: OlFeature<OlGeomPolygon | OlGeomMultiPolygon> | OlGeomPolygon, polygon2: OlFeature<OlGeomPolygon | OlGeomMultiPolygon> | OlGeomPolygon, projection?: ProjectionLike): OlGeomMultiPolygon | OlGeomPolygon | OlFeature<OlGeomPolygon | OlGeomMultiPolygon> | undefined; /** * Takes two polygons and finds their intersection. * * @param {OlGeomPolygon|OlGeomMultiPolygon} polygon1 An ol.geom.Geometry * @param {OlGeomPolygon|OlGeomMultiPolygon} polygon2 An ol.geom.Geometry * @param {string} projection The projection of the input polygons as EPSG code. * Default is to EPSG:3857. * * @returns {OlGeomPolygon|OlGeomMultiPolygon|null} A Geometry with the * shared area of the two polygons or null if the polygons don't intersect. */ static geometryIntersection(polygon1: OlGeomPolygon | OlGeomMultiPolygon, polygon2: OlGeomPolygon | OlGeomMultiPolygon, projection?: ProjectionLike): OlGeomMultiPolygon | OlGeomPolygon | undefined; static getPolygonFromExtent(extent?: OlExtent | null): OlGeomPolygon | undefined; } export default GeometryUtil;