Class SpatialDb

Source
Expand description

SpatialDb class provides methods to interact with a DuckDB database for spatial data operations.

It allows loading OSM data, CSV, JSON, custom layers, and grid layers, as well as performing spatial joins and raw queries. It also provides methods to retrieve layer data and bounding boxes.

Constructors§

§

new SpatialDb(): SpatialDb

Properties§

Source§

public tables: Table[] = []

Methods§

Source§

buildHeatmap(params: BuildHeatmapParams): Promise<Table>

Builds a heatmap from spatial data by creating a grid and aggregating values. The heatmap is generated by creating a grid over the bounding box and aggregating values from the source table into each grid cell.

throws

Error if the database or connection is not initialized.

Source§

getBoundingBoxFromLayer(layerName: string): Promise<BoundingBox>

Retrieves the bounding box of a layer by its table name.

throws

Error if the database or connection is not initialized.

throws

Error if the layer table is not found.

throws

Error if the layer table does not have a geometry column.

Source§

getLayer(
    layerTableName: string,
): Promise<FeatureCollection<Geometry, GeoJsonProperties>>

Retrieves the GeoJSON representation of a layer by its table name. The returned FeatureCollection will include a bbox property with the layer's bounding box.

throws

Error if the database or connection is not initialized.

throws

Error if the layer table is not found or is not a Layer table.

Source§

getLayerTables(): (LayerTable | CustomLayerTable)[]

Retrieves all layer tables (LayerTable and CustomLayerTable) from the loaded tables.

Source§

getOsmBoundingBox(): [number, number, number, number] | null

Retrieves the bounding box of the OSM data loaded from the Overpass API.

Source§

init(): Promise<void>

Initializes the SpatialDb instance by loading the DuckDB database and setting up use cases.

Source§

loadCsv(params: Params): Promise<CsvTable>

Loads a CSV file into the database and returns the created CsvTable.

throws

Error if the database or connection is not initialized.

Source§

loadCustomLayer(params: Params): Promise<CustomLayerTable>

Loads a custom layer from a GeoJSON file and returns the created CustomLayerTable. If OSM bounding box is available, it will be automatically applied to crop the layer.

throws

Error if the database or connection is not initialized.

Source§

loadGridLayer(params: LoadGridLayerParams): Promise<GridLayerTable>

Loads a grid layer and returns the created GridLayerTable. If no bounding box is provided in params, the OSM bounding box will be used if available.

throws

Error if the database or connection is not initialized.

Source§

loadJson(params: Params): Promise<JsonTable>

Loads a JSON file into the database and returns the created JsonTable.

throws

Error if the database or connection is not initialized.

Source§

loadLayer(params: Params): Promise<LayerTable>

Loads a layer from an OSM input table and returns the created LayerTable.

throws

Error if the database or connection is not initialized.

throws

Error if the OSM input table is not found or is not of the correct type.

Source§

loadOsmFromOverpassApi(params: Params): Promise<void>

Loads OSM data from the Overpass API and optionally loads layers based on the provided parameters. When autoLoadLayers is enabled, this method will automatically extract and process specific layers (e.g., buildings, roads, surface) from the OSM data, and optionally polygonize the surface layer.

throws

Error if the database or connection is not initialized.

Source§

rawQuery<T = RawQueryOutput>(params: RawQueryParams): Promise<Table | T>

Executes a raw SQL query and returns the result.

throws

Error if the database or connection is not initialized.

Source§

spatialJoin(params: SpatialJoinParams): Promise<Table>

Performs a spatial join between two tables and returns the resulting table. The method can either create a new table or update an existing one based on the parameters.

throws

Error if the database or connection is not initialized.