@nshiab/simple-data-analysis-core 0.0.19 → 0.0.21
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.
- package/esm/class/SimpleTable.d.ts +117 -22
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +172 -104
- package/esm/helpers/findGeoColumn.js +1 -1
- package/esm/helpers/getProjection.d.ts.map +1 -1
- package/esm/helpers/getProjection.js +3 -0
- package/esm/helpers/hasGeometryColumn.d.ts +20 -0
- package/esm/helpers/hasGeometryColumn.d.ts.map +1 -0
- package/esm/helpers/hasGeometryColumn.js +21 -0
- package/esm/helpers/writeGeoData.d.ts +9 -0
- package/esm/helpers/writeGeoData.d.ts.map +1 -0
- package/esm/helpers/writeGeoData.js +110 -0
- package/esm/methods/fill.d.ts.map +1 -1
- package/esm/methods/fill.js +16 -16
- package/esm/methods/fuzzyClean.d.ts +2 -2
- package/esm/methods/fuzzyClean.d.ts.map +1 -1
- package/esm/methods/fuzzyClean.js +25 -6
- package/esm/methods/fuzzyJoin.d.ts +2 -2
- package/esm/methods/fuzzyJoin.d.ts.map +1 -1
- package/esm/methods/fuzzyJoin.js +3 -3
- package/esm/methods/fuzzyJoinQuery.d.ts +1 -1
- package/esm/methods/fuzzyJoinQuery.d.ts.map +1 -1
- package/esm/methods/fuzzyJoinQuery.js +13 -3
- package/esm/methods/loadDataQuery.d.ts +1 -0
- package/esm/methods/loadDataQuery.d.ts.map +1 -1
- package/esm/methods/loadDataQuery.js +12 -4
- package/esm/methods/padQuery.d.ts +5 -0
- package/esm/methods/padQuery.d.ts.map +1 -0
- package/esm/methods/padQuery.js +14 -0
- package/esm/methods/writeGeoDataQuery.d.ts.map +1 -1
- package/esm/methods/writeGeoDataQuery.js +4 -1
- package/package.json +1 -1
- package/script/class/SimpleTable.d.ts +117 -22
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +172 -104
- package/script/helpers/findGeoColumn.js +1 -1
- package/script/helpers/getProjection.d.ts.map +1 -1
- package/script/helpers/getProjection.js +3 -0
- package/script/helpers/hasGeometryColumn.d.ts +20 -0
- package/script/helpers/hasGeometryColumn.d.ts.map +1 -0
- package/script/helpers/hasGeometryColumn.js +24 -0
- package/script/helpers/writeGeoData.d.ts +9 -0
- package/script/helpers/writeGeoData.d.ts.map +1 -0
- package/script/helpers/writeGeoData.js +116 -0
- package/script/methods/fill.d.ts.map +1 -1
- package/script/methods/fill.js +16 -16
- package/script/methods/fuzzyClean.d.ts +2 -2
- package/script/methods/fuzzyClean.d.ts.map +1 -1
- package/script/methods/fuzzyClean.js +25 -6
- package/script/methods/fuzzyJoin.d.ts +2 -2
- package/script/methods/fuzzyJoin.d.ts.map +1 -1
- package/script/methods/fuzzyJoin.js +3 -3
- package/script/methods/fuzzyJoinQuery.d.ts +1 -1
- package/script/methods/fuzzyJoinQuery.d.ts.map +1 -1
- package/script/methods/fuzzyJoinQuery.js +13 -3
- package/script/methods/loadDataQuery.d.ts +1 -0
- package/script/methods/loadDataQuery.d.ts.map +1 -1
- package/script/methods/loadDataQuery.js +12 -4
- package/script/methods/padQuery.d.ts +5 -0
- package/script/methods/padQuery.d.ts.map +1 -0
- package/script/methods/padQuery.js +17 -0
- package/script/methods/writeGeoDataQuery.d.ts.map +1 -1
- package/script/methods/writeGeoDataQuery.js +4 -1
|
@@ -52,6 +52,7 @@ const normalizeQuery_js_1 = __importDefault(require("../methods/normalizeQuery.j
|
|
|
52
52
|
const rollingQuery_js_1 = __importDefault(require("../methods/rollingQuery.js"));
|
|
53
53
|
const distanceQuery_js_1 = __importDefault(require("../methods/distanceQuery.js"));
|
|
54
54
|
const getGeoData_js_1 = __importDefault(require("../methods/getGeoData.js"));
|
|
55
|
+
const writeGeoData_js_1 = __importDefault(require("../helpers/writeGeoData.js"));
|
|
55
56
|
const splitSpread_js_1 = __importDefault(require("../methods/splitSpread.js"));
|
|
56
57
|
const node_fs_1 = require("node:fs");
|
|
57
58
|
const stringToArray_js_1 = __importDefault(require("../helpers/stringToArray.js"));
|
|
@@ -59,24 +60,20 @@ const loadDataQuery_js_1 = __importDefault(require("../methods/loadDataQuery.js"
|
|
|
59
60
|
const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
|
|
60
61
|
const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
|
|
61
62
|
const writeDataQuery_js_1 = __importDefault(require("../methods/writeDataQuery.js"));
|
|
62
|
-
const writeGeoDataQuery_js_1 = __importDefault(require("../methods/writeGeoDataQuery.js"));
|
|
63
63
|
const runQuery_js_1 = __importDefault(require("../helpers/runQuery.js"));
|
|
64
64
|
const aggregateGeoQuery_js_1 = __importDefault(require("../methods/aggregateGeoQuery.js"));
|
|
65
65
|
const summarize_js_1 = __importDefault(require("../methods/summarize.js"));
|
|
66
66
|
const correlations_js_1 = __importDefault(require("../methods/correlations.js"));
|
|
67
67
|
const linearRegressions_js_1 = __importDefault(require("../methods/linearRegressions.js"));
|
|
68
68
|
const joinGeo_js_1 = __importDefault(require("../methods/joinGeo.js"));
|
|
69
|
-
const shouldFlipBeforeExport_js_1 = __importDefault(require("../helpers/shouldFlipBeforeExport.js"));
|
|
70
69
|
const getProjection_js_1 = __importDefault(require("../helpers/getProjection.js"));
|
|
71
70
|
const cache_js_1 = __importDefault(require("../methods/cache.js"));
|
|
72
71
|
const camelCase_js_1 = __importDefault(require("../helpers/camelCase.js"));
|
|
73
72
|
const formatNumber_js_1 = __importDefault(require("../helpers/formatNumber.js"));
|
|
74
73
|
const createDirectory_js_1 = __importDefault(require("../helpers/createDirectory.js"));
|
|
75
|
-
const rewind_js_1 = __importDefault(require("../helpers/rewind.js"));
|
|
76
74
|
const writeDataAsArrays_js_1 = __importDefault(require("../helpers/writeDataAsArrays.js"));
|
|
77
75
|
const logData_js_1 = __importDefault(require("../helpers/logData.js"));
|
|
78
76
|
const fill_js_1 = __importDefault(require("../methods/fill.js"));
|
|
79
|
-
const node_fs_2 = require("node:fs");
|
|
80
77
|
const loadArray_js_1 = __importDefault(require("../methods/loadArray.js"));
|
|
81
78
|
const cleanPath_js_1 = __importDefault(require("../helpers/cleanPath.js"));
|
|
82
79
|
const Simple_js_1 = __importDefault(require("./Simple.js"));
|
|
@@ -91,11 +88,11 @@ const getExtension_js_1 = __importDefault(require("../helpers/getExtension.js"))
|
|
|
91
88
|
const getIdenticalColumns_js_1 = __importDefault(require("../helpers/getIdenticalColumns.js"));
|
|
92
89
|
const capitalizeQuery_js_1 = __importDefault(require("../methods/capitalizeQuery.js"));
|
|
93
90
|
const truncateQuery_js_1 = __importDefault(require("../methods/truncateQuery.js"));
|
|
91
|
+
const padQuery_js_1 = __importDefault(require("../methods/padQuery.js"));
|
|
94
92
|
const getProjectionParquet_js_1 = __importDefault(require("../helpers/getProjectionParquet.js"));
|
|
93
|
+
const hasGeometryColumn_js_1 = __importDefault(require("../helpers/hasGeometryColumn.js"));
|
|
95
94
|
const unifyColumns_js_1 = __importDefault(require("../helpers/unifyColumns.js"));
|
|
96
95
|
const accumulateQuery_js_1 = __importDefault(require("../helpers/accumulateQuery.js"));
|
|
97
|
-
const stringifyDates_js_1 = __importDefault(require("../helpers/stringifyDates.js"));
|
|
98
|
-
const stringifyDatesInvert_js_1 = __importDefault(require("../helpers/stringifyDatesInvert.js"));
|
|
99
96
|
const unnestQuery_js_1 = __importDefault(require("../helpers/unnestQuery.js"));
|
|
100
97
|
const nestQuery_js_1 = __importDefault(require("../helpers/nestQuery.js"));
|
|
101
98
|
const concatenateRowQuery_js_1 = __importDefault(require("../helpers/concatenateRowQuery.js"));
|
|
@@ -291,6 +288,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
291
288
|
* @param options.fileName - A boolean indicating whether to include the file name as a new column in the loaded data. Defaults to `false`.
|
|
292
289
|
* @param options.unifyColumns - A boolean indicating whether to unify columns across multiple files when their structures differ. Missing columns will be filled with `NULL` values. Defaults to `false`.
|
|
293
290
|
* @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred.
|
|
291
|
+
* @param options.columns - An array of column names to load. When provided, only the specified columns are loaded, reducing memory usage and improving load times. Not supported for Excel files — combining `columns` with Excel files throws an error. If an invalid column name is provided, DuckDB will throw its native error. An empty array behaves the same as omitting the option (loads all columns). Defaults to loading all columns.
|
|
294
292
|
* @param options.header - A boolean indicating whether the file has a header row. Applicable to CSV files. Defaults to `true`.
|
|
295
293
|
* @param options.allText - A boolean indicating whether all columns should be treated as text. Applicable to CSV files. Defaults to `false`.
|
|
296
294
|
* @param options.delim - The delimiter used in the file. Applicable to CSV and DSV files. By default, the delimiter is inferred.
|
|
@@ -337,6 +335,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
337
335
|
* "https://some-website.com/some-data3.parquet"
|
|
338
336
|
* ], { unifyColumns: true });
|
|
339
337
|
* ```
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* // Load only specific columns from a CSV file
|
|
342
|
+
* await table.loadData("./employees.csv", { columns: ["name", "salary"] });
|
|
343
|
+
* ```
|
|
340
344
|
*/
|
|
341
345
|
async loadData(files, options = {}) {
|
|
342
346
|
await (0, queryDB_js_1.default)(this, (0, loadDataQuery_js_1.default)(this.name, (0, stringToArray_js_1.default)(files), options), (0, mergeOptions_js_1.default)(this, {
|
|
@@ -357,6 +361,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
357
361
|
* @param options.fileName - A boolean indicating whether to include the file name as a new column in the loaded data. Defaults to `false`.
|
|
358
362
|
* @param options.unifyColumns - A boolean indicating whether to unify columns across multiple files when their structures differ. Missing columns will be filled with `NULL` values. Defaults to `false`.
|
|
359
363
|
* @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred.
|
|
364
|
+
* @param options.columns - An array of column names to load. When provided, only the specified columns are loaded, reducing memory usage and improving load times. Not supported for Excel files — combining `columns` with Excel files throws an error. If an invalid column name is provided, DuckDB will throw its native error. An empty array behaves the same as omitting the option (loads all columns). Defaults to loading all columns.
|
|
360
365
|
* @param options.header - A boolean indicating whether the file has a header row. Applicable to CSV files. Defaults to `true`.
|
|
361
366
|
* @param options.allText - A boolean indicating whether all columns should be treated as text. Applicable to CSV files. Defaults to `false`.
|
|
362
367
|
* @param options.delim - The delimiter used in the file. Applicable to CSV and DSV files. By default, the delimiter is inferred.
|
|
@@ -377,6 +382,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
377
382
|
* // Load all supported data files from the "./data/" directory
|
|
378
383
|
* await table.loadDataFromDirectory("./data/");
|
|
379
384
|
* ```
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* // Load only specific columns from all CSV files in a directory
|
|
389
|
+
* await table.loadDataFromDirectory("./data/", { columns: ["name", "salary"] });
|
|
390
|
+
* ```
|
|
380
391
|
*/
|
|
381
392
|
async loadDataFromDirectory(directory, options = {}) {
|
|
382
393
|
const files = (0, node_fs_1.readdirSync)(directory).map((file) => `${directory.slice(-1) === "/" ? directory : directory + "/"}${file}`);
|
|
@@ -412,7 +423,13 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
412
423
|
*
|
|
413
424
|
* @example
|
|
414
425
|
* ```ts
|
|
415
|
-
* // Load geospatial data from a shapefile and reproject to WGS84
|
|
426
|
+
* // Load geospatial data from a shapefile (with relevant files in the same folder) and reproject to WGS84
|
|
427
|
+
* await table.loadGeoData("./some-data/some-data.shp", { toWGS84: true });
|
|
428
|
+
* ```
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```ts
|
|
432
|
+
* // Load geospatial data from a zipped shapefile and reproject to WGS84
|
|
416
433
|
* await table.loadGeoData("./some-data.shp.zip", { toWGS84: true });
|
|
417
434
|
* ```
|
|
418
435
|
*/
|
|
@@ -1893,48 +1910,57 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1893
1910
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
1894
1911
|
* @param leftColumn - The name of the column in this (left) table containing the text to compare.
|
|
1895
1912
|
* @param rightColumn - The name of the column in the right table containing the text to compare.
|
|
1913
|
+
* @param threshold - The minimum similarity score (0–100) required for two rows to be joined. For `method: "ratio"`, a length-based pre-filter is automatically applied based on the threshold to improve performance without losing accuracy.
|
|
1896
1914
|
* @param options - An optional object with configuration options:
|
|
1897
1915
|
* @param options.method - The rapidfuzz similarity algorithm to use. Defaults to `"ratio"`.
|
|
1898
1916
|
* - `"ratio"`: Overall similarity (Levenshtein-based).
|
|
1899
1917
|
* - `"partial_ratio"`: Best partial/substring similarity.
|
|
1900
1918
|
* - `"token_sort_ratio"`: Similarity after sorting tokens (words), useful for reordered words.
|
|
1901
1919
|
* - `"token_set_ratio"`: Similarity based on sets of tokens, ignoring duplicates and word order.
|
|
1902
|
-
* @param options.threshold - The minimum similarity score (0–100) required for two rows to be joined. Defaults to `80`.
|
|
1903
1920
|
* @param options.similarityColumn - If provided, a column with this name is added to the result containing the similarity score (0–100). If omitted, the score is not included in the output.
|
|
1904
1921
|
* @param options.outputTable - If `true`, the results will be stored in a new table with a generated name. If a string, it will be used as the name for the new table. If `false` or omitted, the current table will be overwritten. Defaults to `false`.
|
|
1922
|
+
* @param options.preFilterPrefixLen - An optional prefix length. Only strings sharing the same first N characters are compared. Note that prefix filtering is lossy (e.g. "John" vs. "Phon" will not match despite high similarity).
|
|
1905
1923
|
* @returns A promise that resolves to a table instance containing the fuzzy-joined data (either the modified current table or a new table).
|
|
1906
1924
|
* @category Table Operations
|
|
1907
1925
|
*
|
|
1908
1926
|
* @example
|
|
1909
1927
|
* ```ts
|
|
1910
|
-
* // Fuzzy left join tableA with tableB on 'name' (left) and 'standardName' (right)
|
|
1911
|
-
*
|
|
1928
|
+
* // Fuzzy left join tableA with tableB on 'name' (left) and 'standardName' (right) with a threshold of 80
|
|
1929
|
+
* // A length-based pre-filter is automatically applied.
|
|
1930
|
+
* await tableA.fuzzyJoin(tableB, "name", "standardName", 80);
|
|
1931
|
+
* ```
|
|
1932
|
+
*
|
|
1933
|
+
* @example
|
|
1934
|
+
* ```ts
|
|
1935
|
+
* // Fuzzy join with a prefix-based pre-filter and a threshold of 80
|
|
1936
|
+
* await tableA.fuzzyJoin(tableB, "name", "standardName", 80, {
|
|
1937
|
+
* preFilterPrefixLen: 3, // Must share the same first 3 characters
|
|
1938
|
+
* });
|
|
1912
1939
|
* ```
|
|
1913
1940
|
*
|
|
1914
1941
|
* @example
|
|
1915
1942
|
* ```ts
|
|
1916
1943
|
* // Fuzzy join with a custom threshold and method, storing results in a new table
|
|
1917
|
-
* const tableC = await tableA.fuzzyJoin(tableB, "name", "standardName", {
|
|
1944
|
+
* const tableC = await tableA.fuzzyJoin(tableB, "name", "standardName", 90, {
|
|
1918
1945
|
* method: "token_sort_ratio",
|
|
1919
|
-
* threshold: 90,
|
|
1920
1946
|
* outputTable: "tableC",
|
|
1921
1947
|
* });
|
|
1922
1948
|
* ```
|
|
1923
1949
|
*
|
|
1924
1950
|
* @example
|
|
1925
1951
|
* ```ts
|
|
1926
|
-
* // Fuzzy join with a custom similarity column name
|
|
1927
|
-
* await tableA.fuzzyJoin(tableB, "name", "standardName", {
|
|
1952
|
+
* // Fuzzy join with a custom similarity column name and a threshold of 80
|
|
1953
|
+
* await tableA.fuzzyJoin(tableB, "name", "standardName", 80, {
|
|
1928
1954
|
* similarityColumn: "matchScore",
|
|
1929
1955
|
* });
|
|
1930
1956
|
* ```
|
|
1931
1957
|
*/
|
|
1932
|
-
async fuzzyJoin(rightTable, leftColumn, rightColumn, options = {}) {
|
|
1958
|
+
async fuzzyJoin(rightTable, leftColumn, rightColumn, threshold, options = {}) {
|
|
1933
1959
|
if (options.outputTable === true) {
|
|
1934
1960
|
options.outputTable = `table${this.sdb.tableIncrement}`;
|
|
1935
1961
|
this.sdb.tableIncrement += 1;
|
|
1936
1962
|
}
|
|
1937
|
-
return await (0, fuzzyJoin_js_1.default)(this, rightTable, leftColumn, rightColumn, options);
|
|
1963
|
+
return await (0, fuzzyJoin_js_1.default)(this, rightTable, leftColumn, rightColumn, threshold, options);
|
|
1938
1964
|
}
|
|
1939
1965
|
/**
|
|
1940
1966
|
* Normalizes string values in a column by detecting fuzzy duplicates and replacing them with a single canonical value.
|
|
@@ -1948,42 +1974,52 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1948
1974
|
*
|
|
1949
1975
|
* @param column - The name of the column containing the strings to normalize.
|
|
1950
1976
|
* @param newColumn - The name of the column to write the normalized values to. Use the same name as `column` to normalize in-place.
|
|
1977
|
+
* @param threshold - The minimum similarity score (0–100) for two strings to be considered duplicates. For `method: "ratio"`, a length-based pre-filter is automatically applied based on the threshold to improve performance without losing accuracy.
|
|
1951
1978
|
* @param options - An optional object with configuration options:
|
|
1952
1979
|
* @param options.method - The rapidfuzz similarity algorithm to use. Defaults to `"ratio"`.
|
|
1953
1980
|
* - `"ratio"`: Overall similarity.
|
|
1954
1981
|
* - `"partial_ratio"`: Best partial/substring similarity.
|
|
1955
1982
|
* - `"token_sort_ratio"`: Similarity after sorting tokens (words), useful for reordered words.
|
|
1956
1983
|
* - `"token_set_ratio"`: Similarity based on sets of tokens, ignoring duplicates and word order.
|
|
1957
|
-
* @param options.threshold - The minimum similarity score (0–100) for two strings to be considered duplicates. Defaults to `80`.
|
|
1958
1984
|
* @param options.keep - The strategy for choosing the canonical value within each cluster of similar strings. Defaults to `"mostCommon"`.
|
|
1959
1985
|
* - `"mostCommon"`: Keep the value that appears most frequently in the original column.
|
|
1960
1986
|
* - `"longestString"`: Keep the longest string in the cluster.
|
|
1961
1987
|
* - `"shortestString"`: Keep the shortest string in the cluster.
|
|
1962
1988
|
* - `"mostCentral"`: Keep the string with the highest total similarity score to all other cluster members (the most "central" string).
|
|
1963
1989
|
* - `"maxScore"`: Keep the string that participates in the single highest-scoring pairwise match within the cluster.
|
|
1990
|
+
* @param options.preFilterPrefixLen - An optional prefix length. Only strings sharing the same first N characters are compared. Note that prefix filtering is lossy (e.g. "John" vs. "Phon" will not match despite high similarity).
|
|
1964
1991
|
* @returns A promise that resolves when the column has been normalized.
|
|
1965
1992
|
* @category Updating Data
|
|
1966
1993
|
*
|
|
1967
1994
|
* @example
|
|
1968
1995
|
* ```ts
|
|
1969
|
-
* // Normalize 'city' into a new 'cityClean' column, keeping the most common string per cluster
|
|
1970
|
-
*
|
|
1996
|
+
* // Normalize 'city' into a new 'cityClean' column, keeping the most common string per cluster with a threshold of 80
|
|
1997
|
+
* // A length-based pre-filter is automatically applied.
|
|
1998
|
+
* await table.fuzzyClean("city", "cityClean", 80);
|
|
1999
|
+
* ```
|
|
2000
|
+
*
|
|
2001
|
+
* @example
|
|
2002
|
+
* ```ts
|
|
2003
|
+
* // Normalize with a prefix-based pre-filter and a threshold of 80
|
|
2004
|
+
* await table.fuzzyClean("city", "cityClean", 80, {
|
|
2005
|
+
* preFilterPrefixLen: 5, // Must share the same first 5 characters
|
|
2006
|
+
* });
|
|
1971
2007
|
* ```
|
|
1972
2008
|
*
|
|
1973
2009
|
* @example
|
|
1974
2010
|
* ```ts
|
|
1975
|
-
* // Normalize 'companyName' into a new column using token_sort_ratio and a
|
|
1976
|
-
* await table.fuzzyClean("companyName", "companyNameClean", { method: "token_sort_ratio"
|
|
2011
|
+
* // Normalize 'companyName' into a new column using token_sort_ratio and a threshold of 90
|
|
2012
|
+
* await table.fuzzyClean("companyName", "companyNameClean", 90, { method: "token_sort_ratio" });
|
|
1977
2013
|
* ```
|
|
1978
2014
|
*
|
|
1979
2015
|
* @example
|
|
1980
2016
|
* ```ts
|
|
1981
|
-
* // Normalize 'category' in-place, keeping the longest string in each cluster
|
|
1982
|
-
* await table.fuzzyClean("category", "category", { keep: "longestString" });
|
|
2017
|
+
* // Normalize 'category' in-place, keeping the longest string in each cluster and a threshold of 80
|
|
2018
|
+
* await table.fuzzyClean("category", "category", 80, { keep: "longestString" });
|
|
1983
2019
|
* ```
|
|
1984
2020
|
*/
|
|
1985
|
-
async fuzzyClean(column, newColumn, options = {}) {
|
|
1986
|
-
await (0, fuzzyClean_js_1.default)(this, column, newColumn, options);
|
|
2021
|
+
async fuzzyClean(column, newColumn, threshold, options = {}) {
|
|
2022
|
+
await (0, fuzzyClean_js_1.default)(this, column, newColumn, threshold, options);
|
|
1987
2023
|
}
|
|
1988
2024
|
/**
|
|
1989
2025
|
* Replaces specified strings in the selected columns.
|
|
@@ -2137,6 +2173,72 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2137
2173
|
parameters: { column, length },
|
|
2138
2174
|
}));
|
|
2139
2175
|
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Pads the strings in the specified columns to a target length.
|
|
2178
|
+
*
|
|
2179
|
+
* The columns must contain string (VARCHAR) values. An error is thrown if any
|
|
2180
|
+
* column is of a different type. `null` values remain `null`. If any string
|
|
2181
|
+
* already exceeds the target length, an error is thrown (no silent truncation).
|
|
2182
|
+
*
|
|
2183
|
+
* @param columns - The column name(s) containing strings to be padded.
|
|
2184
|
+
* @param length - The target length of the padded strings.
|
|
2185
|
+
* @param options - An optional object with configuration options:
|
|
2186
|
+
* @param options.method - Which side to pad. `'left'` (default) or `'right'`.
|
|
2187
|
+
* @param options.char - The character to use for padding. Defaults to `'0'`.
|
|
2188
|
+
* @returns A promise that resolves when the padding operation is complete.
|
|
2189
|
+
* @throws {Error} If any column is not of string (VARCHAR) type.
|
|
2190
|
+
* @throws {Error} If any string value exceeds the target length.
|
|
2191
|
+
* @category Updating Data
|
|
2192
|
+
*
|
|
2193
|
+
* @example
|
|
2194
|
+
* ```ts
|
|
2195
|
+
* // Left-pad 'id' column to 3 characters with zeros (default)
|
|
2196
|
+
* await table.pad("id", 3);
|
|
2197
|
+
* // Result: '1' -> '001', '23' -> '023', null -> null
|
|
2198
|
+
* ```
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* ```ts
|
|
2202
|
+
* // Right-pad 'code' column to 5 characters with spaces
|
|
2203
|
+
* await table.pad("code", 5, { method: "right", char: " " });
|
|
2204
|
+
* // Result: '123' -> '123 ', '45' -> '45 ', null -> null
|
|
2205
|
+
* ```
|
|
2206
|
+
*
|
|
2207
|
+
* @example
|
|
2208
|
+
* ```ts
|
|
2209
|
+
* // Left-pad multiple columns to 5 characters with dashes
|
|
2210
|
+
* await table.pad(["id", "code"], 5, { method: "left", char: "-" });
|
|
2211
|
+
* // Result: '1' -> '----1', '23' -> '---23'
|
|
2212
|
+
* ```
|
|
2213
|
+
*/
|
|
2214
|
+
async pad(columns, length, options = {}) {
|
|
2215
|
+
const columnList = (0, stringToArray_js_1.default)(columns);
|
|
2216
|
+
// Validate all columns are string type
|
|
2217
|
+
const allTypes = await this.getTypes();
|
|
2218
|
+
for (const column of columnList) {
|
|
2219
|
+
if (allTypes[column] !== "VARCHAR") {
|
|
2220
|
+
throw new Error(`The column "${column}" is of type ${allTypes[column]}. The pad() method only works with string (VARCHAR) columns. Please convert the column to string first with the .convert() method.`);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
// Pre-validation: check for strings exceeding target length
|
|
2224
|
+
for (const column of columnList) {
|
|
2225
|
+
const overflowResult = await (0, queryDB_js_1.default)(this, `SELECT COUNT(*) AS cnt FROM "${this.name}" WHERE LENGTH("${column}") > ${length};`, (0, mergeOptions_js_1.default)(this, {
|
|
2226
|
+
table: this.name,
|
|
2227
|
+
method: "pad()",
|
|
2228
|
+
parameters: { columns, length, options },
|
|
2229
|
+
returnDataFrom: "query",
|
|
2230
|
+
}));
|
|
2231
|
+
const overflowCount = Number(overflowResult[0].cnt);
|
|
2232
|
+
if (overflowCount > 0) {
|
|
2233
|
+
throw new Error(`The column "${column}" has ${overflowCount} string(s) exceeding the target length of ${length}. The pad() method does not truncate. Shorten the strings first or use a larger target length.`);
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
await (0, queryDB_js_1.default)(this, (0, padQuery_js_1.default)(this.name, columnList, length, options), (0, mergeOptions_js_1.default)(this, {
|
|
2237
|
+
table: this.name,
|
|
2238
|
+
method: "pad()",
|
|
2239
|
+
parameters: { columns, length, options },
|
|
2240
|
+
}));
|
|
2241
|
+
}
|
|
2140
2242
|
/**
|
|
2141
2243
|
* Splits strings in a specified column by a separator and extracts a substring at a given index, storing the result in a new or existing column.
|
|
2142
2244
|
* If the index is out of bounds, an empty string will be returned for that row.
|
|
@@ -2482,9 +2584,18 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2482
2584
|
* // Round 'columnA' and 'columnB' values to 1 decimal place using ceiling method
|
|
2483
2585
|
* await table.round(["columnA", "columnB"], { decimals: 1, method: "ceiling" });
|
|
2484
2586
|
* ```
|
|
2587
|
+
*
|
|
2588
|
+
* @example
|
|
2589
|
+
* ```ts
|
|
2590
|
+
* // Round 'column1' values to 2 decimal places using the shorthand
|
|
2591
|
+
* await table.round("column1", 2);
|
|
2592
|
+
* ```
|
|
2485
2593
|
*/
|
|
2486
2594
|
async round(columns, options = {}) {
|
|
2487
|
-
|
|
2595
|
+
const optionsNormalized = typeof options === "number"
|
|
2596
|
+
? { decimals: options }
|
|
2597
|
+
: options;
|
|
2598
|
+
await (0, queryDB_js_1.default)(this, (0, roundQuery_js_1.default)(this.name, (0, stringToArray_js_1.default)(columns), optionsNormalized), (0, mergeOptions_js_1.default)(this, {
|
|
2488
2599
|
table: this.name,
|
|
2489
2600
|
method: "round()",
|
|
2490
2601
|
parameters: { columns, options },
|
|
@@ -3840,6 +3951,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3840
3951
|
* ```
|
|
3841
3952
|
*/
|
|
3842
3953
|
async getData(options = {}) {
|
|
3954
|
+
if (await (0, hasGeometryColumn_js_1.default)(this)) {
|
|
3955
|
+
throw new Error("Table contains geometry columns. Use getGeoData() instead.");
|
|
3956
|
+
}
|
|
3843
3957
|
const columns = options.columns
|
|
3844
3958
|
? (typeof options.columns === "string"
|
|
3845
3959
|
? [options.columns]
|
|
@@ -3904,8 +4018,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3904
4018
|
* ```
|
|
3905
4019
|
*/
|
|
3906
4020
|
async points(columnLat, columnLon, newColumn) {
|
|
3907
|
-
await (0, queryDB_js_1.default)(this,
|
|
3908
|
-
|
|
4021
|
+
await (0, queryDB_js_1.default)(this, (await this.getColumns()).includes(newColumn)
|
|
4022
|
+
? `INSTALL spatial; LOAD spatial; UPDATE "${this.name}" SET "${newColumn}" = ST_Point2D("${columnLat}", "${columnLon}")`
|
|
4023
|
+
: `INSTALL spatial; LOAD spatial; ALTER TABLE "${this.name}" ADD COLUMN "${newColumn}" GEOMETRY; UPDATE "${this.name}" SET "${newColumn}" = ST_Point2D("${columnLat}", "${columnLon}")`, (0, mergeOptions_js_1.default)(this, {
|
|
3909
4024
|
table: this.name,
|
|
3910
4025
|
method: "points()",
|
|
3911
4026
|
parameters: { columnLat, columnLon, newColumn },
|
|
@@ -4321,7 +4436,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4321
4436
|
const column = typeof options.column === "string"
|
|
4322
4437
|
? options.column
|
|
4323
4438
|
: await (0, findGeoColumn_js_1.default)(this);
|
|
4324
|
-
await (0, queryDB_js_1.default)(this,
|
|
4439
|
+
await (0, queryDB_js_1.default)(this, (await this.getColumns()).includes(newColumn)
|
|
4440
|
+
? `INSTALL spatial; LOAD spatial; UPDATE "${this.name}" SET "${newColumn}" = ST_Buffer("${column}", ${distance})`
|
|
4441
|
+
: `INSTALL spatial; LOAD spatial; ALTER TABLE "${this.name}" ADD "${newColumn}" GEOMETRY; UPDATE "${this.name}" SET "${newColumn}" = ST_Buffer("${column}", ${distance})`, (0, mergeOptions_js_1.default)(this, {
|
|
4325
4442
|
table: this.name,
|
|
4326
4443
|
method: "buffer()",
|
|
4327
4444
|
parameters: { column, newColumn, distance },
|
|
@@ -4407,7 +4524,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4407
4524
|
if (this.projections[column1] !== this.projections[column2]) {
|
|
4408
4525
|
throw new Error(`${column1} and ${column2} don't have the same projection.\n${column1}: ${this.projections[column1]}\n${column2}: ${this.projections[column2]}`);
|
|
4409
4526
|
}
|
|
4410
|
-
await (0, queryDB_js_1.default)(this,
|
|
4527
|
+
await (0, queryDB_js_1.default)(this, (await this.getColumns()).includes(newColumn)
|
|
4528
|
+
? `INSTALL spatial; LOAD spatial; UPDATE "${this.name}" SET "${newColumn}" = ST_Intersection("${column1}", "${column2}")`
|
|
4529
|
+
: `INSTALL spatial; LOAD spatial; ALTER TABLE "${this.name}" ADD "${newColumn}" GEOMETRY; UPDATE "${this.name}" SET "${newColumn}" = ST_Intersection("${column1}", "${column2}")`, (0, mergeOptions_js_1.default)(this, {
|
|
4411
4530
|
table: this.name,
|
|
4412
4531
|
method: "intersection()",
|
|
4413
4532
|
parameters: { column1, column2, newColumn },
|
|
@@ -4532,7 +4651,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4532
4651
|
if (this.projections[column1] !== this.projections[column2]) {
|
|
4533
4652
|
throw new Error(`${column1} and ${column2} don't have the same projection.\n${column1}: ${this.projections[column1]}\n${column2}: ${this.projections[column2]}`);
|
|
4534
4653
|
}
|
|
4535
|
-
await (0, queryDB_js_1.default)(this,
|
|
4654
|
+
await (0, queryDB_js_1.default)(this, (await this.getColumns()).includes(newColumn)
|
|
4655
|
+
? `INSTALL spatial; LOAD spatial; UPDATE "${this.name}" SET "${newColumn}" = ST_Union("${column1}", "${column2}")`
|
|
4656
|
+
: `INSTALL spatial; LOAD spatial; ALTER TABLE "${this.name}" ADD "${newColumn}" GEOMETRY; UPDATE "${this.name}" SET "${newColumn}" = ST_Union("${column1}", "${column2}")`, (0, mergeOptions_js_1.default)(this, {
|
|
4536
4657
|
table: this.name,
|
|
4537
4658
|
method: "union()",
|
|
4538
4659
|
parameters: { column1, column2, newColumn },
|
|
@@ -4623,7 +4744,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4623
4744
|
const column = typeof options.column === "string"
|
|
4624
4745
|
? options.column
|
|
4625
4746
|
: await (0, findGeoColumn_js_1.default)(this);
|
|
4626
|
-
await (0, queryDB_js_1.default)(this,
|
|
4747
|
+
await (0, queryDB_js_1.default)(this, (await this.getColumns()).includes(newColumn)
|
|
4748
|
+
? `INSTALL spatial; LOAD spatial; UPDATE "${this.name}" SET "${newColumn}" = ST_Centroid("${column}")`
|
|
4749
|
+
: `INSTALL spatial; LOAD spatial; ALTER TABLE "${this.name}" ADD "${newColumn}" GEOMETRY; UPDATE "${this.name}" SET "${newColumn}" = ST_Centroid("${column}")`, (0, mergeOptions_js_1.default)(this, {
|
|
4627
4750
|
table: this.name,
|
|
4628
4751
|
method: "centroid()",
|
|
4629
4752
|
parameters: { column, newColumn },
|
|
@@ -4908,6 +5031,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4908
5031
|
* ```
|
|
4909
5032
|
*/
|
|
4910
5033
|
async writeData(file, options = {}) {
|
|
5034
|
+
if (await (0, hasGeometryColumn_js_1.default)(this)) {
|
|
5035
|
+
throw new Error("Table contains geometry columns. Use writeGeoData() instead.");
|
|
5036
|
+
}
|
|
4911
5037
|
(0, createDirectory_js_1.default)(file);
|
|
4912
5038
|
const extension = (0, getExtension_js_1.default)(file);
|
|
4913
5039
|
if (options.dataAsArrays) {
|
|
@@ -4922,12 +5048,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4922
5048
|
}
|
|
4923
5049
|
}
|
|
4924
5050
|
/**
|
|
4925
|
-
* Writes the table's geospatial data to a file in GeoJSON or
|
|
5051
|
+
* Writes the table's geospatial data to a file in GeoJSON, GeoParquet, or Shapefile format.
|
|
4926
5052
|
* If the specified path does not exist, it will be created.
|
|
4927
5053
|
*
|
|
4928
5054
|
* For GeoJSON files (`.geojson` or `.json`), if the projection is WGS84 or EPSG:4326 (`[latitude, longitude]` axis order), the coordinates will be flipped to follow the RFC7946 standard (`[longitude, latitude]` axis order) in the output.
|
|
4929
5055
|
*
|
|
4930
|
-
* @param file - The absolute path to the output file (e.g., `"./output.geojson"`, `"./output.geoparquet"`).
|
|
5056
|
+
* @param file - The absolute path to the output file (e.g., `"./output.geojson"`, `"./output.geoparquet"`, `"./shapefile-folder/output.shp"`).
|
|
4931
5057
|
* @param options - An optional object with configuration options:
|
|
4932
5058
|
* @param options.precision - For GeoJSON, the maximum number of figures after the decimal separator to write in coordinates. Defaults to `undefined` (full precision).
|
|
4933
5059
|
* @param options.compression - For GeoParquet, if `true`, the output will be ZSTD compressed. Defaults to `false`.
|
|
@@ -4951,6 +5077,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4951
5077
|
*
|
|
4952
5078
|
* @example
|
|
4953
5079
|
* ```ts
|
|
5080
|
+
* // Write geospatial data to a Shapefile with all relevant files in the same folder
|
|
5081
|
+
* await table.writeGeoData("./shapefile-folder/output.shp");
|
|
5082
|
+
* ```
|
|
5083
|
+
*
|
|
5084
|
+
* @example
|
|
5085
|
+
* ```ts
|
|
4954
5086
|
* // Write GeoJSON with specific precision and metadata
|
|
4955
5087
|
* await table.writeGeoData("./output_high_precision.geojson", {
|
|
4956
5088
|
* precision: 6,
|
|
@@ -4959,71 +5091,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4959
5091
|
* ```
|
|
4960
5092
|
*/
|
|
4961
5093
|
async writeGeoData(file, options = {}) {
|
|
4962
|
-
(0,
|
|
4963
|
-
const fileExtension = (0, getExtension_js_1.default)(file);
|
|
4964
|
-
if (fileExtension === "geojson" || fileExtension === "json") {
|
|
4965
|
-
let types;
|
|
4966
|
-
if (options.formatDates === true) {
|
|
4967
|
-
types = await this.getTypes();
|
|
4968
|
-
if (Object.values(types).includes("DATE") ||
|
|
4969
|
-
Object.values(types).includes("TIMESTAMP")) {
|
|
4970
|
-
await (0, stringifyDates_js_1.default)(this, types);
|
|
4971
|
-
}
|
|
4972
|
-
}
|
|
4973
|
-
if (typeof options.compression === "boolean") {
|
|
4974
|
-
throw new Error("The compression option is not supported for writing GeoJSON files.");
|
|
4975
|
-
}
|
|
4976
|
-
const geoColumn = await (0, findGeoColumn_js_1.default)(this);
|
|
4977
|
-
const flip = (0, shouldFlipBeforeExport_js_1.default)(this.projections[geoColumn]);
|
|
4978
|
-
if (flip) {
|
|
4979
|
-
await this.flipCoordinates(geoColumn);
|
|
4980
|
-
await (0, queryDB_js_1.default)(this, (0, writeGeoDataQuery_js_1.default)(this.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(this, {
|
|
4981
|
-
table: this.name,
|
|
4982
|
-
method: "writeGeoData()",
|
|
4983
|
-
parameters: { file, options },
|
|
4984
|
-
}));
|
|
4985
|
-
await this.flipCoordinates(geoColumn);
|
|
4986
|
-
}
|
|
4987
|
-
else {
|
|
4988
|
-
await (0, queryDB_js_1.default)(this, (0, writeGeoDataQuery_js_1.default)(this.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(this, {
|
|
4989
|
-
table: this.name,
|
|
4990
|
-
method: "writeGeoData()",
|
|
4991
|
-
parameters: { file, options },
|
|
4992
|
-
}));
|
|
4993
|
-
}
|
|
4994
|
-
if (options.metadata) {
|
|
4995
|
-
const fileData = JSON.parse((0, node_fs_2.readFileSync)(file, "utf-8"));
|
|
4996
|
-
fileData.metadata = options.metadata;
|
|
4997
|
-
(0, node_fs_2.writeFileSync)(file, JSON.stringify(fileData));
|
|
4998
|
-
}
|
|
4999
|
-
if (options.rewind) {
|
|
5000
|
-
const fileData = JSON.parse((0, node_fs_2.readFileSync)(file, "utf-8"));
|
|
5001
|
-
const fileRewinded = (0, rewind_js_1.default)(fileData);
|
|
5002
|
-
(0, node_fs_2.writeFileSync)(file, JSON.stringify(fileRewinded));
|
|
5003
|
-
}
|
|
5004
|
-
if (types && (Object.values(types).includes("DATE") ||
|
|
5005
|
-
Object.values(types).includes("TIMESTAMP"))) {
|
|
5006
|
-
await (0, stringifyDatesInvert_js_1.default)(this, types);
|
|
5007
|
-
}
|
|
5008
|
-
}
|
|
5009
|
-
else if (fileExtension === "geoparquet") {
|
|
5010
|
-
if (typeof options.precision === "number") {
|
|
5011
|
-
throw new Error("The precision option is not supported for writing PARQUET files. Use the .reducePrecision() method.");
|
|
5012
|
-
}
|
|
5013
|
-
if (typeof options.rewind === "boolean") {
|
|
5014
|
-
throw new Error("The rewind option is not supported for writing PARQUET files.");
|
|
5015
|
-
}
|
|
5016
|
-
await (0, queryDB_js_1.default)(this, `COPY "${this.name}" TO '${(0, cleanPath_js_1.default)(file)}' WITH (FORMAT PARQUET${options.compression === true ? ", COMPRESSION 'zstd'" : ""}, KV_METADATA {
|
|
5017
|
-
projections: '${JSON.stringify(this.projections)}'
|
|
5018
|
-
});`, (0, mergeOptions_js_1.default)(this, {
|
|
5019
|
-
table: this.name,
|
|
5020
|
-
method: "writeGeoData()",
|
|
5021
|
-
parameters: { file, options },
|
|
5022
|
-
}));
|
|
5023
|
-
}
|
|
5024
|
-
else {
|
|
5025
|
-
throw new Error(`Unknown extension ${fileExtension}`);
|
|
5026
|
-
}
|
|
5094
|
+
await (0, writeGeoData_js_1.default)(this, file, options);
|
|
5027
5095
|
}
|
|
5028
5096
|
/**
|
|
5029
5097
|
* Caches the results of computations in `./.sda-cache`.
|
|
@@ -5231,10 +5299,10 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5231
5299
|
async logDescription() {
|
|
5232
5300
|
if (this.connection === undefined ||
|
|
5233
5301
|
!(await this.sdb.hasTable(this.name))) {
|
|
5234
|
-
console.log(`\
|
|
5302
|
+
console.log(`\nTable ${this.name}: no data`);
|
|
5235
5303
|
}
|
|
5236
5304
|
else {
|
|
5237
|
-
console.log(`\
|
|
5305
|
+
console.log(`\nTable ${this.name}:`);
|
|
5238
5306
|
console.table(await (0, getDescription_js_1.default)(this));
|
|
5239
5307
|
}
|
|
5240
5308
|
}
|
|
@@ -5251,7 +5319,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5251
5319
|
* ```
|
|
5252
5320
|
*/
|
|
5253
5321
|
async logProjections() {
|
|
5254
|
-
console.log(`\
|
|
5322
|
+
console.log(`\nTable ${this.name} projections:`);
|
|
5255
5323
|
console.log(this.projections);
|
|
5256
5324
|
return await this;
|
|
5257
5325
|
}
|
|
@@ -5268,7 +5336,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5268
5336
|
* ```
|
|
5269
5337
|
*/
|
|
5270
5338
|
async logTypes() {
|
|
5271
|
-
console.log(`\
|
|
5339
|
+
console.log(`\nTable ${this.name} types:`);
|
|
5272
5340
|
console.log(await this.getTypes());
|
|
5273
5341
|
return await this;
|
|
5274
5342
|
}
|
|
@@ -5296,7 +5364,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5296
5364
|
*/
|
|
5297
5365
|
async logUniques(column, options = {}) {
|
|
5298
5366
|
const values = await this.getUniques(column);
|
|
5299
|
-
console.log(`\
|
|
5367
|
+
console.log(`\nTable ${this.name} — unique values in ${column}:`);
|
|
5300
5368
|
if (options.stringify) {
|
|
5301
5369
|
console.log(JSON.stringify(values, null, 2));
|
|
5302
5370
|
}
|
|
@@ -6,7 +6,7 @@ async function findGeoColumn(SimpleTable) {
|
|
|
6
6
|
const types = await SimpleTable.getTypes();
|
|
7
7
|
const geometries = Object.values(types).filter((d) => d.toLowerCase() === "geometry");
|
|
8
8
|
if (geometries.length === 0) {
|
|
9
|
-
throw new Error("
|
|
9
|
+
throw new Error("Table contains no geometry columns.");
|
|
10
10
|
}
|
|
11
11
|
else if (geometries.length > 1) {
|
|
12
12
|
throw new Error("More than one column storing geometries. If the method allows to specify one, do it. Otherwise, use the selectColumns methods beforehand.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProjection.d.ts","sourceRoot":"","sources":["../../src/helpers/getProjection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAGjD,wBAA8B,aAAa,CACzC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getProjection.d.ts","sourceRoot":"","sources":["../../src/helpers/getProjection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAGjD,wBAA8B,aAAa,CACzC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,mBAiCb"}
|
|
@@ -21,6 +21,9 @@ async function getProjection(simpleDB, file) {
|
|
|
21
21
|
throw new Error("No queryResults");
|
|
22
22
|
}
|
|
23
23
|
const proj4 = queryResult[0].proj4;
|
|
24
|
+
if (proj4 === null) {
|
|
25
|
+
return "UNKNOWN";
|
|
26
|
+
}
|
|
24
27
|
if (typeof proj4 !== "string") {
|
|
25
28
|
throw new Error(`Expected proj4 to be a string, got ${typeof proj4}`);
|
|
26
29
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the table has one or more columns of type geometry.
|
|
4
|
+
*
|
|
5
|
+
* Uses `getTypes()` to inspect column types and checks for any column
|
|
6
|
+
* whose type normalizes to `"geometry"`.
|
|
7
|
+
*
|
|
8
|
+
* @param table - The SimpleTable instance to inspect.
|
|
9
|
+
* @returns `true` if at least one geometry column exists, `false` otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const hasGeo = await hasGeometryColumn(table);
|
|
14
|
+
* if (hasGeo) {
|
|
15
|
+
* console.log("This table contains geometry columns");
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export default function hasGeometryColumn(table: SimpleTable): Promise<boolean>;
|
|
20
|
+
//# sourceMappingURL=hasGeometryColumn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasGeometryColumn.d.ts","sourceRoot":"","sources":["../../src/helpers/hasGeometryColumn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAA8B,iBAAiB,CAC7C,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,OAAO,CAAC,CAGlB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = hasGeometryColumn;
|
|
4
|
+
/**
|
|
5
|
+
* Returns `true` if the table has one or more columns of type geometry.
|
|
6
|
+
*
|
|
7
|
+
* Uses `getTypes()` to inspect column types and checks for any column
|
|
8
|
+
* whose type normalizes to `"geometry"`.
|
|
9
|
+
*
|
|
10
|
+
* @param table - The SimpleTable instance to inspect.
|
|
11
|
+
* @returns `true` if at least one geometry column exists, `false` otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const hasGeo = await hasGeometryColumn(table);
|
|
16
|
+
* if (hasGeo) {
|
|
17
|
+
* console.log("This table contains geometry columns");
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
async function hasGeometryColumn(table) {
|
|
22
|
+
const types = await table.getTypes();
|
|
23
|
+
return Object.values(types).some((t) => t.toLowerCase() === "geometry");
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
|
+
export default function writeGeoData(table: SimpleTable, file: string, options?: {
|
|
3
|
+
precision?: number;
|
|
4
|
+
compression?: boolean;
|
|
5
|
+
rewind?: boolean;
|
|
6
|
+
metadata?: unknown;
|
|
7
|
+
formatDates?: boolean;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=writeGeoData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeGeoData.d.ts","sourceRoot":"","sources":["../../src/helpers/writeGeoData.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,YAAY,CACxC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;CAClB,GACL,OAAO,CAAC,IAAI,CAAC,CAqIf"}
|