@urban-toolkit/autk-db 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +14 -0
  2. package/dist/autk-db.js +6356 -0
  3. package/dist/autk-db.js.map +1 -0
  4. package/dist/basedecoder-DaTXO39b.js +62 -0
  5. package/dist/basedecoder-DaTXO39b.js.map +1 -0
  6. package/dist/deflate-DT_oTgqy.js +12 -0
  7. package/dist/deflate-DT_oTgqy.js.map +1 -0
  8. package/dist/duckdb-browser-eh.worker.js +14 -0
  9. package/dist/duckdb-browser-mvp.worker.js +14 -0
  10. package/dist/duckdb-eh.wasm +0 -0
  11. package/dist/duckdb-mvp.wasm +0 -0
  12. package/dist/globals-QF85DtAk.js +574 -0
  13. package/dist/globals-QF85DtAk.js.map +1 -0
  14. package/dist/jpeg-DckFSoVK.js +522 -0
  15. package/dist/jpeg-DckFSoVK.js.map +1 -0
  16. package/dist/lerc-BCdGEeLp.js +758 -0
  17. package/dist/lerc-BCdGEeLp.js.map +1 -0
  18. package/dist/lzw-B3twMQgz.js +73 -0
  19. package/dist/lzw-B3twMQgz.js.map +1 -0
  20. package/dist/packbits-pbHfk2l8.js +24 -0
  21. package/dist/packbits-pbHfk2l8.js.map +1 -0
  22. package/dist/pako.esm-Crx1NgSq.js +1447 -0
  23. package/dist/pako.esm-Crx1NgSq.js.map +1 -0
  24. package/dist/raw-BpEIWqGM.js +11 -0
  25. package/dist/raw-BpEIWqGM.js.map +1 -0
  26. package/dist/src/config/duckdb.d.ts +8 -0
  27. package/dist/src/main.d.ts +22 -0
  28. package/dist/src/shared/HttpCache.d.ts +55 -0
  29. package/dist/src/shared/clusterIntersectingFeatures.d.ts +11 -0
  30. package/dist/src/shared/consts.d.ts +4 -0
  31. package/dist/src/shared/interfaces.d.ts +44 -0
  32. package/dist/src/shared/osm-tag-definitions.d.ts +13 -0
  33. package/dist/src/spatial/SpatialDb.d.ts +264 -0
  34. package/dist/src/spatial/index.d.ts +5 -0
  35. package/dist/src/spatial/shared/use-cases/drop-table/DropTableUseCase.d.ts +25 -0
  36. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-area/GetBoundingBoxFromAreaUseCase.d.ts +16 -0
  37. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-area/interfaces.d.ts +6 -0
  38. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-layer/GetBoundingBoxFromLayerUseCase.d.ts +19 -0
  39. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-layer/interfaces.d.ts +6 -0
  40. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-layer/queries.d.ts +1 -0
  41. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-osm/GetBoundingBoxFromOsmUseCase.d.ts +19 -0
  42. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-osm/interfaces.d.ts +4 -0
  43. package/dist/src/spatial/shared/use-cases/get-bounding-box-from-osm/queries.d.ts +1 -0
  44. package/dist/src/spatial/shared/use-cases/transform-bounding-box-coordinates/TransformBoundingBoxCoordinatesUseCase.d.ts +20 -0
  45. package/dist/src/spatial/shared/use-cases/transform-bounding-box-coordinates/interfaces.d.ts +9 -0
  46. package/dist/src/spatial/shared/use-cases/transform-bounding-box-coordinates/queries.d.ts +11 -0
  47. package/dist/src/spatial/shared/utils.d.ts +20 -0
  48. package/dist/src/spatial/use-cases/aggregate-building-layer/AggregateBuildingLayerUseCase.d.ts +12 -0
  49. package/dist/src/spatial/use-cases/assign-building-ids/AssignBuildingIdsUseCase.d.ts +21 -0
  50. package/dist/src/spatial/use-cases/build-heatmap/BuildHeatmapUseCase.d.ts +14 -0
  51. package/dist/src/spatial/use-cases/build-heatmap/index.d.ts +2 -0
  52. package/dist/src/spatial/use-cases/build-heatmap/interfaces.d.ts +18 -0
  53. package/dist/src/spatial/use-cases/get-layer-geojson/GetLayerGeojsonUseCase.d.ts +11 -0
  54. package/dist/src/spatial/use-cases/get-layer-geojson/index.d.ts +1 -0
  55. package/dist/src/spatial/use-cases/get-layer-geojson/queries.d.ts +2 -0
  56. package/dist/src/spatial/use-cases/get-table-data/GetTableDataUseCase.d.ts +10 -0
  57. package/dist/src/spatial/use-cases/get-table-data/index.d.ts +2 -0
  58. package/dist/src/spatial/use-cases/get-table-data/interfaces.d.ts +7 -0
  59. package/dist/src/spatial/use-cases/load-csv/LoadCsvUseCase.d.ts +13 -0
  60. package/dist/src/spatial/use-cases/load-csv/index.d.ts +2 -0
  61. package/dist/src/spatial/use-cases/load-csv/interfaces.d.ts +12 -0
  62. package/dist/src/spatial/use-cases/load-csv/queries.d.ts +12 -0
  63. package/dist/src/spatial/use-cases/load-custom-layer/LoadCustomLayerUseCase.d.ts +13 -0
  64. package/dist/src/spatial/use-cases/load-custom-layer/index.d.ts +2 -0
  65. package/dist/src/spatial/use-cases/load-custom-layer/interfaces.d.ts +13 -0
  66. package/dist/src/spatial/use-cases/load-custom-layer/queries.d.ts +3 -0
  67. package/dist/src/spatial/use-cases/load-geotiff/LoadGeoTiffUseCase.d.ts +12 -0
  68. package/dist/src/spatial/use-cases/load-geotiff/index.d.ts +2 -0
  69. package/dist/src/spatial/use-cases/load-geotiff/interfaces.d.ts +33 -0
  70. package/dist/src/spatial/use-cases/load-grid-layer/LoadGridLayerUseCase.d.ts +17 -0
  71. package/dist/src/spatial/use-cases/load-json/LoadJsonUseCase.d.ts +12 -0
  72. package/dist/src/spatial/use-cases/load-json/index.d.ts +2 -0
  73. package/dist/src/spatial/use-cases/load-json/interfaces.d.ts +11 -0
  74. package/dist/src/spatial/use-cases/load-json/queries.d.ts +11 -0
  75. package/dist/src/spatial/use-cases/load-layer/LoadLayerUseCase.d.ts +27 -0
  76. package/dist/src/spatial/use-cases/load-layer/index.d.ts +2 -0
  77. package/dist/src/spatial/use-cases/load-layer/interfaces.d.ts +19 -0
  78. package/dist/src/spatial/use-cases/load-layer/osm-processing-config.d.ts +10 -0
  79. package/dist/src/spatial/use-cases/load-layer/queries.d.ts +12 -0
  80. package/dist/src/spatial/use-cases/load-osm-from-overpass-api/LoadOsmFromOverpassApiUseCase.d.ts +89 -0
  81. package/dist/src/spatial/use-cases/load-osm-from-overpass-api/index.d.ts +2 -0
  82. package/dist/src/spatial/use-cases/load-osm-from-overpass-api/interfaces.d.ts +59 -0
  83. package/dist/src/spatial/use-cases/load-osm-from-overpass-api/queries.d.ts +2 -0
  84. package/dist/src/spatial/use-cases/load-osm-from-pbf/LoadOsmFromPbfUseCase.d.ts +39 -0
  85. package/dist/src/spatial/use-cases/load-osm-from-pbf/index.d.ts +1 -0
  86. package/dist/src/spatial/use-cases/load-osm-from-pbf/osm-pbf-parser.d.ts +28 -0
  87. package/dist/src/spatial/use-cases/osm-processing-pipeline/OsmProcessingPipeline.d.ts +67 -0
  88. package/dist/src/spatial/use-cases/polygonize-surface-layer/PolygonizeSurfaceLayerUseCase.d.ts +13 -0
  89. package/dist/src/spatial/use-cases/polygonize-surface-layer/index.d.ts +2 -0
  90. package/dist/src/spatial/use-cases/polygonize-surface-layer/interfaces.d.ts +4 -0
  91. package/dist/src/spatial/use-cases/polygonize-surface-layer/queries.d.ts +1 -0
  92. package/dist/src/spatial/use-cases/raw-query/RawQueryUseCase.d.ts +12 -0
  93. package/dist/src/spatial/use-cases/raw-query/errors.d.ts +6 -0
  94. package/dist/src/spatial/use-cases/raw-query/index.d.ts +3 -0
  95. package/dist/src/spatial/use-cases/raw-query/interfaces.d.ts +13 -0
  96. package/dist/src/spatial/use-cases/spatial-join/SpatialJoinUseCase.d.ts +22 -0
  97. package/dist/src/spatial/use-cases/spatial-join/errors.d.ts +7 -0
  98. package/dist/src/spatial/use-cases/spatial-join/interfaces.d.ts +22 -0
  99. package/dist/src/spatial/use-cases/spatial-join/queries.d.ts +24 -0
  100. package/dist/src/spatial/use-cases/update-table/UpdateTableUseCase.d.ts +41 -0
  101. package/dist/src/spatial/use-cases/update-table/index.d.ts +3 -0
  102. package/dist/src/spatial/use-cases/update-table/interfaces.d.ts +35 -0
  103. package/dist/src/spatial/use-cases/update-table/queries.d.ts +45 -0
  104. package/dist/webimage-OC9EEb5f.js +25 -0
  105. package/dist/webimage-OC9EEb5f.js.map +1 -0
  106. package/dist/zstd-rpfNjbfx.js +49 -0
  107. package/dist/zstd-rpfNjbfx.js.map +1 -0
  108. package/package.json +58 -0
