UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

90 lines (89 loc) 5.21 kB
import { Feature, Polygon, MultiPolygon, BBox } from "../types/index.js"; import { ProjectClientInterface } from "../project/ProjectClientBase.js"; /** Supported clip operations */ export type ClipOperations = "intersection" | "difference"; /** Parameters for clip operation using polygon features */ export interface FeatureClipOperation { clipFeatures: Feature<Polygon | MultiPolygon>[]; operation: ClipOperations; } export interface DatasourceOptions { /** Fetches features overlapping with bounding box */ bbox?: BBox; /** Filter features by property having one or more specific values */ propertyFilter?: { property: string; values: (string | number)[]; }; /** Provide if you have subdivided dataset and want to rebuild (union) subdivided polygons based on having same value for this property name */ unionProperty?: string; } /** Parameters for clip operation using a datasource */ export interface DatasourceClipOperation { datasourceId: string; operation: ClipOperations; options?: DatasourceOptions; } /** Optional parameters for polygon clip preprocessor */ export interface ClipOptions { /** Ensures result is a polygon. If clip results in multipolygon, returns the largest component */ ensurePolygon?: boolean; } /** * Returns true if feature is valid and meets requirements set by options. * @param feature - feature to validate * @param options - validation options * @param options.minSize - minimum size in square kilometers that polygon can be. Throws if smaller. * @param options.enforceMinSize - Whether or not minSize should be enforced and throw if smaller * @param options.maxSize - maxSize in square kilometers that polygon can be. Throws if larger. * @param options.enforceMaxSize - Whether or not maxSize should be enforced and throw if larger * @throws if polygon is invalid with reason * @returns true if valid */ export declare function ensureValidPolygon(feature: Feature, options?: { allowSelfCrossing?: boolean; minSize?: number; enforceMinSize?: boolean; maxSize?: number; enforceMaxSize?: boolean; }): boolean; /** * Returns a function that applies clip operations to a feature using other polygon features. * @param operations - array of DatasourceClipOperations * @param options - clip options * @param options.ensurePolygon - if true always returns single polygon. If operations result in multiple polygons it returns the largest (defaults to true) * @throws if a datasource fetch returns no features or if nothing remains of feature after clip operations * @returns clipped polygon */ export declare const genClipToPolygonFeatures: (clipOperations: FeatureClipOperation[], options?: ClipOptions) => (feature: Feature) => Promise<Feature>; /** * Takes a Polygon feature and returns the portion remaining after performing clipOperations against one or more Polygon features * @param feature - feature to clip * @param clipOperations - array of DatasourceClipOperations * @param options - clip options * @param options.ensurePolygon - if true always returns single polygon. If operations result in multiple polygons it returns the largest (defaults to true) * @throws if a datasource fetch returns no features or if nothing remains of feature after clip operations * @returns clipped polygon */ export declare function clipToPolygonFeatures(feature: Feature, clipOperations: FeatureClipOperation[], options?: ClipOptions): Promise<Feature<Polygon | MultiPolygon>>; /** * Returns a function that Takes a Polygon feature and returns the portion remaining after performing clipOperations against one or more datasources * @param project - project client to use for accessing datasources * @param clipOperations - array of DatasourceClipOperations * @param options - clip options * @param options.ensurePolygon - if true always returns single polygon. If operations result in multiple polygons it returns the largest (defaults to true) * @throws if a datasource fetch returns no features or if nothing remains of feature after clip operations * @returns clipped polygon */ export declare const genClipToPolygonDatasources: <P extends ProjectClientInterface>(project: P, clipOperations: DatasourceClipOperation[], options?: ClipOptions) => (feature: Feature<Polygon | MultiPolygon>) => Promise<Feature>; /** * Takes a Polygon feature and returns the portion remaining after performing clipOperations against one or more datasources * @param project - project client to use for accessing datasources * @param feature - feature to clip * @param clipOperations - array of DatasourceClipOperations * @param options - clip options * @param options.ensurePolygon - if true always returns single polygon. If operations result in multiple polygons it returns the largest (defaults to true) * @throws if a datasource fetch returns no features or if nothing remains of feature after clip operations * @returns clipped polygon */ export declare function clipToPolygonDatasources<P extends ProjectClientInterface>(project: P, feature: Feature, clipOperations: DatasourceClipOperation[], options?: ClipOptions): Promise<Feature<Polygon | MultiPolygon>>;