UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

79 lines 3.67 kB
import { isExternalVectorDatasource, isInternalVectorDatasource, VectorDataSource, } from "../datasources/index.js"; import { loadFgb } from "./flatgeobuf.js"; import { getFeaturesForSketchBBoxes } from "./getFeaturesForSketchBBoxes.js"; /** * Returns features for a variety of vector datasources and formats, with additional filter options */ /** * Fetches and returns features for a given datasource supporting a variety of formats/clients * @param datasource the datasource to fetch features from * @param url the url of the datasource * @param options.bbox fetch features overlapping with bounding box * @param options.propertyFilter filter features by property having one or more specific values * @param options.unionProperty provide if you have subdivided dataset and want to rebuild (union) subdivided polygons based on having same value for this property name * @param options.sketch fetch features overlapping with sketch bounding box, can be more precise than passing single bounding box * @returns feature array */ export async function getDatasourceFeatures(datasource, /** url of datasource */ url, options = {}) { const propertyFilter = datasource.propertyFilter || options.propertyFilter; const bboxFilter = datasource.bboxFilter || options.bbox; let features = []; if (isInternalVectorDatasource(datasource)) { if (options.sketch) { features = await getFeaturesForSketchBBoxes(options.sketch, url); } else { features = await loadFgb(url, bboxFilter); } } else if (isExternalVectorDatasource(datasource) && datasource.formats && datasource.formats.includes("subdivided")) { // prefer subdivided if external if (!bboxFilter) { throw new Error(`bbox option expected for ExternalVectorDatasource ${datasource.datasourceId}`); } const vectorDs = new VectorDataSource(url); if (options.unionProperty) { const fc = await vectorDs.fetchUnion(bboxFilter, options.unionProperty); features = fc.features; } else { features = (await vectorDs.fetch(bboxFilter)); } } else if (isExternalVectorDatasource(datasource) && datasource.formats && datasource.formats.includes("fgb")) { // fallback to flatgeobuf features = await loadFgb(url, bboxFilter); } // filter by property value if (propertyFilter) { features = features.filter((curFeat) => { if (!curFeat.properties) return false; return propertyFilter?.values.includes(curFeat.properties[propertyFilter.property]); }); } return features; } /** * Fetches and returns features for a given datasource supporting a variety of formats/clients * @param datasource the datasource to fetch features from * @param url the url of the datasource * @param options.bbox fetch features overlapping with bounding box * @param options.propertyFilter filter features by property having one or more specific values * @param options.unionProperty provide if you have subdivided dataset and want to rebuild (union) subdivided polygons based on having same value for this property name * @param options.sketch fetch features overlapping with sketch bounding box, can be more precise than passing single bounding box * @returns feature array * @deprecated use getDatasourceFeatures instead */ export async function getFeatures(datasource, /** url of datasource */ url, options = {}) { return getDatasourceFeatures(datasource, url, options); } //# sourceMappingURL=getDatasourceFeatures.js.map