@@ -0,0 +1,21 @@
1
+ import { AsyncDuckDB, AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { Column } from '../../../shared/interfaces';
3
+ /**
4
+ * Assigns stable `building_id` values by clustering intersecting building geometries.
5
+ */
6
+ export declare class AssignBuildingIdsUseCase {
7
+ private db;
8
+ private conn;
9
+ constructor(db: AsyncDuckDB, conn: AsyncDuckDBConnection);
10
+ /**
11
+ * Reads geometries from the provided building table, computes intersecting
12
+ * clusters in JS, writes a stable building_id per row back to the table, and
13
+ * returns the updated column list for the table.
14
+ */
15
+ exec(params: {
16
+ tableName: string;
17
+ workspace?: string;
18
+ }): Promise<Column[]>;
19
+ private columnExists;
20
+ private describeColumns;
21
+ }
@@ -0,0 +1,14 @@
1
+ import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { BuildHeatmapParams } from './interfaces';
3
+ import { BoundingBox, Table } from '../../../shared/interfaces';
4
+ /**
5
+ * Builds a heatmap grid by spatially joining source data into grid cells.
6
+ */
7
+ export declare class BuildHeatmapUseCase {
8
+ private conn;
9
+ private loadGridLayerUseCase;
10
+ private spatialJoinUseCase;
11
+ constructor(conn: AsyncDuckDBConnection);
12
+ exec(params: BuildHeatmapParams, tables: Array<Table>, boundingBox?: BoundingBox): Promise<Table>;
13
+ private transformToRasterFormat;
14
+ }
@@ -0,0 +1,2 @@
1
+ export { BuildHeatmapUseCase } from './BuildHeatmapUseCase';
2
+ export type { BuildHeatmapParams } from './interfaces';
@@ -0,0 +1,18 @@
1
+ export type HeatmapAggregateFunction = 'sum' | 'avg' | 'count' | 'min' | 'max' | 'weighted';
2
+ export interface BuildHeatmapParams {
3
+ tableJoinName: string;
4
+ nearDistance: number;
5
+ outputTableName: string;
6
+ groupBy?: {
7
+ selectColumns: Array<{
8
+ tableName: string;
9
+ column: string;
10
+ aggregateFn?: HeatmapAggregateFunction;
11
+ aggregateFnResultColumnName?: string;
12
+ }>;
13
+ };
14
+ grid: {
15
+ rows: number;
16
+ columns: number;
17
+ };
18
+ }
@@ -0,0 +1,11 @@
1
+ import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { FeatureCollection } from 'geojson';
3
+ import { CustomLayerTable, LayerTable } from '../../../shared/interfaces';
4
+ /**
5
+ * Exports a layer table as a GeoJSON FeatureCollection.
6
+ */
7
+ export declare class GetLayerGeojsonUseCase {
8
+ private conn;
9
+ constructor(conn: AsyncDuckDBConnection);
10
+ exec(table: LayerTable | CustomLayerTable, workspace?: string): Promise<FeatureCollection>;
11
+ }
@@ -0,0 +1 @@
1
+ export * from './GetLayerGeojsonUseCase';
@@ -0,0 +1,2 @@
1
+ import { CustomLayerTable, LayerTable } from '../../../shared/interfaces';
2
+ export declare const GET_LAYER_AS_GEOJSON_QUERY: (layerTable: LayerTable | CustomLayerTable, workspace: string) => string;
@@ -0,0 +1,10 @@
1
+ import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { GetTableDataParams, GetTableDataOutput } from './interfaces';
3
+ /**
4
+ * Reads rows from any table as plain JavaScript objects.
5
+ */
6
+ export declare class GetTableDataUseCase {
7
+ private conn;
8
+ constructor(conn: AsyncDuckDBConnection);
9
+ exec(params: GetTableDataParams): Promise<GetTableDataOutput>;
10
+ }
@@ -0,0 +1,2 @@
1
+ export { GetTableDataUseCase } from './GetTableDataUseCase';
2
+ export type { GetTableDataParams, GetTableDataOutput } from './interfaces';
@@ -0,0 +1,7 @@
1
+ export interface GetTableDataParams {
2
+ tableName: string;
3
+ limit?: number;
4
+ offset?: number;
5
+ workspace?: string;
6
+ }
7
+ export type GetTableDataOutput = Record<string, unknown>[];
@@ -0,0 +1,13 @@
1
+ import { AsyncDuckDB, AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { LoadCsvParams } from './interfaces';
3
+ import { CsvTable } from '../../../shared/interfaces';
4
+ /**
5
+ * Loads CSV data into DuckDB, with optional geometry column creation.
6
+ */
7
+ export declare class LoadCsvUseCase {
8
+ private db;
9
+ private conn;
10
+ constructor(db: AsyncDuckDB, conn: AsyncDuckDBConnection);
11
+ exec({ csvFileUrl, csvObject, outputTableName, geometryColumns, delimiter, workspace }: LoadCsvParams): Promise<CsvTable>;
12
+ private buildCsvString;
13
+ }
@@ -0,0 +1,2 @@
1
+ export * from './LoadCsvUseCase';
2
+ export type { LoadCsvParams } from './interfaces';
@@ -0,0 +1,12 @@
1
+ export interface LoadCsvParams {
2
+ csvFileUrl?: string;
3
+ csvObject?: unknown[][];
4
+ outputTableName: string;
5
+ delimiter?: string;
6
+ geometryColumns?: {
7
+ latColumnName: string;
8
+ longColumnName: string;
9
+ coordinateFormat?: string;
10
+ };
11
+ workspace?: string;
12
+ }
@@ -0,0 +1,12 @@
1
+ export declare const LOAD_CSV_ON_TABLE_QUERY: (csvFileUrl: string, tableName: string, delimiter: string, workspace: string) => string;
2
+ interface LoadCsvOnTableWithCoordinatesParams {
3
+ csvFileUrl: string;
4
+ tableName: string;
5
+ delimiter: string;
6
+ latColumnName: string;
7
+ longColumnName: string;
8
+ coordinateFormat: string;
9
+ workspace: string;
10
+ }
11
+ export declare const LOAD_CSV_ON_TABLE_WITH_COORDINATES_QUERY: ({ csvFileUrl, tableName, delimiter, latColumnName, longColumnName, coordinateFormat, workspace, }: LoadCsvOnTableWithCoordinatesParams) => string;
12
+ export {};
@@ -0,0 +1,13 @@
1
+ import { AsyncDuckDB, AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { CustomLayerTable } from '../../../shared/interfaces';
3
+ import { LoadCustomLayerParams } from './interfaces';
4
+ /**
5
+ * Loads a GeoJSON FeatureCollection as a spatial layer table.
6
+ */
7
+ export declare class LoadCustomLayerUseCase {
8
+ private db;
9
+ private conn;
10
+ constructor(db: AsyncDuckDB, conn: AsyncDuckDBConnection);
11
+ exec({ geojsonFileUrl, geojsonObject, outputTableName, coordinateFormat, boundingBox, workspace, layerType, }: LoadCustomLayerParams): Promise<CustomLayerTable>;
12
+ private createTableFromFeatureCollection;
13
+ }
@@ -0,0 +1,2 @@
1
+ export * from './LoadCustomLayerUseCase';
2
+ export type { LoadCustomLayerParams } from './interfaces';
@@ -0,0 +1,13 @@
1
+ import { FeatureCollection } from 'geojson';
2
+ import { LayerType } from 'autk-core';
3
+ import { BoundingBox } from '../../../shared/interfaces';
4
+ export interface LoadCustomLayerParams {
5
+ geojsonFileUrl?: string;
6
+ geojsonObject?: FeatureCollection;
7
+ outputTableName: string;
8
+ coordinateFormat?: string;
9
+ boundingBox?: BoundingBox;
10
+ workspace?: string;
11
+ /** Explicitly set the layer type. If omitted, auto-detected from the first feature's geometry. */
12
+ layerType?: LayerType;
13
+ }
@@ -0,0 +1,3 @@
1
+ import { BoundingBox } from '../../../shared/interfaces';
2
+ export declare const LOAD_FEATURE_COLLECTION_QUERY: (geojsonFileUrl: string, featureCollectionTableName: string, workspace: string) => string;
3
+ export declare const LOAD_LAYER_FROM_FEATURE_COLLECTION_QUERY: (featureCollectionTableName: string, outputTableName: string, coordinateFormat: string, workspace: string, boundingBox?: BoundingBox) => string;
@@ -0,0 +1,12 @@
1
+ import { AsyncDuckDB, AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { GeoTiffTable } from '../../../shared/interfaces';
3
+ import { LoadGeoTiffParams } from './interfaces';
4
+ /**
5
+ * Loads a GeoTIFF raster file into DuckDB as a spatially-indexed table.
6
+ */
7
+ export declare class LoadGeoTiffUseCase {
8
+ private db;
9
+ private conn;
10
+ constructor(db: AsyncDuckDB, conn: AsyncDuckDBConnection);
11
+ exec(params: LoadGeoTiffParams): Promise<GeoTiffTable>;
12
+ }
@@ -0,0 +1,2 @@
1
+ export { LoadGeoTiffUseCase } from './LoadGeoTiffUseCase';
2
+ export type { LoadGeoTiffParams } from './interfaces';
@@ -0,0 +1,33 @@
1
+ import { BoundingBox } from '../../../shared/interfaces';
2
+ export interface LoadGeoTiffParams {
3
+ /** URL of the GeoTIFF file to fetch and load. */
4
+ geotiffFileUrl?: string;
5
+ /** Raw ArrayBuffer of an already-fetched GeoTIFF file. */
6
+ geotiffArrayBuffer?: ArrayBuffer;
7
+ /** Name of the output DuckDB table. */
8
+ outputTableName: string;
9
+ /**
10
+ * Target coordinate format for the geometry column (e.g. 'EPSG:3395').
11
+ * Defaults to EPSG:4326 (no transformation).
12
+ */
13
+ coordinateFormat?: string;
14
+ /**
15
+ * CRS of the input GeoTIFF (e.g. 'EPSG:4326', 'EPSG:32633').
16
+ * Required when coordinateFormat differs from the file's native CRS.
17
+ * If omitted, no coordinate transformation is applied.
18
+ */
19
+ sourceCrs?: string;
20
+ /**
21
+ * Clip the raster to this bounding box (in the source CRS) before loading.
22
+ * Strongly recommended for large tiles — without it the full raster is decoded,
23
+ * which may be millions of pixels and exceed browser memory limits.
24
+ */
25
+ boundingBox?: BoundingBox;
26
+ /**
27
+ * Maximum number of pixels to load. Defaults to 500 000.
28
+ * An error is thrown if the decoded region exceeds this limit,
29
+ * prompting the caller to supply a `boundingBox` to reduce the area.
30
+ */
31
+ maxPixels?: number;
32
+ workspace?: string;
33
+ }
@@ -0,0 +1,17 @@
1
+ import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { BoundingBox, GridLayerTable } from '../../../shared/interfaces';
3
+ export interface LoadGridLayerParams {
4
+ boundingBox?: BoundingBox;
5
+ rows: number;
6
+ columns: number;
7
+ outputTableName: string;
8
+ workspace?: string;
9
+ }
10
+ /**
11
+ * Creates a grid layer table with evenly spaced cell centroids.
12
+ */
13
+ export declare class LoadGridLayerUseCase {
14
+ private conn;
15
+ constructor(conn: AsyncDuckDBConnection);
16
+ exec(params: LoadGridLayerParams): Promise<GridLayerTable>;
17
+ }
@@ -0,0 +1,12 @@
1
+ import { AsyncDuckDB, AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { LoadJsonParams } from './interfaces';
3
+ import { JsonTable } from '../../../shared/interfaces';
4
+ /**
5
+ * Loads JSON data into DuckDB, with optional geometry column creation.
6
+ */
7
+ export declare class LoadJsonUseCase {
8
+ private db;
9
+ private conn;
10
+ constructor(db: AsyncDuckDB, conn: AsyncDuckDBConnection);
11
+ exec({ jsonFileUrl, jsonObject, outputTableName, geometryColumns, workspace }: LoadJsonParams): Promise<JsonTable>;
12
+ }
@@ -0,0 +1,2 @@
1
+ export * from './LoadJsonUseCase';
2
+ export type { LoadJsonParams } from './interfaces';
@@ -0,0 +1,11 @@
1
+ export interface LoadJsonParams {
2
+ jsonFileUrl?: string;
3
+ jsonObject?: unknown[];
4
+ outputTableName: string;
5
+ geometryColumns?: {
6
+ latColumnName: string;
7
+ longColumnName: string;
8
+ coordinateFormat?: string;
9
+ };
10
+ workspace?: string;
11
+ }
@@ -0,0 +1,11 @@
1
+ export declare const LOAD_JSON_ON_TABLE_QUERY: (jsonFileUrl: string, tableName: string, workspace: string) => string;
2
+ interface LoadJsonOnTableWithCoordinatesParams {
3
+ jsonFileUrl: string;
4
+ tableName: string;
5
+ latColumnName: string;
6
+ longColumnName: string;
7
+ coordinateFormat: string;
8
+ workspace: string;
9
+ }
10
+ export declare const LOAD_JSON_ON_TABLE_WITH_COORDINATES_QUERY: ({ jsonFileUrl, tableName, latColumnName, longColumnName, coordinateFormat, workspace, }: LoadJsonOnTableWithCoordinatesParams) => string;
11
+ export {};
@@ -0,0 +1,27 @@
1
+ import { AsyncDuckDB, AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { LoadLayerParams } from './interfaces';
3
+ import { LayerTable } from '../../../shared/interfaces';
4
+ /**
5
+ * Extracts a thematic layer (roads, buildings, parks, water, surface) from raw OSM data.
6
+ */
7
+ export declare class LoadLayerUseCase {
8
+ private db;
9
+ private conn;
10
+ private assignBuildingIdsUseCase;
11
+ private aggregateBuildingLayerUseCase;
12
+ constructor(db: AsyncDuckDB, conn: AsyncDuckDBConnection);
13
+ exec(params: LoadLayerParams): Promise<LayerTable>;
14
+ private appendRelationAreaGeometries;
15
+ private buildRelationAreaRecords;
16
+ private buildRelationGeometry;
17
+ private buildClosedRings;
18
+ private stitchOpenWaySegmentsIntoRings;
19
+ private tryMergeRings;
20
+ private concatRings;
21
+ private reverseRing;
22
+ private ringContainsPosition;
23
+ private parseTags;
24
+ private toNumberArray;
25
+ private toStringArray;
26
+ private toNumber;
27
+ }
@@ -0,0 +1,2 @@
1
+ export * from './LoadLayerUseCase';
2
+ export type { LoadLayerParams, Layer } from './interfaces';
@@ -0,0 +1,19 @@
1
+ import { LayerType, BoundingBox } from 'autk-core';
2
+ export type { LayerType };
3
+ export interface LoadLayerParams {
4
+ osmInputTableName: string;
5
+ outputTableName?: string;
6
+ layer: LayerType;
7
+ coordinateFormat?: string;
8
+ boundingBox?: BoundingBox;
9
+ workspace?: string;
10
+ }
11
+ export interface Layer {
12
+ metadata: {
13
+ [key: string]: string;
14
+ };
15
+ linestring: {
16
+ type: 'LineString';
17
+ coordinates: Array<Array<number>>;
18
+ };
19
+ }
@@ -0,0 +1,10 @@
1
+ import { LayerType } from 'autk-core';
2
+ export type OsmLayerType = Exclude<LayerType, 'background'>;
3
+ export interface OsmProcessingConfig {
4
+ type: OsmLayerType;
5
+ processesRelations: boolean;
6
+ createsPolygons: boolean;
7
+ postProcessing?: 'building-aggregation' | 'surface-polygonization' | null;
8
+ }
9
+ export declare const OSM_PROCESSING_CONFIGS: Record<OsmLayerType, OsmProcessingConfig>;
10
+ export declare function getOsmProcessingConfig(layer: LayerType): OsmProcessingConfig | null;
@@ -0,0 +1,12 @@
1
+ import { LayerType } from './interfaces';
2
+ import { BoundingBox } from '../../../shared/interfaces';
3
+ type Params = {
4
+ tableName: string;
5
+ layer: LayerType;
6
+ outputFormat: string;
7
+ outputTableName: string;
8
+ boundingBox?: BoundingBox;
9
+ workspace?: string;
10
+ };
11
+ export declare const LOAD_LAYER_QUERY: ({ tableName, layer, outputFormat, outputTableName, boundingBox, workspace }: Params) => string;
12
+ export {};
@@ -0,0 +1,89 @@
1
+ import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { LoadOsmParams } from './interfaces';
3
+ import { OsmTable } from '../../../shared/interfaces';
4
+ import { OsmProcessingPipeline } from '../osm-processing-pipeline/OsmProcessingPipeline';
5
+ interface OsmExecResult {
6
+ tables: OsmTable[];
7
+ osmElementCount: number;
8
+ boundaryElementCount: number;
9
+ osmDataProcessingMs: number;
10
+ boundariesProcessingMs: number;
11
+ }
12
+ /**
13
+ * Loads OSM data from the Overpass API with caching, retry, and slot polling.
14
+ */
15
+ export declare class LoadOsmFromOverpassApiUseCase {
16
+ private readonly conn;
17
+ private readonly cache;
18
+ private readonly pipeline;
19
+ constructor(conn: AsyncDuckDBConnection, pipeline: OsmProcessingPipeline);
20
+ exec(params: LoadOsmParams): Promise<OsmExecResult>;
21
+ private getCacheKey;
22
+ private getFullDataCacheKey;
23
+ /**
24
+ * Fetches OSM data as four independent requests — boundaries, parks+water,
25
+ * roads, buildings — so each request is smaller and less likely to trigger a
26
+ * 504. A pause between requests avoids immediate rate-limiting. Results are
27
+ * cached for 24h.
28
+ *
29
+ * `geocodeArea` (e.g. "New York") is used only as a disambiguation scope.
30
+ * All data is spatially constrained to the entries in `queryArea.areas`.
31
+ */
32
+ private fetchCombinedOsmData;
33
+ private static readonly OVERPASS_ENDPOINT;
34
+ private static readonly OVERPASS_STATUS_ENDPOINT;
35
+ private static readonly QUERY_TIMEOUTS_S;
36
+ private static setQueryTimeout;
37
+ /**
38
+ * Polls the Overpass status endpoint until a slot is free, then returns.
39
+ * Fails silently — a status check error never blocks the actual request.
40
+ */
41
+ private waitForSlot;
42
+ /**
43
+ * POSTs a query to the Overpass API with slot checking and automatic retry.
44
+ *
45
+ * POST is used so large queries are never truncated by proxy URL-length limits.
46
+ * Before each top-level call the slot status is checked and waited on.
47
+ *
48
+ * Retryable conditions:
49
+ * - 429 / 503 — server overloaded; backoff: 20s → 45s → 90s → 120s → 180s → 240s
50
+ * - 504 / ERR_EMPTY_RESPONSE / fetch timeout — proxy rejection; backoff:
51
+ * 10s → 20s → 45s → 90s → 120s → 180s, plus [timeout] in the query is
52
+ * stepped down (60s → 45s → 30s → 20s → 15s → 10s) so each retry looks
53
+ * cheaper to the server.
54
+ *
55
+ * All backoff values have ±10% jitter. The fetch-level AbortController
56
+ * deadline is derived from the current query [timeout] + 30s overhead.
57
+ */
58
+ private fetchWithRetry;
59
+ /**
60
+ * Builds the boundaries query: admin relations + their member ways.
61
+ * Relations are output with `body` only (tags + member IDs); ways get full
62
+ * inline geometry via `out geom qt`.
63
+ */
64
+ private buildBoundariesQuery;
65
+ /**
66
+ * Builds a query for a specific group of layers.
67
+ * Returns null when no tag selectors apply to the given group (e.g. surface-only).
68
+ */
69
+ private buildLayerGroupQuery;
70
+ /**
71
+ * Returns Overpass tag filter expressions for the requested layers.
72
+ * Uses value-level specificity for `natural` to avoid fetching unused types
73
+ * (coastline, beach, cliff, etc.). `surface` needs no selectors — its ways
74
+ * come from `way(r.rel)` in the boundaries query.
75
+ */
76
+ private getTagSelectorsForLayers;
77
+ private buildExactValueSelector;
78
+ private buildExcludedValueSelector;
79
+ /**
80
+ * Returns `cols × rows` Overpass queries that together cover `bbox`, each
81
+ * using a combined area + tile-bbox filter so only features inside both the
82
+ * named OSM area and the tile are returned. 256 MB maxsize per tile keeps
83
+ * each response well within Overpass limits.
84
+ */
85
+ private buildBuildingsTileQueries;
86
+ /** Merges two Overpass responses, deduplicating all elements by (type, id). */
87
+ private mergeResponses;
88
+ }
89
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './LoadOsmFromOverpassApiUseCase';
2
+ export type { LoadOsmParams, LoadingPhase, OnLoadingProgress, OsmLoadTimings, LayerLoadTimings } from './interfaces';
@@ -0,0 +1,59 @@
1
+ import { LayerType } from 'autk-core';
2
+ export interface OsmElement {
3
+ type: 'node' | 'way' | 'relation';
4
+ id: number;
5
+ lat?: number;
6
+ lon?: number;
7
+ tags?: Record<string, string>;
8
+ members?: {
9
+ type: 'node' | 'way' | 'relation';
10
+ ref: number;
11
+ role?: string;
12
+ }[];
13
+ nodes?: number[];
14
+ /** Inline geometry from Overpass `out geom;` — present alongside `nodes` for ways. */
15
+ geometry?: Array<{
16
+ lat: number;
17
+ lon: number;
18
+ }>;
19
+ }
20
+ export type LoadingPhase = 'querying-osm-server' | 'downloading-osm-data' | 'processing-osm-data' | 'processing-boundaries';
21
+ export type OnLoadingProgress = (phase: LoadingPhase) => void;
22
+ export interface LayerLoadTimings {
23
+ layerName: string;
24
+ layerType: string;
25
+ /** Time in ms to run the SQL query that extracts this layer from the OSM table (excludes HTTP). */
26
+ loadMs: number;
27
+ /** Number of GeoJSON features in the loaded layer. */
28
+ featureCount: number;
29
+ }
30
+ export interface OsmLoadTimings {
31
+ /** Number of OSM elements (nodes + ways + relations) in the main dataset. */
32
+ osmElementCount: number;
33
+ /** Number of elements in the boundary dataset. */
34
+ boundaryElementCount: number;
35
+ /** Time in ms to insert OSM elements into DuckDB (excludes HTTP download). */
36
+ osmDataProcessingMs: number;
37
+ /** Time in ms to insert boundary elements into DuckDB (excludes HTTP download). */
38
+ boundariesProcessingMs: number;
39
+ /** Per-layer timing and feature count details (populated when autoLoadLayers is used). */
40
+ layers: LayerLoadTimings[];
41
+ }
42
+ export type LoadOsmParams = {
43
+ outputTableName: string;
44
+ autoLoadLayers?: {
45
+ coordinateFormat: string;
46
+ dropOsmTable: boolean;
47
+ layers: Array<LayerType>;
48
+ };
49
+ queryArea: {
50
+ geocodeArea: string;
51
+ areas: string[];
52
+ };
53
+ /** If provided, OSM data is loaded from this `.osm.pbf` file instead of the Overpass API. */
54
+ pbfFileUrl?: string;
55
+ /** When true, bypasses the cached Overpass response and fetches fresh data. */
56
+ forceRefresh?: boolean;
57
+ workspace?: string;
58
+ onProgress?: OnLoadingProgress;
59
+ };
@@ -0,0 +1,2 @@
1
+ export declare const CREATE_OSM_TABLE_QUERY: (tableName: string, workspace: string) => string;
2
+ export declare const INSERT_OSM_DATA_QUERY: (tableName: string, fileName: string, workspace: string, ignoreTags?: boolean) => string;
@@ -0,0 +1,39 @@
1
+ import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
2
+ import { OsmTable } from '../../../shared/interfaces';
3
+ import { LoadOsmParams } from '../load-osm-from-overpass-api/interfaces';
4
+ import { OsmProcessingPipeline } from '../osm-processing-pipeline/OsmProcessingPipeline';
5
+ interface OsmExecResult {
6
+ tables: OsmTable[];
7
+ osmElementCount: number;
8
+ boundaryElementCount: number;
9
+ osmDataProcessingMs: number;
10
+ boundariesProcessingMs: number;
11
+ }
12
+ /**
13
+ * Loads OSM data from a local PBF file with multi-pass streaming.
14
+ */
15
+ export declare class LoadOsmFromPbfUseCase {
16
+ private readonly conn;
17
+ private readonly pipeline;
18
+ constructor(conn: AsyncDuckDBConnection, pipeline: OsmProcessingPipeline);
19
+ exec(params: LoadOsmParams): Promise<OsmExecResult>;
20
+ private getRequestedLayers;
21
+ private collectBoundaryContext;
22
+ private collectBoundaryBbox;
23
+ private collectCandidateWaysAndRelations;
24
+ private collectRequiredNodes;
25
+ private filterFinalElements;
26
+ private buildGroupedCollections;
27
+ private mergeResponses;
28
+ private getRelationWayRefs;
29
+ private wayIntersectsBbox;
30
+ private streamPbfBlocks;
31
+ private matchesRequestedWayLayers;
32
+ private matchesRequestedRelationLayers;
33
+ private isRoadTagSet;
34
+ private isBuildingTagSet;
35
+ private isParkTagSet;
36
+ private isWaterTagSet;
37
+ private hasTagValue;
38
+ }
39
+ export {};
@@ -0,0 +1 @@
1
+ export { LoadOsmFromPbfUseCase } from './LoadOsmFromPbfUseCase';
@@ -0,0 +1,28 @@
1
+ import { OsmPbfBlock } from '@osmix/pbf';
2
+ import { OsmElement } from '../load-osm-from-overpass-api/interfaces';
3
+ /**
4
+ * Converts a `@osmix/pbf` block into an array of `OsmElement` records.
5
+ *
6
+ * Handles all four primitive types:
7
+ * - regular nodes
8
+ * - dense nodes (delta-encoded, compact storage)
9
+ * - ways (with node refs)
10
+ * - relations (with member refs)
11
+ *
12
+ * StringTable indices are resolved to actual tag strings.
13
+ * Way geometry is **not** resolved here — caller must build a node index
14
+ * and call `resolveWayGeometries()` afterwards.
15
+ */
16
+ export declare function blockToElements(block: OsmPbfBlock): OsmElement[];
17
+ /**
18
+ * Resolves inline `geometry` for every way by looking up node coordinates.
19
+ *
20
+ * Mutates the `elements` array in place — each way that has a non-empty
21
+ * `nodes[]` array gets a matching `geometry[]` array.
22
+ *
23
+ * @returns A `Map<nodeId, {lat, lon}>` for downstream use (e.g. bbox computation).
24
+ */
25
+ export declare function resolveWayGeometries(elements: OsmElement[]): Map<number, {
26
+ lat: number;
27
+ lon: number;
28
+ }>;