UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

131 lines (130 loc) • 7.52 kB
import { Feature, FeatureCollection, Point, Polygon, MultiPolygon, LineString, Geometry } from "../types/geojson.js"; import { Sketch, SketchCollection, SketchGeometryTypes, NullSketch, NullSketchCollection, SketchProperties, UserAttribute } from "../types/sketch.js"; import { ReportContextValue } from "../context/index.js"; /** * UserAttributes are those filled in via the attributes form specified as * part of a SketchClass. This getter function is easier to use than searching * the Sketch.properties.userAttributes array, supports default values, and is * easier to use with typescript. */ export declare function getUserAttribute<T>(sketchOrProps: Sketch | SketchCollection | SketchProperties, exportid: string): T | undefined; export declare function getUserAttribute<T>(sketchOrProps: Sketch | SketchCollection | SketchProperties, exportid: string, defaultValue: T): T; export declare function getJsonUserAttribute<T>(sketchOrProps: Sketch | SketchProperties, exportid: string, defaultValue: T): T; /** * Converts array of sketches to an array of their SketchProperties */ export declare function toSketchPropertiesArray(sketchArray: Sketch[] | NullSketch[]): SketchProperties[]; /** * Returns SketchProperties for each child sketch in a SketchCollection */ export declare function toChildProperties(sketchCollection: SketchCollection): SketchProperties[]; /** * Converts a Sketch or SketchCollection to a Sketch array, maintaining geometry type * Useful for putting in a consistent form that can be iterated over * @param input sketch or sketch collection * @returns array of sketches, if input is a sketch collection then it is the child sketches */ export declare function toSketchArray<G>(input: Sketch<G> | SketchCollection<G>): Sketch<G>[]; /** Helper to convert a NullSketch or NullSketchCollection to a NullSketch array */ export declare function toNullSketchArray(input: NullSketch | NullSketchCollection): NullSketch[]; /** * Returns sketch or sketch collection with null geometry */ export declare function toNullSketch(sketch: Sketch | SketchCollection, useNull?: boolean): NullSketch | NullSketchCollection; /** * Checks if object is a Sketch. Any code inside a block guarded by a conditional call to this function will have type narrowed to Sketch */ export declare const isSketch: (feature: any) => feature is Sketch; /** * Checks if sketch is a Polygon */ export declare const isPolygonSketch: (sketch: any) => sketch is Sketch<Polygon>; /** * Checks if sketch is a MultiPolygon. Any code inside a block guarded by a conditional call to this function will have type narrowed to Sketch */ export declare const isMultiPolygonSketch: (sketch: any) => sketch is Sketch<MultiPolygon>; /** * Check if object is a SketchCollection. Any code inside a block guarded by a conditional call to this function will have type narrowed to SketchCollection */ export declare const isSketchCollection: (collection: any) => collection is SketchCollection; /** * Checks if object is a NullSketch. Any code inside a block guarded by a conditional call to this function will have type narrowed to NullSketch */ export declare const isNullSketch: (feature: any) => feature is NullSketch; /** * Check if object is a NullSketchCollection. Any code inside a block guarded by a conditional call to this function will have type narrowed to NullSketchCollection */ export declare const isNullSketchCollection: (collection: any) => collection is NullSketchCollection; export declare const isPolygonSketchCollection: (collection: any) => collection is SketchCollection<Polygon>; export declare const isMultiPolygonSketchCollection: (collection: any) => collection is SketchCollection<MultiPolygon>; export declare const isPolygonAllSketchCollection: (collection: any) => collection is SketchCollection<Polygon | MultiPolygon>; export declare const isLineStringSketchCollection: (collection: any) => collection is SketchCollection<LineString>; export declare const isPointSketchCollection: (collection: any) => collection is SketchCollection<Point>; export declare const genSampleUserAttributes: () => UserAttribute[]; /** * Returns a Sketch with given features geometry and properties. Reasonable defaults are given for properties not provided * Default geometry is a square from 0,0 to 1,1 */ export declare const genSketch: <G extends Geometry = SketchGeometryTypes>(options?: { feature?: Feature<G>; name?: string; id?: string; userAttributes?: UserAttribute[]; sketchClassId?: string; createdAt?: string; updatedAt?: string; }) => Sketch<G>; /** * Given array of sketches, return a sketch collection with given properties. * Generates reasonable default values for any properties not passed in * The geometry type of the returned collection will match the one passed in * Properties of sketches are retained */ export declare const genSketchCollection: <G extends Geometry = SketchGeometryTypes>(sketches: Sketch<G>[], options?: { name?: string; id?: string; userAttributes?: UserAttribute[]; sketchClassId?: string; createdAt?: string; updatedAt?: string; }) => SketchCollection<G>; /** * Returns a Sketch with given geometry and Geometry type, Properties are reasonable random */ export declare const genSampleSketch: <G extends Geometry = Polygon | MultiPolygon | LineString>(geometry: G, name?: string) => Sketch<G>; /** * Returns a Sketch with given geometry and Geometry type, Properties are reasonable random */ export declare const genSampleNullSketch: (name?: string) => NullSketch; /** * Given feature collection, return a sketch collection with reasonable random props. * The geometry type of the returned collection will match the one passed in * @param geometry */ export declare const genSampleSketchCollection: <G extends Geometry = Polygon>(fc: FeatureCollection<G>, name?: string) => SketchCollection<G>; /** * Given feature collection, return a sketch collection with reasonable random props. * The geometry type of the returned collection will match the one passed in * @param geometry */ export declare const genSampleSketchCollectionFromSketches: <G extends Geometry = Polygon | LineString>(sketches: Sketch<G>[], name?: string) => SketchCollection<G>; /** * Given feature collection, return a sketch collection with reasonable random props. * The geometry type of the returned collection will match the one passed in * @param geometry */ export declare const genSampleNullSketchCollection: (sketches: NullSketch[], name?: string) => NullSketchCollection; export declare const genSampleSketchContext: () => ReportContextValue; /** * Given sketch or sketch collection, returns just the individual sketch features inside. * @param sketch */ export declare function getSketchFeatures(sketch: Sketch | SketchCollection | NullSketchCollection | NullSketch): (NullSketch | Sketch<SketchGeometryTypes>)[]; /** * Converts Feature to Sketch with reasonable defaults given for sketch properties if not provided */ export declare const featureToSketch: <G extends SketchGeometryTypes>(feat: Feature<G>, name?: string, sketchProperties?: Partial<SketchProperties>) => Sketch<G>; /** * Converts FeatureCollection to SketchCollection with reasonable defaults given for sketch properties if not provided */ export declare const featureToSketchCollection: <G extends SketchGeometryTypes>(fc: FeatureCollection<G>, name?: string, sketchProperties?: Partial<SketchProperties>) => SketchCollection<G>;