@walkthru-earth/objex-utils 1.0.0 → 1.2.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.
- package/README.md +99 -0
- package/dist/index.cjs +1224 -956
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +230 -7
- package/dist/index.d.ts +230 -7
- package/dist/index.js +1202 -957
- package/dist/index.js.map +1 -1
- package/docs/README.md +102 -0
- package/docs/cog.md +303 -0
- package/docs/errors.md +34 -0
- package/docs/file-sort.md +67 -0
- package/docs/file-types.md +141 -0
- package/docs/formatting.md +192 -0
- package/docs/geometry.md +198 -0
- package/docs/local-storage.md +51 -0
- package/docs/markdown-sql.md +109 -0
- package/docs/parquet-metadata.md +133 -0
- package/docs/query-engine.md +140 -0
- package/docs/storage.md +251 -0
- package/docs/types-constants.md +173 -0
- package/package.json +9 -3
package/dist/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import '@developmentseed/epsg/all';
|
|
2
|
+
import '@developmentseed/epsg/all.csv.gz?url';
|
|
3
|
+
import '@developmentseed/geotiff';
|
|
4
|
+
import '@developmentseed/proj';
|
|
5
|
+
import 'proj4';
|
|
1
6
|
import { Field, Float64, FixedSizeList, Schema, Struct, makeData, RecordBatch, Table, List, Utf8 } from 'apache-arrow';
|
|
2
7
|
|
|
3
8
|
// ../../src/lib/constants.ts
|
|
@@ -7,7 +12,7 @@ var STORAGE_KEYS = {
|
|
|
7
12
|
QUERY_HISTORY: "obstore-explore-query-history"
|
|
8
13
|
};
|
|
9
14
|
var WGS84_CODES = /* @__PURE__ */ new Set([4326, 4979]);
|
|
10
|
-
var DEFAULT_TARGET_CRS = "
|
|
15
|
+
var DEFAULT_TARGET_CRS = "OGC:CRS84";
|
|
11
16
|
var DUCKDB_INIT_TIMEOUT_MS = 3e4;
|
|
12
17
|
var MAX_QUERY_HISTORY_ENTRIES = 200;
|
|
13
18
|
var SQL_PREVIEW_LENGTH = 120;
|
|
@@ -887,6 +892,16 @@ var EXTENSIONS = {
|
|
|
887
892
|
duckdbReadFn: null,
|
|
888
893
|
mimeType: "application/octet-stream"
|
|
889
894
|
},
|
|
895
|
+
".ducklake": {
|
|
896
|
+
icon: "Database",
|
|
897
|
+
color: "text-teal-600 dark:text-teal-400",
|
|
898
|
+
label: "DuckLake",
|
|
899
|
+
category: "database",
|
|
900
|
+
viewer: "database",
|
|
901
|
+
queryable: true,
|
|
902
|
+
duckdbReadFn: null,
|
|
903
|
+
mimeType: "application/octet-stream"
|
|
904
|
+
},
|
|
890
905
|
".sqlite": {
|
|
891
906
|
icon: "Database",
|
|
892
907
|
color: "text-sky-600 dark:text-sky-400",
|
|
@@ -1034,7 +1049,7 @@ function buildDuckDbSource(pathOrExt, url) {
|
|
|
1034
1049
|
const readFn = EXTENSIONS[ext]?.duckdbReadFn ?? "read_parquet";
|
|
1035
1050
|
return `${readFn}('${url}')`;
|
|
1036
1051
|
}
|
|
1037
|
-
var CLOUD_NATIVE_EXTS = /* @__PURE__ */ new Set([".parquet", ".geoparquet", ".gpq", ".gparquet"]);
|
|
1052
|
+
var CLOUD_NATIVE_EXTS = /* @__PURE__ */ new Set([".parquet", ".geoparquet", ".gpq", ".gparquet", ".ducklake"]);
|
|
1038
1053
|
function isCloudNativeFormat(pathOrExt) {
|
|
1039
1054
|
const ext = pathOrExt.includes(".") ? `.${pathOrExt.split(".").pop().toLowerCase()}` : "";
|
|
1040
1055
|
return CLOUD_NATIVE_EXTS.has(ext);
|
|
@@ -1057,959 +1072,6 @@ var QueryCancelledError = class extends Error {
|
|
|
1057
1072
|
}
|
|
1058
1073
|
};
|
|
1059
1074
|
|
|
1060
|
-
// ../../src/lib/storage/url-adapter.ts
|
|
1061
|
-
var UrlAdapter = class {
|
|
1062
|
-
supportsWrite = false;
|
|
1063
|
-
async read(url, offset, length, signal) {
|
|
1064
|
-
const headers = {};
|
|
1065
|
-
if (offset !== void 0 && length !== void 0) {
|
|
1066
|
-
headers.Range = `bytes=${offset}-${offset + length - 1}`;
|
|
1067
|
-
} else if (offset !== void 0) {
|
|
1068
|
-
headers.Range = `bytes=${offset}-`;
|
|
1069
|
-
}
|
|
1070
|
-
const res = await fetch(url, { headers, signal });
|
|
1071
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1072
|
-
return new Uint8Array(await res.arrayBuffer());
|
|
1073
|
-
}
|
|
1074
|
-
async head(url, signal) {
|
|
1075
|
-
const res = await fetch(url, { method: "HEAD", signal });
|
|
1076
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1077
|
-
const name = url.split("/").pop()?.split("?")[0] || "file";
|
|
1078
|
-
const ext = name.includes(".") ? name.split(".").pop().toLowerCase() : "";
|
|
1079
|
-
return {
|
|
1080
|
-
name,
|
|
1081
|
-
path: url,
|
|
1082
|
-
is_dir: false,
|
|
1083
|
-
size: Number(res.headers.get("content-length") || 0),
|
|
1084
|
-
modified: new Date(res.headers.get("last-modified") || 0).getTime(),
|
|
1085
|
-
extension: ext
|
|
1086
|
-
};
|
|
1087
|
-
}
|
|
1088
|
-
async list() {
|
|
1089
|
-
return [];
|
|
1090
|
-
}
|
|
1091
|
-
async put() {
|
|
1092
|
-
throw new Error("Write not supported for direct URL sources");
|
|
1093
|
-
}
|
|
1094
|
-
async delete() {
|
|
1095
|
-
throw new Error("Delete not supported for direct URL sources");
|
|
1096
|
-
}
|
|
1097
|
-
async deletePrefix() {
|
|
1098
|
-
throw new Error("Delete not supported for direct URL sources");
|
|
1099
|
-
}
|
|
1100
|
-
async copy() {
|
|
1101
|
-
throw new Error("Copy not supported for direct URL sources");
|
|
1102
|
-
}
|
|
1103
|
-
};
|
|
1104
|
-
|
|
1105
|
-
// ../../src/lib/utils/column-types.ts
|
|
1106
|
-
var NUMBER_TYPES = [
|
|
1107
|
-
"TINYINT",
|
|
1108
|
-
"SMALLINT",
|
|
1109
|
-
"INTEGER",
|
|
1110
|
-
"BIGINT",
|
|
1111
|
-
"HUGEINT",
|
|
1112
|
-
"UTINYINT",
|
|
1113
|
-
"USMALLINT",
|
|
1114
|
-
"UINTEGER",
|
|
1115
|
-
"UBIGINT",
|
|
1116
|
-
"FLOAT",
|
|
1117
|
-
"DOUBLE",
|
|
1118
|
-
"DECIMAL",
|
|
1119
|
-
"NUMERIC",
|
|
1120
|
-
"REAL",
|
|
1121
|
-
"INT",
|
|
1122
|
-
"INT1",
|
|
1123
|
-
"INT2",
|
|
1124
|
-
"INT4",
|
|
1125
|
-
"INT8",
|
|
1126
|
-
"SIGNED",
|
|
1127
|
-
"SHORT",
|
|
1128
|
-
"LONG"
|
|
1129
|
-
];
|
|
1130
|
-
var STRING_TYPES = ["VARCHAR", "TEXT", "STRING", "CHAR", "BPCHAR", "NAME", "UUID", "ENUM"];
|
|
1131
|
-
var DATE_TYPES = [
|
|
1132
|
-
"DATE",
|
|
1133
|
-
"TIME",
|
|
1134
|
-
"TIMESTAMP",
|
|
1135
|
-
"TIMESTAMP_S",
|
|
1136
|
-
"TIMESTAMP_MS",
|
|
1137
|
-
"TIMESTAMP_NS",
|
|
1138
|
-
"TIMESTAMP WITH TIME ZONE",
|
|
1139
|
-
"TIMESTAMPTZ",
|
|
1140
|
-
"INTERVAL",
|
|
1141
|
-
"TIMESTAMP_TZ"
|
|
1142
|
-
];
|
|
1143
|
-
var BOOLEAN_TYPES = ["BOOLEAN", "BOOL", "LOGICAL"];
|
|
1144
|
-
var GEO_TYPES = [
|
|
1145
|
-
"GEOMETRY",
|
|
1146
|
-
"POINT",
|
|
1147
|
-
"LINESTRING",
|
|
1148
|
-
"POLYGON",
|
|
1149
|
-
"MULTIPOINT",
|
|
1150
|
-
"MULTILINESTRING",
|
|
1151
|
-
"MULTIPOLYGON",
|
|
1152
|
-
"GEOMETRYCOLLECTION",
|
|
1153
|
-
"WKB_GEOMETRY"
|
|
1154
|
-
];
|
|
1155
|
-
var BINARY_TYPES = ["BLOB", "BYTEA", "BINARY", "VARBINARY"];
|
|
1156
|
-
var JSON_TYPES = ["JSON", "JSONB"];
|
|
1157
|
-
function classifyType(duckdbType) {
|
|
1158
|
-
const upper = duckdbType.toUpperCase().trim();
|
|
1159
|
-
const base = upper.replace(/\(.*\)/, "").trim();
|
|
1160
|
-
if (NUMBER_TYPES.includes(base)) return "number";
|
|
1161
|
-
if (STRING_TYPES.includes(base)) return "string";
|
|
1162
|
-
if (DATE_TYPES.includes(base)) return "date";
|
|
1163
|
-
if (BOOLEAN_TYPES.includes(base)) return "boolean";
|
|
1164
|
-
if (GEO_TYPES.includes(base)) return "geo";
|
|
1165
|
-
if (BINARY_TYPES.includes(base)) return "binary";
|
|
1166
|
-
if (JSON_TYPES.includes(base)) return "json";
|
|
1167
|
-
if (base.startsWith("STRUCT") || base.startsWith("MAP") || base.startsWith("UNION"))
|
|
1168
|
-
return "json";
|
|
1169
|
-
if (base.endsWith("[]") || base.startsWith("LIST")) return "json";
|
|
1170
|
-
if (upper.includes("INT") || upper.includes("FLOAT") || upper.includes("DOUBLE") || upper.includes("DECIMAL") || upper.includes("NUMERIC"))
|
|
1171
|
-
return "number";
|
|
1172
|
-
if (upper.includes("CHAR") || upper.includes("TEXT") || upper.includes("STRING")) return "string";
|
|
1173
|
-
if (upper.includes("TIME") || upper.includes("DATE")) return "date";
|
|
1174
|
-
if (upper.includes("BOOL")) return "boolean";
|
|
1175
|
-
if (upper.includes("GEOMETRY") || upper.includes("GEO") || upper.includes("WKB")) return "geo";
|
|
1176
|
-
if (upper.includes("BLOB") || upper.includes("BINARY")) return "binary";
|
|
1177
|
-
if (upper.includes("JSON") || upper.includes("STRUCT") || upper.includes("MAP") || upper.includes("LIST"))
|
|
1178
|
-
return "json";
|
|
1179
|
-
return "other";
|
|
1180
|
-
}
|
|
1181
|
-
var TYPE_COLORS = {
|
|
1182
|
-
number: "text-blue-500",
|
|
1183
|
-
string: "text-green-500",
|
|
1184
|
-
date: "text-amber-500",
|
|
1185
|
-
boolean: "text-purple-500",
|
|
1186
|
-
geo: "text-teal-500",
|
|
1187
|
-
binary: "text-zinc-500",
|
|
1188
|
-
json: "text-orange-500",
|
|
1189
|
-
other: "text-zinc-400"
|
|
1190
|
-
};
|
|
1191
|
-
var TYPE_BADGE_CLASSES = {
|
|
1192
|
-
number: "bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",
|
|
1193
|
-
string: "bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20",
|
|
1194
|
-
date: "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20",
|
|
1195
|
-
boolean: "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/20",
|
|
1196
|
-
geo: "bg-teal-500/10 text-teal-600 dark:text-teal-400 border-teal-500/20",
|
|
1197
|
-
binary: "bg-zinc-500/10 text-zinc-600 dark:text-zinc-400 border-zinc-500/20",
|
|
1198
|
-
json: "bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/20",
|
|
1199
|
-
other: "bg-zinc-500/10 text-zinc-500 dark:text-zinc-400 border-zinc-500/20"
|
|
1200
|
-
};
|
|
1201
|
-
var TYPE_LABELS = {
|
|
1202
|
-
number: "#",
|
|
1203
|
-
string: "Aa",
|
|
1204
|
-
date: "dt",
|
|
1205
|
-
boolean: "T/F",
|
|
1206
|
-
geo: "geo",
|
|
1207
|
-
binary: "01",
|
|
1208
|
-
json: "{}",
|
|
1209
|
-
other: "?"
|
|
1210
|
-
};
|
|
1211
|
-
function typeColor(category) {
|
|
1212
|
-
return TYPE_COLORS[category];
|
|
1213
|
-
}
|
|
1214
|
-
function typeBadgeClass(category) {
|
|
1215
|
-
return TYPE_BADGE_CLASSES[category];
|
|
1216
|
-
}
|
|
1217
|
-
function typeLabel(category) {
|
|
1218
|
-
return TYPE_LABELS[category];
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
// ../../src/lib/utils/error.ts
|
|
1222
|
-
function handleLoadError(err) {
|
|
1223
|
-
if (err instanceof DOMException && err.name === "AbortError") return null;
|
|
1224
|
-
return err instanceof Error ? err.message : String(err);
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
// ../../src/lib/utils/format.ts
|
|
1228
|
-
function formatFileSize(bytes) {
|
|
1229
|
-
if (bytes < 0) return "0 B";
|
|
1230
|
-
if (bytes === 0) return "0 B";
|
|
1231
|
-
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
1232
|
-
const base = 1024;
|
|
1233
|
-
const exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(base)), units.length - 1);
|
|
1234
|
-
const value = bytes / base ** exponent;
|
|
1235
|
-
if (exponent === 0) return `${bytes} B`;
|
|
1236
|
-
return `${value.toFixed(1)} ${units[exponent]}`;
|
|
1237
|
-
}
|
|
1238
|
-
function formatDate(timestamp) {
|
|
1239
|
-
if (!timestamp || timestamp <= 0 || !Number.isFinite(timestamp)) return "--";
|
|
1240
|
-
const date = new Date(timestamp);
|
|
1241
|
-
const now = Date.now();
|
|
1242
|
-
const diffMs = now - timestamp;
|
|
1243
|
-
const diffSeconds = Math.floor(diffMs / 1e3);
|
|
1244
|
-
const diffMinutes = Math.floor(diffSeconds / 60);
|
|
1245
|
-
const diffHours = Math.floor(diffMinutes / 60);
|
|
1246
|
-
const diffDays = Math.floor(diffHours / 24);
|
|
1247
|
-
if (diffSeconds < 60) return "Just now";
|
|
1248
|
-
if (diffMinutes < 60) return `${diffMinutes}m ago`;
|
|
1249
|
-
if (diffHours < 24) return `${diffHours}h ago`;
|
|
1250
|
-
if (diffDays < 7) return `${diffDays}d ago`;
|
|
1251
|
-
return date.toLocaleDateString(void 0, {
|
|
1252
|
-
year: "numeric",
|
|
1253
|
-
month: "short",
|
|
1254
|
-
day: "numeric"
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
function getFileExtension(filename) {
|
|
1258
|
-
const lastDot = filename.lastIndexOf(".");
|
|
1259
|
-
if (lastDot <= 0) return "";
|
|
1260
|
-
return filename.slice(lastDot).toLowerCase();
|
|
1261
|
-
}
|
|
1262
|
-
function jsonReplacerBigInt(_key, value) {
|
|
1263
|
-
return typeof value === "bigint" ? value.toString() : value;
|
|
1264
|
-
}
|
|
1265
|
-
function formatValue(value) {
|
|
1266
|
-
if (value === null || value === void 0) return "NULL";
|
|
1267
|
-
if (value instanceof Date) return value.toISOString();
|
|
1268
|
-
if (typeof value === "bigint") return value.toString();
|
|
1269
|
-
if (typeof value === "object") return JSON.stringify(value, jsonReplacerBigInt);
|
|
1270
|
-
return String(value);
|
|
1271
|
-
}
|
|
1272
|
-
function normalizeGeomType(raw) {
|
|
1273
|
-
const s = raw.toUpperCase().replace(/\s+/g, "");
|
|
1274
|
-
if (s === "POINT") return "point";
|
|
1275
|
-
if (s === "LINESTRING") return "linestring";
|
|
1276
|
-
if (s === "POLYGON") return "polygon";
|
|
1277
|
-
if (s === "MULTIPOINT") return "multipoint";
|
|
1278
|
-
if (s === "MULTILINESTRING") return "multilinestring";
|
|
1279
|
-
if (s === "MULTIPOLYGON") return "multipolygon";
|
|
1280
|
-
return "polygon";
|
|
1281
|
-
}
|
|
1282
|
-
var EXTENSION_NAMES = {
|
|
1283
|
-
point: "geoarrow.point",
|
|
1284
|
-
linestring: "geoarrow.linestring",
|
|
1285
|
-
polygon: "geoarrow.polygon",
|
|
1286
|
-
multipoint: "geoarrow.multipoint",
|
|
1287
|
-
multilinestring: "geoarrow.multilinestring",
|
|
1288
|
-
multipolygon: "geoarrow.multipolygon"
|
|
1289
|
-
};
|
|
1290
|
-
function readWkbHeader(wkb) {
|
|
1291
|
-
if (wkb.length < 5) return null;
|
|
1292
|
-
const le = wkb[0] === 1;
|
|
1293
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1294
|
-
const rawType = dv.getUint32(1, le);
|
|
1295
|
-
let headerSize = 5;
|
|
1296
|
-
if ((rawType & 536870912) !== 0) headerSize += 4;
|
|
1297
|
-
const ewkbZ = (rawType & 2147483648) !== 0;
|
|
1298
|
-
const ewkbM = (rawType & 1073741824) !== 0;
|
|
1299
|
-
let type = rawType & 268435455;
|
|
1300
|
-
let isoZ = false;
|
|
1301
|
-
let isoM = false;
|
|
1302
|
-
if (type > 3e3) {
|
|
1303
|
-
isoZ = true;
|
|
1304
|
-
isoM = true;
|
|
1305
|
-
type -= 3e3;
|
|
1306
|
-
} else if (type > 2e3) {
|
|
1307
|
-
isoM = true;
|
|
1308
|
-
type -= 2e3;
|
|
1309
|
-
} else if (type > 1e3) {
|
|
1310
|
-
isoZ = true;
|
|
1311
|
-
type -= 1e3;
|
|
1312
|
-
}
|
|
1313
|
-
const dims = (ewkbZ || isoZ ? 1 : 0) + (ewkbM || isoM ? 1 : 0);
|
|
1314
|
-
const coordStride = (2 + dims) * 8;
|
|
1315
|
-
return { type, le, coordStride, dataOffset: headerSize };
|
|
1316
|
-
}
|
|
1317
|
-
function classifyWkbType(wkb) {
|
|
1318
|
-
const h = readWkbHeader(wkb);
|
|
1319
|
-
if (!h) return null;
|
|
1320
|
-
switch (h.type) {
|
|
1321
|
-
case 1:
|
|
1322
|
-
return "point";
|
|
1323
|
-
case 2:
|
|
1324
|
-
return "linestring";
|
|
1325
|
-
case 3:
|
|
1326
|
-
return "polygon";
|
|
1327
|
-
case 4:
|
|
1328
|
-
return "multipoint";
|
|
1329
|
-
case 5:
|
|
1330
|
-
return "multilinestring";
|
|
1331
|
-
case 6:
|
|
1332
|
-
return "multipolygon";
|
|
1333
|
-
default:
|
|
1334
|
-
return null;
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
function newBounds() {
|
|
1338
|
-
return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
1339
|
-
}
|
|
1340
|
-
function expandBounds(b, x, y) {
|
|
1341
|
-
if (Number.isNaN(x) || Number.isNaN(y)) return;
|
|
1342
|
-
if (x < b.minX) b.minX = x;
|
|
1343
|
-
if (y < b.minY) b.minY = y;
|
|
1344
|
-
if (x > b.maxX) b.maxX = x;
|
|
1345
|
-
if (y > b.maxY) b.maxY = y;
|
|
1346
|
-
}
|
|
1347
|
-
var coordField = new Field("xy", new Float64());
|
|
1348
|
-
var coordType = new FixedSizeList(2, coordField);
|
|
1349
|
-
function makeCoordData(coords, numPoints) {
|
|
1350
|
-
const floatData = makeData({ type: new Float64(), length: coords.length, data: coords });
|
|
1351
|
-
return makeData({ type: coordType, length: numPoints, nullCount: 0, child: floatData });
|
|
1352
|
-
}
|
|
1353
|
-
function buildPointData(wkbs, b) {
|
|
1354
|
-
const n = wkbs.length;
|
|
1355
|
-
const coords = new Float64Array(n * 2);
|
|
1356
|
-
for (let i = 0; i < n; i++) {
|
|
1357
|
-
const wkb = wkbs[i];
|
|
1358
|
-
const h = readWkbHeader(wkb);
|
|
1359
|
-
if (!h || h.type !== 1) {
|
|
1360
|
-
coords[i * 2] = 0;
|
|
1361
|
-
coords[i * 2 + 1] = 0;
|
|
1362
|
-
continue;
|
|
1363
|
-
}
|
|
1364
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1365
|
-
const x = dv.getFloat64(h.dataOffset, h.le);
|
|
1366
|
-
const y = dv.getFloat64(h.dataOffset + 8, h.le);
|
|
1367
|
-
coords[i * 2] = x;
|
|
1368
|
-
coords[i * 2 + 1] = y;
|
|
1369
|
-
expandBounds(b, x, y);
|
|
1370
|
-
}
|
|
1371
|
-
return makeCoordData(coords, n);
|
|
1372
|
-
}
|
|
1373
|
-
function buildLineStringData(wkbs, b) {
|
|
1374
|
-
const n = wkbs.length;
|
|
1375
|
-
const geomOffsets = new Int32Array(n + 1);
|
|
1376
|
-
let totalCoords = 0;
|
|
1377
|
-
for (let i = 0; i < n; i++) {
|
|
1378
|
-
geomOffsets[i] = totalCoords;
|
|
1379
|
-
const h = readWkbHeader(wkbs[i]);
|
|
1380
|
-
if (!h || h.type !== 2) continue;
|
|
1381
|
-
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1382
|
-
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1383
|
-
totalCoords += numPts;
|
|
1384
|
-
}
|
|
1385
|
-
geomOffsets[n] = totalCoords;
|
|
1386
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1387
|
-
let ci = 0;
|
|
1388
|
-
for (const wkb of wkbs) {
|
|
1389
|
-
const h = readWkbHeader(wkb);
|
|
1390
|
-
if (!h || h.type !== 2) continue;
|
|
1391
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1392
|
-
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1393
|
-
let off = h.dataOffset + 4;
|
|
1394
|
-
for (let j = 0; j < numPts; j++) {
|
|
1395
|
-
const x = dv.getFloat64(off, h.le);
|
|
1396
|
-
const y = dv.getFloat64(off + 8, h.le);
|
|
1397
|
-
coords[ci++] = x;
|
|
1398
|
-
coords[ci++] = y;
|
|
1399
|
-
expandBounds(b, x, y);
|
|
1400
|
-
off += h.coordStride;
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
const fslData = makeCoordData(coords, totalCoords);
|
|
1404
|
-
const listType = new List(new Field("vertices", coordType));
|
|
1405
|
-
return makeData({
|
|
1406
|
-
type: listType,
|
|
1407
|
-
length: n,
|
|
1408
|
-
nullCount: 0,
|
|
1409
|
-
valueOffsets: geomOffsets,
|
|
1410
|
-
child: fslData
|
|
1411
|
-
});
|
|
1412
|
-
}
|
|
1413
|
-
function buildPolygonData(wkbs, b) {
|
|
1414
|
-
const n = wkbs.length;
|
|
1415
|
-
const geomOffsets = new Int32Array(n + 1);
|
|
1416
|
-
let totalRings = 0;
|
|
1417
|
-
let totalCoords = 0;
|
|
1418
|
-
for (let i = 0; i < n; i++) {
|
|
1419
|
-
geomOffsets[i] = totalRings;
|
|
1420
|
-
const h = readWkbHeader(wkbs[i]);
|
|
1421
|
-
if (!h || h.type !== 3) continue;
|
|
1422
|
-
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1423
|
-
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1424
|
-
let off = h.dataOffset + 4;
|
|
1425
|
-
for (let r = 0; r < numRings; r++) {
|
|
1426
|
-
const numPts = dv.getUint32(off, h.le);
|
|
1427
|
-
off += 4 + numPts * h.coordStride;
|
|
1428
|
-
totalCoords += numPts;
|
|
1429
|
-
totalRings++;
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
geomOffsets[n] = totalRings;
|
|
1433
|
-
const ringOffsets = new Int32Array(totalRings + 1);
|
|
1434
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1435
|
-
let ri = 0;
|
|
1436
|
-
let ci = 0;
|
|
1437
|
-
for (const wkb of wkbs) {
|
|
1438
|
-
const h = readWkbHeader(wkb);
|
|
1439
|
-
if (!h || h.type !== 3) continue;
|
|
1440
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1441
|
-
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1442
|
-
let off = h.dataOffset + 4;
|
|
1443
|
-
for (let r = 0; r < numRings; r++) {
|
|
1444
|
-
ringOffsets[ri++] = ci >> 1;
|
|
1445
|
-
const numPts = dv.getUint32(off, h.le);
|
|
1446
|
-
off += 4;
|
|
1447
|
-
for (let j = 0; j < numPts; j++) {
|
|
1448
|
-
const x = dv.getFloat64(off, h.le);
|
|
1449
|
-
const y = dv.getFloat64(off + 8, h.le);
|
|
1450
|
-
coords[ci++] = x;
|
|
1451
|
-
coords[ci++] = y;
|
|
1452
|
-
expandBounds(b, x, y);
|
|
1453
|
-
off += h.coordStride;
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
ringOffsets[totalRings] = ci >> 1;
|
|
1458
|
-
const coordCount = ci >> 1;
|
|
1459
|
-
const fslData = makeCoordData(coords, coordCount);
|
|
1460
|
-
const ringListType = new List(new Field("vertices", coordType));
|
|
1461
|
-
const ringListData = makeData({
|
|
1462
|
-
type: ringListType,
|
|
1463
|
-
length: totalRings,
|
|
1464
|
-
nullCount: 0,
|
|
1465
|
-
valueOffsets: ringOffsets,
|
|
1466
|
-
child: fslData
|
|
1467
|
-
});
|
|
1468
|
-
const polyType = new List(new Field("rings", ringListType));
|
|
1469
|
-
return makeData({
|
|
1470
|
-
type: polyType,
|
|
1471
|
-
length: n,
|
|
1472
|
-
nullCount: 0,
|
|
1473
|
-
valueOffsets: geomOffsets,
|
|
1474
|
-
child: ringListData
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
function buildMultiPointData(wkbs, b) {
|
|
1478
|
-
const n = wkbs.length;
|
|
1479
|
-
const geomOffsets = new Int32Array(n + 1);
|
|
1480
|
-
let totalCoords = 0;
|
|
1481
|
-
for (let i = 0; i < n; i++) {
|
|
1482
|
-
geomOffsets[i] = totalCoords;
|
|
1483
|
-
const h = readWkbHeader(wkbs[i]);
|
|
1484
|
-
if (!h || h.type !== 4) continue;
|
|
1485
|
-
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1486
|
-
totalCoords += dv.getUint32(h.dataOffset, h.le);
|
|
1487
|
-
}
|
|
1488
|
-
geomOffsets[n] = totalCoords;
|
|
1489
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1490
|
-
let ci = 0;
|
|
1491
|
-
for (const wkb of wkbs) {
|
|
1492
|
-
const h = readWkbHeader(wkb);
|
|
1493
|
-
if (!h || h.type !== 4) continue;
|
|
1494
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1495
|
-
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1496
|
-
let off = h.dataOffset + 4;
|
|
1497
|
-
for (let j = 0; j < numPts; j++) {
|
|
1498
|
-
const innerH = readWkbHeader(
|
|
1499
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1500
|
-
);
|
|
1501
|
-
if (innerH) {
|
|
1502
|
-
const x = dv.getFloat64(off + innerH.dataOffset, innerH.le);
|
|
1503
|
-
const y = dv.getFloat64(off + innerH.dataOffset + 8, innerH.le);
|
|
1504
|
-
coords[ci++] = x;
|
|
1505
|
-
coords[ci++] = y;
|
|
1506
|
-
expandBounds(b, x, y);
|
|
1507
|
-
off += innerH.dataOffset + innerH.coordStride;
|
|
1508
|
-
} else {
|
|
1509
|
-
coords[ci++] = 0;
|
|
1510
|
-
coords[ci++] = 0;
|
|
1511
|
-
off += 21;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
const fslData = makeCoordData(coords, totalCoords);
|
|
1516
|
-
const listType = new List(new Field("vertices", coordType));
|
|
1517
|
-
return makeData({
|
|
1518
|
-
type: listType,
|
|
1519
|
-
length: n,
|
|
1520
|
-
nullCount: 0,
|
|
1521
|
-
valueOffsets: geomOffsets,
|
|
1522
|
-
child: fslData
|
|
1523
|
-
});
|
|
1524
|
-
}
|
|
1525
|
-
function buildMultiLineStringData(wkbs, b) {
|
|
1526
|
-
const n = wkbs.length;
|
|
1527
|
-
const geomOffsetsArr = [0];
|
|
1528
|
-
let totalLines = 0;
|
|
1529
|
-
let totalCoords = 0;
|
|
1530
|
-
for (const wkb of wkbs) {
|
|
1531
|
-
const h = readWkbHeader(wkb);
|
|
1532
|
-
if (!h || h.type !== 5) {
|
|
1533
|
-
geomOffsetsArr.push(totalLines);
|
|
1534
|
-
continue;
|
|
1535
|
-
}
|
|
1536
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1537
|
-
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1538
|
-
let off = h.dataOffset + 4;
|
|
1539
|
-
for (let l = 0; l < numLines; l++) {
|
|
1540
|
-
const innerH = readWkbHeader(
|
|
1541
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1542
|
-
);
|
|
1543
|
-
if (!innerH) break;
|
|
1544
|
-
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1545
|
-
const numPts = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1546
|
-
totalCoords += numPts;
|
|
1547
|
-
off += innerH.dataOffset + 4 + numPts * innerH.coordStride;
|
|
1548
|
-
totalLines++;
|
|
1549
|
-
}
|
|
1550
|
-
geomOffsetsArr.push(totalLines);
|
|
1551
|
-
}
|
|
1552
|
-
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
1553
|
-
const lineOffsets = new Int32Array(totalLines + 1);
|
|
1554
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1555
|
-
let li = 0;
|
|
1556
|
-
let ci = 0;
|
|
1557
|
-
for (const wkb of wkbs) {
|
|
1558
|
-
const h = readWkbHeader(wkb);
|
|
1559
|
-
if (!h || h.type !== 5) continue;
|
|
1560
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1561
|
-
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1562
|
-
let off = h.dataOffset + 4;
|
|
1563
|
-
for (let l = 0; l < numLines; l++) {
|
|
1564
|
-
lineOffsets[li++] = ci >> 1;
|
|
1565
|
-
const innerH = readWkbHeader(
|
|
1566
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1567
|
-
);
|
|
1568
|
-
if (!innerH) break;
|
|
1569
|
-
const numPts = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off).getUint32(
|
|
1570
|
-
innerH.dataOffset,
|
|
1571
|
-
innerH.le
|
|
1572
|
-
);
|
|
1573
|
-
let ptOff = off + innerH.dataOffset + 4;
|
|
1574
|
-
for (let j = 0; j < numPts; j++) {
|
|
1575
|
-
const x = dv.getFloat64(ptOff, innerH.le);
|
|
1576
|
-
const y = dv.getFloat64(ptOff + 8, innerH.le);
|
|
1577
|
-
coords[ci++] = x;
|
|
1578
|
-
coords[ci++] = y;
|
|
1579
|
-
expandBounds(b, x, y);
|
|
1580
|
-
ptOff += innerH.coordStride;
|
|
1581
|
-
}
|
|
1582
|
-
off = ptOff;
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
lineOffsets[totalLines] = ci >> 1;
|
|
1586
|
-
const fslData = makeCoordData(coords, ci >> 1);
|
|
1587
|
-
const lineListType = new List(new Field("vertices", coordType));
|
|
1588
|
-
const lineListData = makeData({
|
|
1589
|
-
type: lineListType,
|
|
1590
|
-
length: totalLines,
|
|
1591
|
-
nullCount: 0,
|
|
1592
|
-
valueOffsets: lineOffsets,
|
|
1593
|
-
child: fslData
|
|
1594
|
-
});
|
|
1595
|
-
const multiLineType = new List(new Field("lines", lineListType));
|
|
1596
|
-
return makeData({
|
|
1597
|
-
type: multiLineType,
|
|
1598
|
-
length: n,
|
|
1599
|
-
nullCount: 0,
|
|
1600
|
-
valueOffsets: geomOffsets,
|
|
1601
|
-
child: lineListData
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
function buildMultiPolygonData(wkbs, b) {
|
|
1605
|
-
const n = wkbs.length;
|
|
1606
|
-
const geomOffsetsArr = [0];
|
|
1607
|
-
let totalPolys = 0;
|
|
1608
|
-
let totalRings = 0;
|
|
1609
|
-
let totalCoords = 0;
|
|
1610
|
-
for (const wkb of wkbs) {
|
|
1611
|
-
const h = readWkbHeader(wkb);
|
|
1612
|
-
if (!h || h.type !== 6) {
|
|
1613
|
-
geomOffsetsArr.push(totalPolys);
|
|
1614
|
-
continue;
|
|
1615
|
-
}
|
|
1616
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1617
|
-
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
1618
|
-
let off = h.dataOffset + 4;
|
|
1619
|
-
for (let p = 0; p < numPolys; p++) {
|
|
1620
|
-
const innerH = readWkbHeader(
|
|
1621
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1622
|
-
);
|
|
1623
|
-
if (!innerH) break;
|
|
1624
|
-
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1625
|
-
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1626
|
-
let ringOff = innerH.dataOffset + 4;
|
|
1627
|
-
for (let r = 0; r < numRings; r++) {
|
|
1628
|
-
const numPts = innerDv.getUint32(ringOff, innerH.le);
|
|
1629
|
-
ringOff += 4 + numPts * innerH.coordStride;
|
|
1630
|
-
totalCoords += numPts;
|
|
1631
|
-
totalRings++;
|
|
1632
|
-
}
|
|
1633
|
-
off += ringOff;
|
|
1634
|
-
totalPolys++;
|
|
1635
|
-
}
|
|
1636
|
-
geomOffsetsArr.push(totalPolys);
|
|
1637
|
-
}
|
|
1638
|
-
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
1639
|
-
const polyOffsets = new Int32Array(totalPolys + 1);
|
|
1640
|
-
const ringOffsets = new Int32Array(totalRings + 1);
|
|
1641
|
-
const coords = new Float64Array(totalCoords * 2);
|
|
1642
|
-
let pi = 0;
|
|
1643
|
-
let ri = 0;
|
|
1644
|
-
let ci = 0;
|
|
1645
|
-
for (const wkb of wkbs) {
|
|
1646
|
-
const h = readWkbHeader(wkb);
|
|
1647
|
-
if (!h || h.type !== 6) continue;
|
|
1648
|
-
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1649
|
-
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
1650
|
-
let off = h.dataOffset + 4;
|
|
1651
|
-
for (let p = 0; p < numPolys; p++) {
|
|
1652
|
-
polyOffsets[pi++] = ri;
|
|
1653
|
-
const innerH = readWkbHeader(
|
|
1654
|
-
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1655
|
-
);
|
|
1656
|
-
if (!innerH) break;
|
|
1657
|
-
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1658
|
-
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1659
|
-
let ringOff = off + innerH.dataOffset + 4;
|
|
1660
|
-
for (let r = 0; r < numRings; r++) {
|
|
1661
|
-
ringOffsets[ri++] = ci >> 1;
|
|
1662
|
-
const numPts = dv.getUint32(ringOff, innerH.le);
|
|
1663
|
-
ringOff += 4;
|
|
1664
|
-
for (let j = 0; j < numPts; j++) {
|
|
1665
|
-
const x = dv.getFloat64(ringOff, innerH.le);
|
|
1666
|
-
const y = dv.getFloat64(ringOff + 8, innerH.le);
|
|
1667
|
-
coords[ci++] = x;
|
|
1668
|
-
coords[ci++] = y;
|
|
1669
|
-
expandBounds(b, x, y);
|
|
1670
|
-
ringOff += innerH.coordStride;
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
off = ringOff;
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
polyOffsets[totalPolys] = ri;
|
|
1677
|
-
ringOffsets[totalRings] = ci >> 1;
|
|
1678
|
-
const fslData = makeCoordData(coords, ci >> 1);
|
|
1679
|
-
const ringListType = new List(new Field("vertices", coordType));
|
|
1680
|
-
const ringListData = makeData({
|
|
1681
|
-
type: ringListType,
|
|
1682
|
-
length: totalRings,
|
|
1683
|
-
nullCount: 0,
|
|
1684
|
-
valueOffsets: ringOffsets,
|
|
1685
|
-
child: fslData
|
|
1686
|
-
});
|
|
1687
|
-
const polyListType = new List(new Field("rings", ringListType));
|
|
1688
|
-
const polyListData = makeData({
|
|
1689
|
-
type: polyListType,
|
|
1690
|
-
length: totalPolys,
|
|
1691
|
-
nullCount: 0,
|
|
1692
|
-
valueOffsets: polyOffsets,
|
|
1693
|
-
child: ringListData
|
|
1694
|
-
});
|
|
1695
|
-
const multiPolyType = new List(new Field("polygons", polyListType));
|
|
1696
|
-
return makeData({
|
|
1697
|
-
type: multiPolyType,
|
|
1698
|
-
length: n,
|
|
1699
|
-
nullCount: 0,
|
|
1700
|
-
valueOffsets: geomOffsets,
|
|
1701
|
-
child: polyListData
|
|
1702
|
-
});
|
|
1703
|
-
}
|
|
1704
|
-
function buildAttributeColumns(indices, attributes) {
|
|
1705
|
-
const n = indices.length;
|
|
1706
|
-
const fields = [];
|
|
1707
|
-
const dataArr = [];
|
|
1708
|
-
for (const [name, col] of attributes) {
|
|
1709
|
-
const { values } = col;
|
|
1710
|
-
let isNumeric = true;
|
|
1711
|
-
const sampleEnd = Math.min(n, 100);
|
|
1712
|
-
for (let i = 0; i < sampleEnd; i++) {
|
|
1713
|
-
if (values[indices[i]] != null && typeof values[indices[i]] !== "number") {
|
|
1714
|
-
isNumeric = false;
|
|
1715
|
-
break;
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
if (isNumeric) {
|
|
1719
|
-
const arr = new Float64Array(n);
|
|
1720
|
-
for (let i = 0; i < n; i++) arr[i] = values[indices[i]] ?? NaN;
|
|
1721
|
-
const data = makeData({ type: new Float64(), length: n, data: arr });
|
|
1722
|
-
fields.push(new Field(name, new Float64(), true));
|
|
1723
|
-
dataArr.push(data);
|
|
1724
|
-
} else {
|
|
1725
|
-
const encoder = new TextEncoder();
|
|
1726
|
-
const offsets = new Int32Array(n + 1);
|
|
1727
|
-
let totalBytes = 0;
|
|
1728
|
-
const strParts = [];
|
|
1729
|
-
for (let i = 0; i < n; i++) {
|
|
1730
|
-
offsets[i] = totalBytes;
|
|
1731
|
-
const s = values[indices[i]] != null ? String(values[indices[i]]) : "";
|
|
1732
|
-
const encoded = encoder.encode(s);
|
|
1733
|
-
strParts.push(encoded);
|
|
1734
|
-
totalBytes += encoded.length;
|
|
1735
|
-
}
|
|
1736
|
-
offsets[n] = totalBytes;
|
|
1737
|
-
const valueBuffer = new Uint8Array(totalBytes);
|
|
1738
|
-
let pos = 0;
|
|
1739
|
-
for (const sv of strParts) {
|
|
1740
|
-
valueBuffer.set(sv, pos);
|
|
1741
|
-
pos += sv.length;
|
|
1742
|
-
}
|
|
1743
|
-
const data = makeData({
|
|
1744
|
-
type: new Utf8(),
|
|
1745
|
-
length: n,
|
|
1746
|
-
valueOffsets: offsets,
|
|
1747
|
-
data: valueBuffer
|
|
1748
|
-
});
|
|
1749
|
-
fields.push(new Field(name, new Utf8(), true));
|
|
1750
|
-
dataArr.push(data);
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
return { fields, data: dataArr };
|
|
1754
|
-
}
|
|
1755
|
-
function buildSingleTable(geomType, wkbs, indices, attributes, b) {
|
|
1756
|
-
const n = wkbs.length;
|
|
1757
|
-
let geomData;
|
|
1758
|
-
switch (geomType) {
|
|
1759
|
-
case "point":
|
|
1760
|
-
geomData = buildPointData(wkbs, b);
|
|
1761
|
-
break;
|
|
1762
|
-
case "linestring":
|
|
1763
|
-
geomData = buildLineStringData(wkbs, b);
|
|
1764
|
-
break;
|
|
1765
|
-
case "polygon":
|
|
1766
|
-
geomData = buildPolygonData(wkbs, b);
|
|
1767
|
-
break;
|
|
1768
|
-
case "multipoint":
|
|
1769
|
-
geomData = buildMultiPointData(wkbs, b);
|
|
1770
|
-
break;
|
|
1771
|
-
case "multilinestring":
|
|
1772
|
-
geomData = buildMultiLineStringData(wkbs, b);
|
|
1773
|
-
break;
|
|
1774
|
-
case "multipolygon":
|
|
1775
|
-
geomData = buildMultiPolygonData(wkbs, b);
|
|
1776
|
-
break;
|
|
1777
|
-
}
|
|
1778
|
-
const extensionName = EXTENSION_NAMES[geomType];
|
|
1779
|
-
const geomMetadata = /* @__PURE__ */ new Map([
|
|
1780
|
-
["ARROW:extension:name", extensionName],
|
|
1781
|
-
[
|
|
1782
|
-
"ARROW:extension:metadata",
|
|
1783
|
-
JSON.stringify({
|
|
1784
|
-
crs: {
|
|
1785
|
-
type: "name",
|
|
1786
|
-
properties: { name: "urn:ogc:def:crs:OGC:1.3:CRS84" }
|
|
1787
|
-
}
|
|
1788
|
-
})
|
|
1789
|
-
]
|
|
1790
|
-
]);
|
|
1791
|
-
const geomField = new Field("geometry", geomData.type, false, geomMetadata);
|
|
1792
|
-
const attrCols = buildAttributeColumns(indices, attributes);
|
|
1793
|
-
const fields = [geomField, ...attrCols.fields];
|
|
1794
|
-
const childrenData = [geomData, ...attrCols.data];
|
|
1795
|
-
const arrowSchema = new Schema(fields);
|
|
1796
|
-
const structType = new Struct(fields);
|
|
1797
|
-
const structData = makeData({
|
|
1798
|
-
type: structType,
|
|
1799
|
-
length: n,
|
|
1800
|
-
nullCount: 0,
|
|
1801
|
-
children: childrenData
|
|
1802
|
-
});
|
|
1803
|
-
const batch = new RecordBatch(arrowSchema, structData);
|
|
1804
|
-
const table = new Table(arrowSchema, batch);
|
|
1805
|
-
return {
|
|
1806
|
-
table,
|
|
1807
|
-
geometryType: geomType,
|
|
1808
|
-
bounds: [b.minX, b.minY, b.maxX, b.maxY],
|
|
1809
|
-
sourceIndices: indices
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1812
|
-
function buildGeoArrowTables(wkbArrays, attributes, knownGeomType) {
|
|
1813
|
-
if (wkbArrays.length === 0) return [];
|
|
1814
|
-
if (knownGeomType) {
|
|
1815
|
-
const globalBounds2 = newBounds();
|
|
1816
|
-
const indices = Array.from({ length: wkbArrays.length }, (_, i) => i);
|
|
1817
|
-
const result = buildSingleTable(knownGeomType, wkbArrays, indices, attributes, globalBounds2);
|
|
1818
|
-
return [result];
|
|
1819
|
-
}
|
|
1820
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1821
|
-
for (let i = 0; i < wkbArrays.length; i++) {
|
|
1822
|
-
const geomType = classifyWkbType(wkbArrays[i]);
|
|
1823
|
-
if (!geomType) continue;
|
|
1824
|
-
let group = groups.get(geomType);
|
|
1825
|
-
if (!group) {
|
|
1826
|
-
group = { wkbs: [], indices: [] };
|
|
1827
|
-
groups.set(geomType, group);
|
|
1828
|
-
}
|
|
1829
|
-
group.wkbs.push(wkbArrays[i]);
|
|
1830
|
-
group.indices.push(i);
|
|
1831
|
-
}
|
|
1832
|
-
if (groups.size === 0) return [];
|
|
1833
|
-
const globalBounds = newBounds();
|
|
1834
|
-
const results = [];
|
|
1835
|
-
for (const [geomType, { wkbs, indices }] of groups) {
|
|
1836
|
-
const result = buildSingleTable(geomType, wkbs, indices, attributes, globalBounds);
|
|
1837
|
-
results.push(result);
|
|
1838
|
-
}
|
|
1839
|
-
const mergedBounds = [
|
|
1840
|
-
globalBounds.minX,
|
|
1841
|
-
globalBounds.minY,
|
|
1842
|
-
globalBounds.maxX,
|
|
1843
|
-
globalBounds.maxY
|
|
1844
|
-
];
|
|
1845
|
-
for (const r of results) r.bounds = mergedBounds;
|
|
1846
|
-
return results;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
// ../../src/lib/utils/hex.ts
|
|
1850
|
-
function generateHexDump(data, bytesPerRow = 16) {
|
|
1851
|
-
const rows = [];
|
|
1852
|
-
for (let i = 0; i < data.length; i += bytesPerRow) {
|
|
1853
|
-
const slice = data.slice(i, i + bytesPerRow);
|
|
1854
|
-
const offset = i.toString(16).padStart(8, "0");
|
|
1855
|
-
const hex = [];
|
|
1856
|
-
for (let j = 0; j < bytesPerRow; j++) {
|
|
1857
|
-
if (j < slice.length) {
|
|
1858
|
-
hex.push(slice[j].toString(16).padStart(2, "0"));
|
|
1859
|
-
} else {
|
|
1860
|
-
hex.push(" ");
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
let ascii = "";
|
|
1864
|
-
for (let j = 0; j < slice.length; j++) {
|
|
1865
|
-
const byte = slice[j];
|
|
1866
|
-
ascii += byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : ".";
|
|
1867
|
-
}
|
|
1868
|
-
rows.push({ offset, hex, ascii });
|
|
1869
|
-
}
|
|
1870
|
-
return rows;
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
// ../../src/lib/utils/parquet-metadata.ts
|
|
1874
|
-
function mapParquetType(col) {
|
|
1875
|
-
const lt = col.logical_type;
|
|
1876
|
-
if (lt) {
|
|
1877
|
-
if (lt.type === "GEOMETRY" || lt.type === "GEOGRAPHY") return "GEOMETRY";
|
|
1878
|
-
if (lt.type === "STRING" || lt.type === "UTF8") return "VARCHAR";
|
|
1879
|
-
if (lt.type === "JSON") return "JSON";
|
|
1880
|
-
if (lt.type === "UUID") return "UUID";
|
|
1881
|
-
if (lt.type === "ENUM") return "VARCHAR";
|
|
1882
|
-
if (lt.type === "INT" || lt.type === "INTEGER") {
|
|
1883
|
-
const bits = lt.bitWidth ?? 32;
|
|
1884
|
-
const signed = lt.isSigned !== false;
|
|
1885
|
-
if (bits <= 8) return signed ? "TINYINT" : "UTINYINT";
|
|
1886
|
-
if (bits <= 16) return signed ? "SMALLINT" : "USMALLINT";
|
|
1887
|
-
if (bits <= 32) return signed ? "INTEGER" : "UINTEGER";
|
|
1888
|
-
return signed ? "BIGINT" : "UBIGINT";
|
|
1889
|
-
}
|
|
1890
|
-
if (lt.type === "DECIMAL") return `DECIMAL(${lt.precision ?? 18},${lt.scale ?? 0})`;
|
|
1891
|
-
if (lt.type === "DATE") return "DATE";
|
|
1892
|
-
if (lt.type === "TIME") return "TIME";
|
|
1893
|
-
if (lt.type === "TIMESTAMP") return "TIMESTAMP";
|
|
1894
|
-
if (lt.type === "BSON") return "BLOB";
|
|
1895
|
-
}
|
|
1896
|
-
const ct = col.converted_type;
|
|
1897
|
-
if (ct === "UTF8") return "VARCHAR";
|
|
1898
|
-
if (ct === "JSON") return "JSON";
|
|
1899
|
-
if (ct === "DATE") return "DATE";
|
|
1900
|
-
if (ct === "TIMESTAMP_MILLIS" || ct === "TIMESTAMP_MICROS") return "TIMESTAMP";
|
|
1901
|
-
if (ct === "DECIMAL") return `DECIMAL(${col.precision ?? 18},${col.scale ?? 0})`;
|
|
1902
|
-
if (ct === "INT_8") return "TINYINT";
|
|
1903
|
-
if (ct === "INT_16") return "SMALLINT";
|
|
1904
|
-
if (ct === "INT_32") return "INTEGER";
|
|
1905
|
-
if (ct === "INT_64") return "BIGINT";
|
|
1906
|
-
if (ct === "UINT_8") return "UTINYINT";
|
|
1907
|
-
if (ct === "UINT_16") return "USMALLINT";
|
|
1908
|
-
if (ct === "UINT_32") return "UINTEGER";
|
|
1909
|
-
if (ct === "UINT_64") return "UBIGINT";
|
|
1910
|
-
const pt = col.type;
|
|
1911
|
-
if (pt === "BOOLEAN") return "BOOLEAN";
|
|
1912
|
-
if (pt === "INT32") return "INTEGER";
|
|
1913
|
-
if (pt === "INT64") return "BIGINT";
|
|
1914
|
-
if (pt === "INT96") return "TIMESTAMP";
|
|
1915
|
-
if (pt === "FLOAT") return "FLOAT";
|
|
1916
|
-
if (pt === "DOUBLE") return "DOUBLE";
|
|
1917
|
-
if (pt === "BYTE_ARRAY") return "BLOB";
|
|
1918
|
-
if (pt === "FIXED_LEN_BYTE_ARRAY") return "BLOB";
|
|
1919
|
-
return "VARCHAR";
|
|
1920
|
-
}
|
|
1921
|
-
async function readParquetMetadata(url) {
|
|
1922
|
-
const { parquetMetadataAsync, asyncBufferFromUrl } = await import('hyparquet');
|
|
1923
|
-
const file = await asyncBufferFromUrl({ url });
|
|
1924
|
-
const metadata = await parquetMetadataAsync(file);
|
|
1925
|
-
const rowCount = metadata.row_groups.reduce(
|
|
1926
|
-
(sum, rg) => sum + Number(rg.num_rows),
|
|
1927
|
-
0
|
|
1928
|
-
);
|
|
1929
|
-
const schema = metadata.schema.slice(1).filter((col) => col.num_children === void 0).map((col) => ({
|
|
1930
|
-
name: col.name,
|
|
1931
|
-
type: mapParquetType(col)
|
|
1932
|
-
}));
|
|
1933
|
-
let geo = null;
|
|
1934
|
-
let legacyGeoParquet = false;
|
|
1935
|
-
const geoKv = metadata.key_value_metadata?.find((kv) => kv.key === "geo");
|
|
1936
|
-
if (geoKv) {
|
|
1937
|
-
try {
|
|
1938
|
-
const geoJson = JSON.parse(geoKv.value ?? "");
|
|
1939
|
-
if (geoJson.schema_version && !geoJson.version) {
|
|
1940
|
-
legacyGeoParquet = true;
|
|
1941
|
-
}
|
|
1942
|
-
geo = {
|
|
1943
|
-
primaryColumn: geoJson.primary_column ?? "geometry",
|
|
1944
|
-
columns: {}
|
|
1945
|
-
};
|
|
1946
|
-
if (geoJson.columns) {
|
|
1947
|
-
for (const [colName, colMeta] of Object.entries(geoJson.columns)) {
|
|
1948
|
-
geo.columns[colName] = {
|
|
1949
|
-
encoding: colMeta.encoding ?? "WKB",
|
|
1950
|
-
geometryTypes: colMeta.geometry_types ?? [],
|
|
1951
|
-
crs: colMeta.crs ?? null,
|
|
1952
|
-
bbox: colMeta.bbox
|
|
1953
|
-
};
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
} catch {
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
const createdBy = metadata.created_by ?? null;
|
|
1960
|
-
const numRowGroups = metadata.row_groups.length;
|
|
1961
|
-
let compression = null;
|
|
1962
|
-
if (numRowGroups > 0 && metadata.row_groups[0].columns) {
|
|
1963
|
-
const codecs = /* @__PURE__ */ new Set();
|
|
1964
|
-
for (const col of metadata.row_groups[0].columns) {
|
|
1965
|
-
const codec = col.meta_data?.codec;
|
|
1966
|
-
if (codec) codecs.add(codec);
|
|
1967
|
-
}
|
|
1968
|
-
if (codecs.size === 1) {
|
|
1969
|
-
compression = [...codecs][0];
|
|
1970
|
-
} else if (codecs.size > 1) {
|
|
1971
|
-
compression = [...codecs].join(", ");
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
return { rowCount, schema, geo, legacyGeoParquet, createdBy, numRowGroups, compression };
|
|
1975
|
-
}
|
|
1976
|
-
function extractEpsgFromGeoMeta(geo) {
|
|
1977
|
-
const primaryCol = geo.columns[geo.primaryColumn];
|
|
1978
|
-
if (!primaryCol?.crs) return null;
|
|
1979
|
-
const crs = primaryCol.crs;
|
|
1980
|
-
if (crs.type === "name" && crs.properties?.name?.includes("CRS84")) return null;
|
|
1981
|
-
if (crs.id?.authority === "EPSG") {
|
|
1982
|
-
const code = crs.id.code;
|
|
1983
|
-
if (WGS84_CODES.has(code)) return null;
|
|
1984
|
-
return `EPSG:${code}`;
|
|
1985
|
-
}
|
|
1986
|
-
return null;
|
|
1987
|
-
}
|
|
1988
|
-
function extractGeometryTypes(geo) {
|
|
1989
|
-
const primaryCol = geo.columns[geo.primaryColumn];
|
|
1990
|
-
if (!primaryCol?.geometryTypes?.length) return [];
|
|
1991
|
-
const typeMap = {
|
|
1992
|
-
Point: "point",
|
|
1993
|
-
LineString: "linestring",
|
|
1994
|
-
Polygon: "polygon",
|
|
1995
|
-
MultiPoint: "multipoint",
|
|
1996
|
-
MultiLineString: "multilinestring",
|
|
1997
|
-
MultiPolygon: "multipolygon"
|
|
1998
|
-
};
|
|
1999
|
-
const types = [];
|
|
2000
|
-
for (const raw of primaryCol.geometryTypes) {
|
|
2001
|
-
const base = raw.split(" ")[0];
|
|
2002
|
-
const mapped = typeMap[base];
|
|
2003
|
-
if (mapped && !types.includes(mapped)) types.push(mapped);
|
|
2004
|
-
}
|
|
2005
|
-
return types;
|
|
2006
|
-
}
|
|
2007
|
-
function extractBounds(geo) {
|
|
2008
|
-
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2009
|
-
if (!primaryCol?.bbox || primaryCol.bbox.length < 4) return null;
|
|
2010
|
-
return [primaryCol.bbox[0], primaryCol.bbox[1], primaryCol.bbox[2], primaryCol.bbox[3]];
|
|
2011
|
-
}
|
|
2012
|
-
|
|
2013
1075
|
// ../../src/lib/storage/providers.ts
|
|
2014
1076
|
var PROVIDERS = {
|
|
2015
1077
|
s3: {
|
|
@@ -2269,7 +1331,1190 @@ var PROVIDERS = {
|
|
|
2269
1331
|
endpointPlaceholder: "https://s3.gra.io.cloud.ovh.net",
|
|
2270
1332
|
schemes: []
|
|
2271
1333
|
}
|
|
2272
|
-
};
|
|
1334
|
+
};
|
|
1335
|
+
var PROVIDER_IDS = [
|
|
1336
|
+
"s3",
|
|
1337
|
+
"gcs",
|
|
1338
|
+
"r2",
|
|
1339
|
+
"azure",
|
|
1340
|
+
"b2",
|
|
1341
|
+
"digitalocean",
|
|
1342
|
+
"wasabi",
|
|
1343
|
+
"storj",
|
|
1344
|
+
"hetzner",
|
|
1345
|
+
"contabo",
|
|
1346
|
+
"linode",
|
|
1347
|
+
"ovhcloud",
|
|
1348
|
+
"minio"
|
|
1349
|
+
];
|
|
1350
|
+
function getProvider(id) {
|
|
1351
|
+
return PROVIDERS[id] ?? PROVIDERS.s3;
|
|
1352
|
+
}
|
|
1353
|
+
function buildEndpointFromTemplate(id, region) {
|
|
1354
|
+
const def = PROVIDERS[id];
|
|
1355
|
+
if (!def?.endpointTemplate) return "";
|
|
1356
|
+
return def.endpointTemplate.replace("{region}", region);
|
|
1357
|
+
}
|
|
1358
|
+
function buildProviderBaseUrl(provider, endpoint, bucket, region) {
|
|
1359
|
+
if (endpoint) {
|
|
1360
|
+
return `${endpoint.replace(/\/$/, "")}/${bucket}`;
|
|
1361
|
+
}
|
|
1362
|
+
const def = PROVIDERS[provider];
|
|
1363
|
+
if (def?.endpointTemplate) {
|
|
1364
|
+
const resolved = def.endpointTemplate.replace("{region}", region || def.defaultRegion);
|
|
1365
|
+
return `${resolved}/${bucket}`;
|
|
1366
|
+
}
|
|
1367
|
+
return `https://s3.${region || "us-east-1"}.amazonaws.com/${bucket}`;
|
|
1368
|
+
}
|
|
1369
|
+
function isGcsProvider(provider, endpoint) {
|
|
1370
|
+
return provider === "gcs" || !!endpoint && /storage\.googleapis\.com/i.test(endpoint);
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
// ../../src/lib/storage/url-adapter.ts
|
|
1374
|
+
var UrlAdapter = class {
|
|
1375
|
+
supportsWrite = false;
|
|
1376
|
+
async read(url, offset, length, signal) {
|
|
1377
|
+
const headers = {};
|
|
1378
|
+
if (offset !== void 0 && length !== void 0) {
|
|
1379
|
+
headers.Range = `bytes=${offset}-${offset + length - 1}`;
|
|
1380
|
+
} else if (offset !== void 0) {
|
|
1381
|
+
headers.Range = `bytes=${offset}-`;
|
|
1382
|
+
}
|
|
1383
|
+
const res = await fetch(url, { headers, signal });
|
|
1384
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1385
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
1386
|
+
}
|
|
1387
|
+
async head(url, signal) {
|
|
1388
|
+
const res = await fetch(url, { method: "HEAD", signal });
|
|
1389
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
1390
|
+
const name = url.split("/").pop()?.split("?")[0] || "file";
|
|
1391
|
+
const ext = name.includes(".") ? name.split(".").pop().toLowerCase() : "";
|
|
1392
|
+
return {
|
|
1393
|
+
name,
|
|
1394
|
+
path: url,
|
|
1395
|
+
is_dir: false,
|
|
1396
|
+
size: Number(res.headers.get("content-length") || 0),
|
|
1397
|
+
modified: new Date(res.headers.get("last-modified") || 0).getTime(),
|
|
1398
|
+
extension: ext
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
async list() {
|
|
1402
|
+
return [];
|
|
1403
|
+
}
|
|
1404
|
+
async put() {
|
|
1405
|
+
throw new Error("Write not supported for direct URL sources");
|
|
1406
|
+
}
|
|
1407
|
+
async delete() {
|
|
1408
|
+
throw new Error("Delete not supported for direct URL sources");
|
|
1409
|
+
}
|
|
1410
|
+
async deletePrefix() {
|
|
1411
|
+
throw new Error("Delete not supported for direct URL sources");
|
|
1412
|
+
}
|
|
1413
|
+
async copy() {
|
|
1414
|
+
throw new Error("Copy not supported for direct URL sources");
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
// ../../src/lib/utils/cloud-url.ts
|
|
1419
|
+
var AWS_REGION_RE = /^(us|eu|ap|sa|ca|me|af|il)-(north|south|east|west|central|northeast|southeast|northwest|southwest)-\d+/;
|
|
1420
|
+
function getNativeScheme(provider) {
|
|
1421
|
+
const def = PROVIDERS[provider];
|
|
1422
|
+
if (def?.schemes.length) return def.schemes[0];
|
|
1423
|
+
return "s3";
|
|
1424
|
+
}
|
|
1425
|
+
function safeDecodeURIComponent(s) {
|
|
1426
|
+
try {
|
|
1427
|
+
return decodeURIComponent(s);
|
|
1428
|
+
} catch {
|
|
1429
|
+
return s;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
function resolveCloudUrl(url) {
|
|
1433
|
+
const s3Match = url.match(/^s3[an]?:\/\/([^/]+)\/?(.*)$/);
|
|
1434
|
+
if (s3Match) {
|
|
1435
|
+
const [, bucket, key] = s3Match;
|
|
1436
|
+
const regionMatch = bucket.match(AWS_REGION_RE);
|
|
1437
|
+
const region = regionMatch ? regionMatch[0] : "us-east-1";
|
|
1438
|
+
const base = buildProviderBaseUrl("s3", "", bucket, region);
|
|
1439
|
+
return key ? `${base}/${key}` : base;
|
|
1440
|
+
}
|
|
1441
|
+
const gcsMatch = url.match(/^gcs?:\/\/([^/]+)\/?(.*)$/);
|
|
1442
|
+
if (gcsMatch) {
|
|
1443
|
+
const [, bucket, key] = gcsMatch;
|
|
1444
|
+
const base = buildProviderBaseUrl("gcs", "", bucket, "");
|
|
1445
|
+
return key ? `${base}/${key}` : base;
|
|
1446
|
+
}
|
|
1447
|
+
return url;
|
|
1448
|
+
}
|
|
1449
|
+
var SF_LABELS = {
|
|
1450
|
+
1: "uint",
|
|
1451
|
+
2: "int",
|
|
1452
|
+
3: "float",
|
|
1453
|
+
4: "void",
|
|
1454
|
+
5: "complex int",
|
|
1455
|
+
6: "complex float"
|
|
1456
|
+
};
|
|
1457
|
+
function safeClamp(v, lo, hi, fallback) {
|
|
1458
|
+
return Number.isFinite(v) ? Math.max(lo, Math.min(hi, v)) : fallback;
|
|
1459
|
+
}
|
|
1460
|
+
function clampBounds(b) {
|
|
1461
|
+
return {
|
|
1462
|
+
west: safeClamp(b.west, -180, 180, -180),
|
|
1463
|
+
south: safeClamp(b.south, -85.051129, 85.051129, -85.051129),
|
|
1464
|
+
east: safeClamp(b.east, -180, 180, 180),
|
|
1465
|
+
north: safeClamp(b.north, -85.051129, 85.051129, 85.051129)
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
function buildDataTypeLabel(sampleFormat, bitsPerSample) {
|
|
1469
|
+
return `${SF_LABELS[sampleFormat] ?? `sf${sampleFormat}`}${bitsPerSample ?? ""}`;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// ../../src/lib/utils/column-types.ts
|
|
1473
|
+
var NUMBER_TYPES = [
|
|
1474
|
+
"TINYINT",
|
|
1475
|
+
"SMALLINT",
|
|
1476
|
+
"INTEGER",
|
|
1477
|
+
"BIGINT",
|
|
1478
|
+
"HUGEINT",
|
|
1479
|
+
"UTINYINT",
|
|
1480
|
+
"USMALLINT",
|
|
1481
|
+
"UINTEGER",
|
|
1482
|
+
"UBIGINT",
|
|
1483
|
+
"FLOAT",
|
|
1484
|
+
"DOUBLE",
|
|
1485
|
+
"DECIMAL",
|
|
1486
|
+
"NUMERIC",
|
|
1487
|
+
"REAL",
|
|
1488
|
+
"INT",
|
|
1489
|
+
"INT1",
|
|
1490
|
+
"INT2",
|
|
1491
|
+
"INT4",
|
|
1492
|
+
"INT8",
|
|
1493
|
+
"SIGNED",
|
|
1494
|
+
"SHORT",
|
|
1495
|
+
"LONG"
|
|
1496
|
+
];
|
|
1497
|
+
var STRING_TYPES = ["VARCHAR", "TEXT", "STRING", "CHAR", "BPCHAR", "NAME", "UUID", "ENUM"];
|
|
1498
|
+
var DATE_TYPES = [
|
|
1499
|
+
"DATE",
|
|
1500
|
+
"TIME",
|
|
1501
|
+
"TIMESTAMP",
|
|
1502
|
+
"TIMESTAMP_S",
|
|
1503
|
+
"TIMESTAMP_MS",
|
|
1504
|
+
"TIMESTAMP_NS",
|
|
1505
|
+
"TIMESTAMP WITH TIME ZONE",
|
|
1506
|
+
"TIMESTAMPTZ",
|
|
1507
|
+
"INTERVAL",
|
|
1508
|
+
"TIMESTAMP_TZ"
|
|
1509
|
+
];
|
|
1510
|
+
var BOOLEAN_TYPES = ["BOOLEAN", "BOOL", "LOGICAL"];
|
|
1511
|
+
var GEO_TYPES = [
|
|
1512
|
+
"GEOMETRY",
|
|
1513
|
+
"POINT",
|
|
1514
|
+
"LINESTRING",
|
|
1515
|
+
"POLYGON",
|
|
1516
|
+
"MULTIPOINT",
|
|
1517
|
+
"MULTILINESTRING",
|
|
1518
|
+
"MULTIPOLYGON",
|
|
1519
|
+
"GEOMETRYCOLLECTION",
|
|
1520
|
+
"WKB_GEOMETRY"
|
|
1521
|
+
];
|
|
1522
|
+
var BINARY_TYPES = ["BLOB", "BYTEA", "BINARY", "VARBINARY"];
|
|
1523
|
+
var JSON_TYPES = ["JSON", "JSONB"];
|
|
1524
|
+
function classifyType(duckdbType) {
|
|
1525
|
+
const upper = duckdbType.toUpperCase().trim();
|
|
1526
|
+
const base = upper.replace(/\(.*\)/, "").trim();
|
|
1527
|
+
if (NUMBER_TYPES.includes(base)) return "number";
|
|
1528
|
+
if (STRING_TYPES.includes(base)) return "string";
|
|
1529
|
+
if (DATE_TYPES.includes(base)) return "date";
|
|
1530
|
+
if (BOOLEAN_TYPES.includes(base)) return "boolean";
|
|
1531
|
+
if (GEO_TYPES.includes(base)) return "geo";
|
|
1532
|
+
if (BINARY_TYPES.includes(base)) return "binary";
|
|
1533
|
+
if (JSON_TYPES.includes(base)) return "json";
|
|
1534
|
+
if (base.startsWith("STRUCT") || base.startsWith("MAP") || base.startsWith("UNION"))
|
|
1535
|
+
return "json";
|
|
1536
|
+
if (base.endsWith("[]") || base.startsWith("LIST")) return "json";
|
|
1537
|
+
if (upper.includes("INT") || upper.includes("FLOAT") || upper.includes("DOUBLE") || upper.includes("DECIMAL") || upper.includes("NUMERIC"))
|
|
1538
|
+
return "number";
|
|
1539
|
+
if (upper.includes("CHAR") || upper.includes("TEXT") || upper.includes("STRING")) return "string";
|
|
1540
|
+
if (upper.includes("TIME") || upper.includes("DATE")) return "date";
|
|
1541
|
+
if (upper.includes("BOOL")) return "boolean";
|
|
1542
|
+
if (upper.includes("GEOMETRY") || upper.includes("GEO") || upper.includes("WKB")) return "geo";
|
|
1543
|
+
if (upper.includes("BLOB") || upper.includes("BINARY")) return "binary";
|
|
1544
|
+
if (upper.includes("JSON") || upper.includes("STRUCT") || upper.includes("MAP") || upper.includes("LIST"))
|
|
1545
|
+
return "json";
|
|
1546
|
+
return "other";
|
|
1547
|
+
}
|
|
1548
|
+
var TYPE_COLORS = {
|
|
1549
|
+
number: "text-blue-500",
|
|
1550
|
+
string: "text-green-500",
|
|
1551
|
+
date: "text-amber-500",
|
|
1552
|
+
boolean: "text-purple-500",
|
|
1553
|
+
geo: "text-teal-500",
|
|
1554
|
+
binary: "text-zinc-500",
|
|
1555
|
+
json: "text-orange-500",
|
|
1556
|
+
other: "text-zinc-400"
|
|
1557
|
+
};
|
|
1558
|
+
var TYPE_BADGE_CLASSES = {
|
|
1559
|
+
number: "bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",
|
|
1560
|
+
string: "bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20",
|
|
1561
|
+
date: "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20",
|
|
1562
|
+
boolean: "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/20",
|
|
1563
|
+
geo: "bg-teal-500/10 text-teal-600 dark:text-teal-400 border-teal-500/20",
|
|
1564
|
+
binary: "bg-zinc-500/10 text-zinc-600 dark:text-zinc-400 border-zinc-500/20",
|
|
1565
|
+
json: "bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/20",
|
|
1566
|
+
other: "bg-zinc-500/10 text-zinc-500 dark:text-zinc-400 border-zinc-500/20"
|
|
1567
|
+
};
|
|
1568
|
+
var TYPE_LABELS = {
|
|
1569
|
+
number: "#",
|
|
1570
|
+
string: "Aa",
|
|
1571
|
+
date: "dt",
|
|
1572
|
+
boolean: "T/F",
|
|
1573
|
+
geo: "geo",
|
|
1574
|
+
binary: "01",
|
|
1575
|
+
json: "{}",
|
|
1576
|
+
other: "?"
|
|
1577
|
+
};
|
|
1578
|
+
function typeColor(category) {
|
|
1579
|
+
return TYPE_COLORS[category];
|
|
1580
|
+
}
|
|
1581
|
+
function typeBadgeClass(category) {
|
|
1582
|
+
return TYPE_BADGE_CLASSES[category];
|
|
1583
|
+
}
|
|
1584
|
+
function typeLabel(category) {
|
|
1585
|
+
return TYPE_LABELS[category];
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// ../../src/lib/utils/error.ts
|
|
1589
|
+
function handleLoadError(err) {
|
|
1590
|
+
if (err instanceof DOMException && err.name === "AbortError") return null;
|
|
1591
|
+
return err instanceof Error ? err.message : String(err);
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
// ../../src/lib/utils/format.ts
|
|
1595
|
+
function formatFileSize(bytes) {
|
|
1596
|
+
if (bytes < 0) return "0 B";
|
|
1597
|
+
if (bytes === 0) return "0 B";
|
|
1598
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
1599
|
+
const base = 1024;
|
|
1600
|
+
const exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(base)), units.length - 1);
|
|
1601
|
+
const value = bytes / base ** exponent;
|
|
1602
|
+
if (exponent === 0) return `${bytes} B`;
|
|
1603
|
+
return `${value.toFixed(1)} ${units[exponent]}`;
|
|
1604
|
+
}
|
|
1605
|
+
function formatDate(timestamp) {
|
|
1606
|
+
if (!timestamp || timestamp <= 0 || !Number.isFinite(timestamp)) return "--";
|
|
1607
|
+
const date = new Date(timestamp);
|
|
1608
|
+
const now = Date.now();
|
|
1609
|
+
const diffMs = now - timestamp;
|
|
1610
|
+
const diffSeconds = Math.floor(diffMs / 1e3);
|
|
1611
|
+
const diffMinutes = Math.floor(diffSeconds / 60);
|
|
1612
|
+
const diffHours = Math.floor(diffMinutes / 60);
|
|
1613
|
+
const diffDays = Math.floor(diffHours / 24);
|
|
1614
|
+
if (diffSeconds < 60) return "Just now";
|
|
1615
|
+
if (diffMinutes < 60) return `${diffMinutes}m ago`;
|
|
1616
|
+
if (diffHours < 24) return `${diffHours}h ago`;
|
|
1617
|
+
if (diffDays < 7) return `${diffDays}d ago`;
|
|
1618
|
+
return date.toLocaleDateString(void 0, {
|
|
1619
|
+
year: "numeric",
|
|
1620
|
+
month: "short",
|
|
1621
|
+
day: "numeric"
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
function getFileExtension(filename) {
|
|
1625
|
+
const lastDot = filename.lastIndexOf(".");
|
|
1626
|
+
if (lastDot <= 0) return "";
|
|
1627
|
+
return filename.slice(lastDot).toLowerCase();
|
|
1628
|
+
}
|
|
1629
|
+
function jsonReplacerBigInt(_key, value) {
|
|
1630
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
1631
|
+
}
|
|
1632
|
+
function formatValue(value) {
|
|
1633
|
+
if (value === null || value === void 0) return "NULL";
|
|
1634
|
+
if (value instanceof Date) return value.toISOString();
|
|
1635
|
+
if (typeof value === "bigint") return value.toString();
|
|
1636
|
+
if (typeof value === "object") return JSON.stringify(value, jsonReplacerBigInt);
|
|
1637
|
+
return String(value);
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
// ../../src/lib/utils/export.ts
|
|
1641
|
+
function formatCellValue(value) {
|
|
1642
|
+
if (value === null || value === void 0) return "";
|
|
1643
|
+
if (value instanceof Date) return value.toISOString();
|
|
1644
|
+
if (typeof value === "bigint") return value.toString();
|
|
1645
|
+
if (typeof value === "object") return JSON.stringify(value, jsonReplacerBigInt);
|
|
1646
|
+
return String(value);
|
|
1647
|
+
}
|
|
1648
|
+
function escapeCsvField(value) {
|
|
1649
|
+
if (value.includes(",") || value.includes('"') || value.includes("\n") || value.includes("\r")) {
|
|
1650
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
1651
|
+
}
|
|
1652
|
+
return value;
|
|
1653
|
+
}
|
|
1654
|
+
function serializeToCsv(columns, rows) {
|
|
1655
|
+
const header = columns.map(escapeCsvField).join(",");
|
|
1656
|
+
const body = rows.map((row) => columns.map((col) => escapeCsvField(formatCellValue(row[col]))).join(",")).join("\n");
|
|
1657
|
+
return `${header}
|
|
1658
|
+
${body}`;
|
|
1659
|
+
}
|
|
1660
|
+
function serializeToJson(columns, rows) {
|
|
1661
|
+
const data = rows.map((row) => {
|
|
1662
|
+
const obj = {};
|
|
1663
|
+
for (const col of columns) {
|
|
1664
|
+
const val = row[col];
|
|
1665
|
+
if (val instanceof Date) {
|
|
1666
|
+
obj[col] = val.toISOString();
|
|
1667
|
+
} else {
|
|
1668
|
+
obj[col] = val ?? null;
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
return obj;
|
|
1672
|
+
});
|
|
1673
|
+
return JSON.stringify(data, jsonReplacerBigInt, 2);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
// ../../src/lib/utils/file-sort.ts
|
|
1677
|
+
function sortFileEntries(entries, config) {
|
|
1678
|
+
const sorted = [...entries];
|
|
1679
|
+
const dir = config.direction === "asc" ? 1 : -1;
|
|
1680
|
+
sorted.sort((a, b) => {
|
|
1681
|
+
if (a.is_dir && !b.is_dir) return -1;
|
|
1682
|
+
if (!a.is_dir && b.is_dir) return 1;
|
|
1683
|
+
switch (config.field) {
|
|
1684
|
+
case "name":
|
|
1685
|
+
return dir * a.name.localeCompare(b.name, void 0, { sensitivity: "base" });
|
|
1686
|
+
case "size":
|
|
1687
|
+
return dir * (a.size - b.size);
|
|
1688
|
+
case "modified":
|
|
1689
|
+
return dir * (a.modified - b.modified);
|
|
1690
|
+
case "extension":
|
|
1691
|
+
return dir * a.extension.localeCompare(b.extension, void 0, { sensitivity: "base" });
|
|
1692
|
+
default:
|
|
1693
|
+
return 0;
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
return sorted;
|
|
1697
|
+
}
|
|
1698
|
+
function toggleSortField(current, field) {
|
|
1699
|
+
if (current.field === field) {
|
|
1700
|
+
return { field, direction: current.direction === "asc" ? "desc" : "asc" };
|
|
1701
|
+
}
|
|
1702
|
+
return { field, direction: "asc" };
|
|
1703
|
+
}
|
|
1704
|
+
function normalizeGeomType(raw) {
|
|
1705
|
+
const s = raw.toUpperCase().replace(/\s+/g, "");
|
|
1706
|
+
if (s === "POINT") return "point";
|
|
1707
|
+
if (s === "LINESTRING") return "linestring";
|
|
1708
|
+
if (s === "POLYGON") return "polygon";
|
|
1709
|
+
if (s === "MULTIPOINT") return "multipoint";
|
|
1710
|
+
if (s === "MULTILINESTRING") return "multilinestring";
|
|
1711
|
+
if (s === "MULTIPOLYGON") return "multipolygon";
|
|
1712
|
+
return "polygon";
|
|
1713
|
+
}
|
|
1714
|
+
var EXTENSION_NAMES = {
|
|
1715
|
+
point: "geoarrow.point",
|
|
1716
|
+
linestring: "geoarrow.linestring",
|
|
1717
|
+
polygon: "geoarrow.polygon",
|
|
1718
|
+
multipoint: "geoarrow.multipoint",
|
|
1719
|
+
multilinestring: "geoarrow.multilinestring",
|
|
1720
|
+
multipolygon: "geoarrow.multipolygon"
|
|
1721
|
+
};
|
|
1722
|
+
function readWkbHeader(wkb) {
|
|
1723
|
+
if (wkb.length < 5) return null;
|
|
1724
|
+
const le = wkb[0] === 1;
|
|
1725
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1726
|
+
const rawType = dv.getUint32(1, le);
|
|
1727
|
+
let headerSize = 5;
|
|
1728
|
+
if ((rawType & 536870912) !== 0) headerSize += 4;
|
|
1729
|
+
const ewkbZ = (rawType & 2147483648) !== 0;
|
|
1730
|
+
const ewkbM = (rawType & 1073741824) !== 0;
|
|
1731
|
+
let type = rawType & 268435455;
|
|
1732
|
+
let isoZ = false;
|
|
1733
|
+
let isoM = false;
|
|
1734
|
+
if (type > 3e3) {
|
|
1735
|
+
isoZ = true;
|
|
1736
|
+
isoM = true;
|
|
1737
|
+
type -= 3e3;
|
|
1738
|
+
} else if (type > 2e3) {
|
|
1739
|
+
isoM = true;
|
|
1740
|
+
type -= 2e3;
|
|
1741
|
+
} else if (type > 1e3) {
|
|
1742
|
+
isoZ = true;
|
|
1743
|
+
type -= 1e3;
|
|
1744
|
+
}
|
|
1745
|
+
const dims = (ewkbZ || isoZ ? 1 : 0) + (ewkbM || isoM ? 1 : 0);
|
|
1746
|
+
const coordStride = (2 + dims) * 8;
|
|
1747
|
+
return { type, le, coordStride, dataOffset: headerSize };
|
|
1748
|
+
}
|
|
1749
|
+
function classifyWkbType(wkb) {
|
|
1750
|
+
const h = readWkbHeader(wkb);
|
|
1751
|
+
if (!h) return null;
|
|
1752
|
+
switch (h.type) {
|
|
1753
|
+
case 1:
|
|
1754
|
+
return "point";
|
|
1755
|
+
case 2:
|
|
1756
|
+
return "linestring";
|
|
1757
|
+
case 3:
|
|
1758
|
+
return "polygon";
|
|
1759
|
+
case 4:
|
|
1760
|
+
return "multipoint";
|
|
1761
|
+
case 5:
|
|
1762
|
+
return "multilinestring";
|
|
1763
|
+
case 6:
|
|
1764
|
+
return "multipolygon";
|
|
1765
|
+
default:
|
|
1766
|
+
return null;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
function newBounds() {
|
|
1770
|
+
return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
1771
|
+
}
|
|
1772
|
+
function expandBounds(b, x, y) {
|
|
1773
|
+
if (Number.isNaN(x) || Number.isNaN(y)) return;
|
|
1774
|
+
if (x < b.minX) b.minX = x;
|
|
1775
|
+
if (y < b.minY) b.minY = y;
|
|
1776
|
+
if (x > b.maxX) b.maxX = x;
|
|
1777
|
+
if (y > b.maxY) b.maxY = y;
|
|
1778
|
+
}
|
|
1779
|
+
var coordField = new Field("xy", new Float64());
|
|
1780
|
+
var coordType = new FixedSizeList(2, coordField);
|
|
1781
|
+
function makeCoordData(coords, numPoints) {
|
|
1782
|
+
const floatData = makeData({ type: new Float64(), length: coords.length, data: coords });
|
|
1783
|
+
return makeData({ type: coordType, length: numPoints, nullCount: 0, child: floatData });
|
|
1784
|
+
}
|
|
1785
|
+
function buildPointData(wkbs, b) {
|
|
1786
|
+
const n = wkbs.length;
|
|
1787
|
+
const coords = new Float64Array(n * 2);
|
|
1788
|
+
for (let i = 0; i < n; i++) {
|
|
1789
|
+
const wkb = wkbs[i];
|
|
1790
|
+
const h = readWkbHeader(wkb);
|
|
1791
|
+
if (!h || h.type !== 1) {
|
|
1792
|
+
coords[i * 2] = 0;
|
|
1793
|
+
coords[i * 2 + 1] = 0;
|
|
1794
|
+
continue;
|
|
1795
|
+
}
|
|
1796
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1797
|
+
const x = dv.getFloat64(h.dataOffset, h.le);
|
|
1798
|
+
const y = dv.getFloat64(h.dataOffset + 8, h.le);
|
|
1799
|
+
coords[i * 2] = x;
|
|
1800
|
+
coords[i * 2 + 1] = y;
|
|
1801
|
+
expandBounds(b, x, y);
|
|
1802
|
+
}
|
|
1803
|
+
return makeCoordData(coords, n);
|
|
1804
|
+
}
|
|
1805
|
+
function buildLineStringData(wkbs, b) {
|
|
1806
|
+
const n = wkbs.length;
|
|
1807
|
+
const geomOffsets = new Int32Array(n + 1);
|
|
1808
|
+
let totalCoords = 0;
|
|
1809
|
+
for (let i = 0; i < n; i++) {
|
|
1810
|
+
geomOffsets[i] = totalCoords;
|
|
1811
|
+
const h = readWkbHeader(wkbs[i]);
|
|
1812
|
+
if (!h || h.type !== 2) continue;
|
|
1813
|
+
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1814
|
+
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1815
|
+
totalCoords += numPts;
|
|
1816
|
+
}
|
|
1817
|
+
geomOffsets[n] = totalCoords;
|
|
1818
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1819
|
+
let ci = 0;
|
|
1820
|
+
for (const wkb of wkbs) {
|
|
1821
|
+
const h = readWkbHeader(wkb);
|
|
1822
|
+
if (!h || h.type !== 2) continue;
|
|
1823
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1824
|
+
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1825
|
+
let off = h.dataOffset + 4;
|
|
1826
|
+
for (let j = 0; j < numPts; j++) {
|
|
1827
|
+
const x = dv.getFloat64(off, h.le);
|
|
1828
|
+
const y = dv.getFloat64(off + 8, h.le);
|
|
1829
|
+
coords[ci++] = x;
|
|
1830
|
+
coords[ci++] = y;
|
|
1831
|
+
expandBounds(b, x, y);
|
|
1832
|
+
off += h.coordStride;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
const fslData = makeCoordData(coords, totalCoords);
|
|
1836
|
+
const listType = new List(new Field("vertices", coordType));
|
|
1837
|
+
return makeData({
|
|
1838
|
+
type: listType,
|
|
1839
|
+
length: n,
|
|
1840
|
+
nullCount: 0,
|
|
1841
|
+
valueOffsets: geomOffsets,
|
|
1842
|
+
child: fslData
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
function buildPolygonData(wkbs, b) {
|
|
1846
|
+
const n = wkbs.length;
|
|
1847
|
+
const geomOffsets = new Int32Array(n + 1);
|
|
1848
|
+
let totalRings = 0;
|
|
1849
|
+
let totalCoords = 0;
|
|
1850
|
+
for (let i = 0; i < n; i++) {
|
|
1851
|
+
geomOffsets[i] = totalRings;
|
|
1852
|
+
const h = readWkbHeader(wkbs[i]);
|
|
1853
|
+
if (!h || h.type !== 3) continue;
|
|
1854
|
+
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1855
|
+
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1856
|
+
let off = h.dataOffset + 4;
|
|
1857
|
+
for (let r = 0; r < numRings; r++) {
|
|
1858
|
+
const numPts = dv.getUint32(off, h.le);
|
|
1859
|
+
off += 4 + numPts * h.coordStride;
|
|
1860
|
+
totalCoords += numPts;
|
|
1861
|
+
totalRings++;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
geomOffsets[n] = totalRings;
|
|
1865
|
+
const ringOffsets = new Int32Array(totalRings + 1);
|
|
1866
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1867
|
+
let ri = 0;
|
|
1868
|
+
let ci = 0;
|
|
1869
|
+
for (const wkb of wkbs) {
|
|
1870
|
+
const h = readWkbHeader(wkb);
|
|
1871
|
+
if (!h || h.type !== 3) continue;
|
|
1872
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1873
|
+
const numRings = dv.getUint32(h.dataOffset, h.le);
|
|
1874
|
+
let off = h.dataOffset + 4;
|
|
1875
|
+
for (let r = 0; r < numRings; r++) {
|
|
1876
|
+
ringOffsets[ri++] = ci >> 1;
|
|
1877
|
+
const numPts = dv.getUint32(off, h.le);
|
|
1878
|
+
off += 4;
|
|
1879
|
+
for (let j = 0; j < numPts; j++) {
|
|
1880
|
+
const x = dv.getFloat64(off, h.le);
|
|
1881
|
+
const y = dv.getFloat64(off + 8, h.le);
|
|
1882
|
+
coords[ci++] = x;
|
|
1883
|
+
coords[ci++] = y;
|
|
1884
|
+
expandBounds(b, x, y);
|
|
1885
|
+
off += h.coordStride;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
ringOffsets[totalRings] = ci >> 1;
|
|
1890
|
+
const coordCount = ci >> 1;
|
|
1891
|
+
const fslData = makeCoordData(coords, coordCount);
|
|
1892
|
+
const ringListType = new List(new Field("vertices", coordType));
|
|
1893
|
+
const ringListData = makeData({
|
|
1894
|
+
type: ringListType,
|
|
1895
|
+
length: totalRings,
|
|
1896
|
+
nullCount: 0,
|
|
1897
|
+
valueOffsets: ringOffsets,
|
|
1898
|
+
child: fslData
|
|
1899
|
+
});
|
|
1900
|
+
const polyType = new List(new Field("rings", ringListType));
|
|
1901
|
+
return makeData({
|
|
1902
|
+
type: polyType,
|
|
1903
|
+
length: n,
|
|
1904
|
+
nullCount: 0,
|
|
1905
|
+
valueOffsets: geomOffsets,
|
|
1906
|
+
child: ringListData
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
function buildMultiPointData(wkbs, b) {
|
|
1910
|
+
const n = wkbs.length;
|
|
1911
|
+
const geomOffsets = new Int32Array(n + 1);
|
|
1912
|
+
let totalCoords = 0;
|
|
1913
|
+
for (let i = 0; i < n; i++) {
|
|
1914
|
+
geomOffsets[i] = totalCoords;
|
|
1915
|
+
const h = readWkbHeader(wkbs[i]);
|
|
1916
|
+
if (!h || h.type !== 4) continue;
|
|
1917
|
+
const dv = new DataView(wkbs[i].buffer, wkbs[i].byteOffset, wkbs[i].byteLength);
|
|
1918
|
+
totalCoords += dv.getUint32(h.dataOffset, h.le);
|
|
1919
|
+
}
|
|
1920
|
+
geomOffsets[n] = totalCoords;
|
|
1921
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1922
|
+
let ci = 0;
|
|
1923
|
+
for (const wkb of wkbs) {
|
|
1924
|
+
const h = readWkbHeader(wkb);
|
|
1925
|
+
if (!h || h.type !== 4) continue;
|
|
1926
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1927
|
+
const numPts = dv.getUint32(h.dataOffset, h.le);
|
|
1928
|
+
let off = h.dataOffset + 4;
|
|
1929
|
+
for (let j = 0; j < numPts; j++) {
|
|
1930
|
+
const innerH = readWkbHeader(
|
|
1931
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1932
|
+
);
|
|
1933
|
+
if (innerH) {
|
|
1934
|
+
const x = dv.getFloat64(off + innerH.dataOffset, innerH.le);
|
|
1935
|
+
const y = dv.getFloat64(off + innerH.dataOffset + 8, innerH.le);
|
|
1936
|
+
coords[ci++] = x;
|
|
1937
|
+
coords[ci++] = y;
|
|
1938
|
+
expandBounds(b, x, y);
|
|
1939
|
+
off += innerH.dataOffset + innerH.coordStride;
|
|
1940
|
+
} else {
|
|
1941
|
+
coords[ci++] = 0;
|
|
1942
|
+
coords[ci++] = 0;
|
|
1943
|
+
off += 21;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
const fslData = makeCoordData(coords, totalCoords);
|
|
1948
|
+
const listType = new List(new Field("vertices", coordType));
|
|
1949
|
+
return makeData({
|
|
1950
|
+
type: listType,
|
|
1951
|
+
length: n,
|
|
1952
|
+
nullCount: 0,
|
|
1953
|
+
valueOffsets: geomOffsets,
|
|
1954
|
+
child: fslData
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
function buildMultiLineStringData(wkbs, b) {
|
|
1958
|
+
const n = wkbs.length;
|
|
1959
|
+
const geomOffsetsArr = [0];
|
|
1960
|
+
let totalLines = 0;
|
|
1961
|
+
let totalCoords = 0;
|
|
1962
|
+
for (const wkb of wkbs) {
|
|
1963
|
+
const h = readWkbHeader(wkb);
|
|
1964
|
+
if (!h || h.type !== 5) {
|
|
1965
|
+
geomOffsetsArr.push(totalLines);
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1968
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1969
|
+
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1970
|
+
let off = h.dataOffset + 4;
|
|
1971
|
+
for (let l = 0; l < numLines; l++) {
|
|
1972
|
+
const innerH = readWkbHeader(
|
|
1973
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1974
|
+
);
|
|
1975
|
+
if (!innerH) break;
|
|
1976
|
+
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
1977
|
+
const numPts = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
1978
|
+
totalCoords += numPts;
|
|
1979
|
+
off += innerH.dataOffset + 4 + numPts * innerH.coordStride;
|
|
1980
|
+
totalLines++;
|
|
1981
|
+
}
|
|
1982
|
+
geomOffsetsArr.push(totalLines);
|
|
1983
|
+
}
|
|
1984
|
+
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
1985
|
+
const lineOffsets = new Int32Array(totalLines + 1);
|
|
1986
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
1987
|
+
let li = 0;
|
|
1988
|
+
let ci = 0;
|
|
1989
|
+
for (const wkb of wkbs) {
|
|
1990
|
+
const h = readWkbHeader(wkb);
|
|
1991
|
+
if (!h || h.type !== 5) continue;
|
|
1992
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
1993
|
+
const numLines = dv.getUint32(h.dataOffset, h.le);
|
|
1994
|
+
let off = h.dataOffset + 4;
|
|
1995
|
+
for (let l = 0; l < numLines; l++) {
|
|
1996
|
+
lineOffsets[li++] = ci >> 1;
|
|
1997
|
+
const innerH = readWkbHeader(
|
|
1998
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
1999
|
+
);
|
|
2000
|
+
if (!innerH) break;
|
|
2001
|
+
const numPts = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off).getUint32(
|
|
2002
|
+
innerH.dataOffset,
|
|
2003
|
+
innerH.le
|
|
2004
|
+
);
|
|
2005
|
+
let ptOff = off + innerH.dataOffset + 4;
|
|
2006
|
+
for (let j = 0; j < numPts; j++) {
|
|
2007
|
+
const x = dv.getFloat64(ptOff, innerH.le);
|
|
2008
|
+
const y = dv.getFloat64(ptOff + 8, innerH.le);
|
|
2009
|
+
coords[ci++] = x;
|
|
2010
|
+
coords[ci++] = y;
|
|
2011
|
+
expandBounds(b, x, y);
|
|
2012
|
+
ptOff += innerH.coordStride;
|
|
2013
|
+
}
|
|
2014
|
+
off = ptOff;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
lineOffsets[totalLines] = ci >> 1;
|
|
2018
|
+
const fslData = makeCoordData(coords, ci >> 1);
|
|
2019
|
+
const lineListType = new List(new Field("vertices", coordType));
|
|
2020
|
+
const lineListData = makeData({
|
|
2021
|
+
type: lineListType,
|
|
2022
|
+
length: totalLines,
|
|
2023
|
+
nullCount: 0,
|
|
2024
|
+
valueOffsets: lineOffsets,
|
|
2025
|
+
child: fslData
|
|
2026
|
+
});
|
|
2027
|
+
const multiLineType = new List(new Field("lines", lineListType));
|
|
2028
|
+
return makeData({
|
|
2029
|
+
type: multiLineType,
|
|
2030
|
+
length: n,
|
|
2031
|
+
nullCount: 0,
|
|
2032
|
+
valueOffsets: geomOffsets,
|
|
2033
|
+
child: lineListData
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
function buildMultiPolygonData(wkbs, b) {
|
|
2037
|
+
const n = wkbs.length;
|
|
2038
|
+
const geomOffsetsArr = [0];
|
|
2039
|
+
let totalPolys = 0;
|
|
2040
|
+
let totalRings = 0;
|
|
2041
|
+
let totalCoords = 0;
|
|
2042
|
+
for (const wkb of wkbs) {
|
|
2043
|
+
const h = readWkbHeader(wkb);
|
|
2044
|
+
if (!h || h.type !== 6) {
|
|
2045
|
+
geomOffsetsArr.push(totalPolys);
|
|
2046
|
+
continue;
|
|
2047
|
+
}
|
|
2048
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
2049
|
+
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
2050
|
+
let off = h.dataOffset + 4;
|
|
2051
|
+
for (let p = 0; p < numPolys; p++) {
|
|
2052
|
+
const innerH = readWkbHeader(
|
|
2053
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
2054
|
+
);
|
|
2055
|
+
if (!innerH) break;
|
|
2056
|
+
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
2057
|
+
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
2058
|
+
let ringOff = innerH.dataOffset + 4;
|
|
2059
|
+
for (let r = 0; r < numRings; r++) {
|
|
2060
|
+
const numPts = innerDv.getUint32(ringOff, innerH.le);
|
|
2061
|
+
ringOff += 4 + numPts * innerH.coordStride;
|
|
2062
|
+
totalCoords += numPts;
|
|
2063
|
+
totalRings++;
|
|
2064
|
+
}
|
|
2065
|
+
off += ringOff;
|
|
2066
|
+
totalPolys++;
|
|
2067
|
+
}
|
|
2068
|
+
geomOffsetsArr.push(totalPolys);
|
|
2069
|
+
}
|
|
2070
|
+
const geomOffsets = new Int32Array(geomOffsetsArr);
|
|
2071
|
+
const polyOffsets = new Int32Array(totalPolys + 1);
|
|
2072
|
+
const ringOffsets = new Int32Array(totalRings + 1);
|
|
2073
|
+
const coords = new Float64Array(totalCoords * 2);
|
|
2074
|
+
let pi = 0;
|
|
2075
|
+
let ri = 0;
|
|
2076
|
+
let ci = 0;
|
|
2077
|
+
for (const wkb of wkbs) {
|
|
2078
|
+
const h = readWkbHeader(wkb);
|
|
2079
|
+
if (!h || h.type !== 6) continue;
|
|
2080
|
+
const dv = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
|
|
2081
|
+
const numPolys = dv.getUint32(h.dataOffset, h.le);
|
|
2082
|
+
let off = h.dataOffset + 4;
|
|
2083
|
+
for (let p = 0; p < numPolys; p++) {
|
|
2084
|
+
polyOffsets[pi++] = ri;
|
|
2085
|
+
const innerH = readWkbHeader(
|
|
2086
|
+
new Uint8Array(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off)
|
|
2087
|
+
);
|
|
2088
|
+
if (!innerH) break;
|
|
2089
|
+
const innerDv = new DataView(wkb.buffer, wkb.byteOffset + off, wkb.byteLength - off);
|
|
2090
|
+
const numRings = innerDv.getUint32(innerH.dataOffset, innerH.le);
|
|
2091
|
+
let ringOff = off + innerH.dataOffset + 4;
|
|
2092
|
+
for (let r = 0; r < numRings; r++) {
|
|
2093
|
+
ringOffsets[ri++] = ci >> 1;
|
|
2094
|
+
const numPts = dv.getUint32(ringOff, innerH.le);
|
|
2095
|
+
ringOff += 4;
|
|
2096
|
+
for (let j = 0; j < numPts; j++) {
|
|
2097
|
+
const x = dv.getFloat64(ringOff, innerH.le);
|
|
2098
|
+
const y = dv.getFloat64(ringOff + 8, innerH.le);
|
|
2099
|
+
coords[ci++] = x;
|
|
2100
|
+
coords[ci++] = y;
|
|
2101
|
+
expandBounds(b, x, y);
|
|
2102
|
+
ringOff += innerH.coordStride;
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
off = ringOff;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
polyOffsets[totalPolys] = ri;
|
|
2109
|
+
ringOffsets[totalRings] = ci >> 1;
|
|
2110
|
+
const fslData = makeCoordData(coords, ci >> 1);
|
|
2111
|
+
const ringListType = new List(new Field("vertices", coordType));
|
|
2112
|
+
const ringListData = makeData({
|
|
2113
|
+
type: ringListType,
|
|
2114
|
+
length: totalRings,
|
|
2115
|
+
nullCount: 0,
|
|
2116
|
+
valueOffsets: ringOffsets,
|
|
2117
|
+
child: fslData
|
|
2118
|
+
});
|
|
2119
|
+
const polyListType = new List(new Field("rings", ringListType));
|
|
2120
|
+
const polyListData = makeData({
|
|
2121
|
+
type: polyListType,
|
|
2122
|
+
length: totalPolys,
|
|
2123
|
+
nullCount: 0,
|
|
2124
|
+
valueOffsets: polyOffsets,
|
|
2125
|
+
child: ringListData
|
|
2126
|
+
});
|
|
2127
|
+
const multiPolyType = new List(new Field("polygons", polyListType));
|
|
2128
|
+
return makeData({
|
|
2129
|
+
type: multiPolyType,
|
|
2130
|
+
length: n,
|
|
2131
|
+
nullCount: 0,
|
|
2132
|
+
valueOffsets: geomOffsets,
|
|
2133
|
+
child: polyListData
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
function buildAttributeColumns(indices, attributes) {
|
|
2137
|
+
const n = indices.length;
|
|
2138
|
+
const fields = [];
|
|
2139
|
+
const dataArr = [];
|
|
2140
|
+
for (const [name, col] of attributes) {
|
|
2141
|
+
const { values } = col;
|
|
2142
|
+
let isNumeric = true;
|
|
2143
|
+
const sampleEnd = Math.min(n, 100);
|
|
2144
|
+
for (let i = 0; i < sampleEnd; i++) {
|
|
2145
|
+
if (values[indices[i]] != null && typeof values[indices[i]] !== "number") {
|
|
2146
|
+
isNumeric = false;
|
|
2147
|
+
break;
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
if (isNumeric) {
|
|
2151
|
+
const arr = new Float64Array(n);
|
|
2152
|
+
for (let i = 0; i < n; i++) arr[i] = values[indices[i]] ?? NaN;
|
|
2153
|
+
const data = makeData({ type: new Float64(), length: n, data: arr });
|
|
2154
|
+
fields.push(new Field(name, new Float64(), true));
|
|
2155
|
+
dataArr.push(data);
|
|
2156
|
+
} else {
|
|
2157
|
+
const encoder = new TextEncoder();
|
|
2158
|
+
const offsets = new Int32Array(n + 1);
|
|
2159
|
+
let totalBytes = 0;
|
|
2160
|
+
const strParts = [];
|
|
2161
|
+
for (let i = 0; i < n; i++) {
|
|
2162
|
+
offsets[i] = totalBytes;
|
|
2163
|
+
const s = values[indices[i]] != null ? String(values[indices[i]]) : "";
|
|
2164
|
+
const encoded = encoder.encode(s);
|
|
2165
|
+
strParts.push(encoded);
|
|
2166
|
+
totalBytes += encoded.length;
|
|
2167
|
+
}
|
|
2168
|
+
offsets[n] = totalBytes;
|
|
2169
|
+
const valueBuffer = new Uint8Array(totalBytes);
|
|
2170
|
+
let pos = 0;
|
|
2171
|
+
for (const sv of strParts) {
|
|
2172
|
+
valueBuffer.set(sv, pos);
|
|
2173
|
+
pos += sv.length;
|
|
2174
|
+
}
|
|
2175
|
+
const data = makeData({
|
|
2176
|
+
type: new Utf8(),
|
|
2177
|
+
length: n,
|
|
2178
|
+
valueOffsets: offsets,
|
|
2179
|
+
data: valueBuffer
|
|
2180
|
+
});
|
|
2181
|
+
fields.push(new Field(name, new Utf8(), true));
|
|
2182
|
+
dataArr.push(data);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
return { fields, data: dataArr };
|
|
2186
|
+
}
|
|
2187
|
+
function buildSingleTable(geomType, wkbs, indices, attributes, b) {
|
|
2188
|
+
const n = wkbs.length;
|
|
2189
|
+
let geomData;
|
|
2190
|
+
switch (geomType) {
|
|
2191
|
+
case "point":
|
|
2192
|
+
geomData = buildPointData(wkbs, b);
|
|
2193
|
+
break;
|
|
2194
|
+
case "linestring":
|
|
2195
|
+
geomData = buildLineStringData(wkbs, b);
|
|
2196
|
+
break;
|
|
2197
|
+
case "polygon":
|
|
2198
|
+
geomData = buildPolygonData(wkbs, b);
|
|
2199
|
+
break;
|
|
2200
|
+
case "multipoint":
|
|
2201
|
+
geomData = buildMultiPointData(wkbs, b);
|
|
2202
|
+
break;
|
|
2203
|
+
case "multilinestring":
|
|
2204
|
+
geomData = buildMultiLineStringData(wkbs, b);
|
|
2205
|
+
break;
|
|
2206
|
+
case "multipolygon":
|
|
2207
|
+
geomData = buildMultiPolygonData(wkbs, b);
|
|
2208
|
+
break;
|
|
2209
|
+
}
|
|
2210
|
+
const extensionName = EXTENSION_NAMES[geomType];
|
|
2211
|
+
const geomMetadata = /* @__PURE__ */ new Map([
|
|
2212
|
+
["ARROW:extension:name", extensionName],
|
|
2213
|
+
[
|
|
2214
|
+
"ARROW:extension:metadata",
|
|
2215
|
+
JSON.stringify({
|
|
2216
|
+
crs: {
|
|
2217
|
+
type: "name",
|
|
2218
|
+
properties: { name: "urn:ogc:def:crs:OGC:1.3:CRS84" }
|
|
2219
|
+
}
|
|
2220
|
+
})
|
|
2221
|
+
]
|
|
2222
|
+
]);
|
|
2223
|
+
const geomField = new Field("geometry", geomData.type, false, geomMetadata);
|
|
2224
|
+
const attrCols = buildAttributeColumns(indices, attributes);
|
|
2225
|
+
const fields = [geomField, ...attrCols.fields];
|
|
2226
|
+
const childrenData = [geomData, ...attrCols.data];
|
|
2227
|
+
const arrowSchema = new Schema(fields);
|
|
2228
|
+
const structType = new Struct(fields);
|
|
2229
|
+
const structData = makeData({
|
|
2230
|
+
type: structType,
|
|
2231
|
+
length: n,
|
|
2232
|
+
nullCount: 0,
|
|
2233
|
+
children: childrenData
|
|
2234
|
+
});
|
|
2235
|
+
const batch = new RecordBatch(arrowSchema, structData);
|
|
2236
|
+
const table = new Table(arrowSchema, batch);
|
|
2237
|
+
return {
|
|
2238
|
+
table,
|
|
2239
|
+
geometryType: geomType,
|
|
2240
|
+
bounds: [b.minX, b.minY, b.maxX, b.maxY],
|
|
2241
|
+
sourceIndices: indices
|
|
2242
|
+
};
|
|
2243
|
+
}
|
|
2244
|
+
function buildGeoArrowTables(wkbArrays, attributes, knownGeomType) {
|
|
2245
|
+
if (wkbArrays.length === 0) return [];
|
|
2246
|
+
if (knownGeomType) {
|
|
2247
|
+
const globalBounds2 = newBounds();
|
|
2248
|
+
const indices = Array.from({ length: wkbArrays.length }, (_, i) => i);
|
|
2249
|
+
const result = buildSingleTable(knownGeomType, wkbArrays, indices, attributes, globalBounds2);
|
|
2250
|
+
return [result];
|
|
2251
|
+
}
|
|
2252
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2253
|
+
for (let i = 0; i < wkbArrays.length; i++) {
|
|
2254
|
+
const geomType = classifyWkbType(wkbArrays[i]);
|
|
2255
|
+
if (!geomType) continue;
|
|
2256
|
+
let group = groups.get(geomType);
|
|
2257
|
+
if (!group) {
|
|
2258
|
+
group = { wkbs: [], indices: [] };
|
|
2259
|
+
groups.set(geomType, group);
|
|
2260
|
+
}
|
|
2261
|
+
group.wkbs.push(wkbArrays[i]);
|
|
2262
|
+
group.indices.push(i);
|
|
2263
|
+
}
|
|
2264
|
+
if (groups.size === 0) return [];
|
|
2265
|
+
const globalBounds = newBounds();
|
|
2266
|
+
const results = [];
|
|
2267
|
+
for (const [geomType, { wkbs, indices }] of groups) {
|
|
2268
|
+
const result = buildSingleTable(geomType, wkbs, indices, attributes, globalBounds);
|
|
2269
|
+
results.push(result);
|
|
2270
|
+
}
|
|
2271
|
+
const mergedBounds = [
|
|
2272
|
+
globalBounds.minX,
|
|
2273
|
+
globalBounds.minY,
|
|
2274
|
+
globalBounds.maxX,
|
|
2275
|
+
globalBounds.maxY
|
|
2276
|
+
];
|
|
2277
|
+
for (const r of results) r.bounds = mergedBounds;
|
|
2278
|
+
return results;
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
// ../../src/lib/utils/hex.ts
|
|
2282
|
+
function generateHexDump(data, bytesPerRow = 16) {
|
|
2283
|
+
const rows = [];
|
|
2284
|
+
for (let i = 0; i < data.length; i += bytesPerRow) {
|
|
2285
|
+
const slice = data.slice(i, i + bytesPerRow);
|
|
2286
|
+
const offset = i.toString(16).padStart(8, "0");
|
|
2287
|
+
const hex = [];
|
|
2288
|
+
for (let j = 0; j < bytesPerRow; j++) {
|
|
2289
|
+
if (j < slice.length) {
|
|
2290
|
+
hex.push(slice[j].toString(16).padStart(2, "0"));
|
|
2291
|
+
} else {
|
|
2292
|
+
hex.push(" ");
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
let ascii = "";
|
|
2296
|
+
for (let j = 0; j < slice.length; j++) {
|
|
2297
|
+
const byte = slice[j];
|
|
2298
|
+
ascii += byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : ".";
|
|
2299
|
+
}
|
|
2300
|
+
rows.push({ offset, hex, ascii });
|
|
2301
|
+
}
|
|
2302
|
+
return rows;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
// ../../src/lib/utils/local-storage.ts
|
|
2306
|
+
function loadFromStorage(key, defaultValue) {
|
|
2307
|
+
if (typeof window === "undefined") return defaultValue;
|
|
2308
|
+
try {
|
|
2309
|
+
const raw = localStorage.getItem(key);
|
|
2310
|
+
if (raw) return JSON.parse(raw);
|
|
2311
|
+
} catch {
|
|
2312
|
+
}
|
|
2313
|
+
return defaultValue;
|
|
2314
|
+
}
|
|
2315
|
+
function persistToStorage(key, value) {
|
|
2316
|
+
if (typeof window === "undefined") return;
|
|
2317
|
+
try {
|
|
2318
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
2319
|
+
} catch {
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
// ../../src/lib/utils/markdown-sql.ts
|
|
2324
|
+
async function parseMarkdownDocument(markdown) {
|
|
2325
|
+
let frontmatter = {};
|
|
2326
|
+
let content = markdown;
|
|
2327
|
+
const fmMatch = markdown.match(/^---\n([\s\S]*?)\n---\n/);
|
|
2328
|
+
if (fmMatch) {
|
|
2329
|
+
try {
|
|
2330
|
+
const { default: YAML } = await import('yaml');
|
|
2331
|
+
frontmatter = YAML.parse(fmMatch[1]) || {};
|
|
2332
|
+
} catch {
|
|
2333
|
+
}
|
|
2334
|
+
content = markdown.slice(fmMatch[0].length);
|
|
2335
|
+
}
|
|
2336
|
+
const sqlBlocks = [];
|
|
2337
|
+
const lines = content.split("\n");
|
|
2338
|
+
let i = 0;
|
|
2339
|
+
while (i < lines.length) {
|
|
2340
|
+
const line = lines[i];
|
|
2341
|
+
const match = line.match(/^```sql\s+(\w[\w-]*)\s*$/);
|
|
2342
|
+
if (match) {
|
|
2343
|
+
const name = match[1];
|
|
2344
|
+
const startLine = i;
|
|
2345
|
+
const sqlLines = [];
|
|
2346
|
+
i++;
|
|
2347
|
+
while (i < lines.length && lines[i] !== "```") {
|
|
2348
|
+
sqlLines.push(lines[i]);
|
|
2349
|
+
i++;
|
|
2350
|
+
}
|
|
2351
|
+
sqlBlocks.push({
|
|
2352
|
+
name,
|
|
2353
|
+
sql: sqlLines.join("\n"),
|
|
2354
|
+
startLine,
|
|
2355
|
+
endLine: i
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
i++;
|
|
2359
|
+
}
|
|
2360
|
+
return { frontmatter, content, sqlBlocks };
|
|
2361
|
+
}
|
|
2362
|
+
function interpolateTemplates(text, queryResults) {
|
|
2363
|
+
return text.replace(/\{(\w+)\.rows\[(\d+)\]\.(\w+)\}/g, (match, queryName, rowIdx, colName) => {
|
|
2364
|
+
const rows = queryResults.get(queryName);
|
|
2365
|
+
if (!rows) return match;
|
|
2366
|
+
const row = rows[parseInt(rowIdx, 10)];
|
|
2367
|
+
if (!row) return match;
|
|
2368
|
+
const value = row[colName];
|
|
2369
|
+
return value !== void 0 ? String(value) : match;
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
function markSqlBlocks(content) {
|
|
2373
|
+
return content.replace(
|
|
2374
|
+
/```sql\s+(\w[\w-]*)\s*\n([\s\S]*?)```/g,
|
|
2375
|
+
(_, name) => `<div data-sql-block="${name}"></div>`
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
// ../../src/lib/utils/parquet-metadata.ts
|
|
2380
|
+
function mapParquetType(col) {
|
|
2381
|
+
const lt = col.logical_type;
|
|
2382
|
+
if (lt) {
|
|
2383
|
+
if (lt.type === "GEOMETRY" || lt.type === "GEOGRAPHY") return "GEOMETRY";
|
|
2384
|
+
if (lt.type === "STRING" || lt.type === "UTF8") return "VARCHAR";
|
|
2385
|
+
if (lt.type === "JSON") return "JSON";
|
|
2386
|
+
if (lt.type === "UUID") return "UUID";
|
|
2387
|
+
if (lt.type === "ENUM") return "VARCHAR";
|
|
2388
|
+
if (lt.type === "INT" || lt.type === "INTEGER") {
|
|
2389
|
+
const bits = lt.bitWidth ?? 32;
|
|
2390
|
+
const signed = lt.isSigned !== false;
|
|
2391
|
+
if (bits <= 8) return signed ? "TINYINT" : "UTINYINT";
|
|
2392
|
+
if (bits <= 16) return signed ? "SMALLINT" : "USMALLINT";
|
|
2393
|
+
if (bits <= 32) return signed ? "INTEGER" : "UINTEGER";
|
|
2394
|
+
return signed ? "BIGINT" : "UBIGINT";
|
|
2395
|
+
}
|
|
2396
|
+
if (lt.type === "DECIMAL") return `DECIMAL(${lt.precision ?? 18},${lt.scale ?? 0})`;
|
|
2397
|
+
if (lt.type === "DATE") return "DATE";
|
|
2398
|
+
if (lt.type === "TIME") return "TIME";
|
|
2399
|
+
if (lt.type === "TIMESTAMP") return "TIMESTAMP";
|
|
2400
|
+
if (lt.type === "BSON") return "BLOB";
|
|
2401
|
+
}
|
|
2402
|
+
const ct = col.converted_type;
|
|
2403
|
+
if (ct === "UTF8") return "VARCHAR";
|
|
2404
|
+
if (ct === "JSON") return "JSON";
|
|
2405
|
+
if (ct === "DATE") return "DATE";
|
|
2406
|
+
if (ct === "TIMESTAMP_MILLIS" || ct === "TIMESTAMP_MICROS") return "TIMESTAMP";
|
|
2407
|
+
if (ct === "DECIMAL") return `DECIMAL(${col.precision ?? 18},${col.scale ?? 0})`;
|
|
2408
|
+
if (ct === "INT_8") return "TINYINT";
|
|
2409
|
+
if (ct === "INT_16") return "SMALLINT";
|
|
2410
|
+
if (ct === "INT_32") return "INTEGER";
|
|
2411
|
+
if (ct === "INT_64") return "BIGINT";
|
|
2412
|
+
if (ct === "UINT_8") return "UTINYINT";
|
|
2413
|
+
if (ct === "UINT_16") return "USMALLINT";
|
|
2414
|
+
if (ct === "UINT_32") return "UINTEGER";
|
|
2415
|
+
if (ct === "UINT_64") return "UBIGINT";
|
|
2416
|
+
const pt = col.type;
|
|
2417
|
+
if (pt === "BOOLEAN") return "BOOLEAN";
|
|
2418
|
+
if (pt === "INT32") return "INTEGER";
|
|
2419
|
+
if (pt === "INT64") return "BIGINT";
|
|
2420
|
+
if (pt === "INT96") return "TIMESTAMP";
|
|
2421
|
+
if (pt === "FLOAT") return "FLOAT";
|
|
2422
|
+
if (pt === "DOUBLE") return "DOUBLE";
|
|
2423
|
+
if (pt === "BYTE_ARRAY") return "BLOB";
|
|
2424
|
+
if (pt === "FIXED_LEN_BYTE_ARRAY") return "BLOB";
|
|
2425
|
+
return "VARCHAR";
|
|
2426
|
+
}
|
|
2427
|
+
async function readParquetMetadata(url) {
|
|
2428
|
+
const { parquetMetadataAsync, asyncBufferFromUrl } = await import('hyparquet');
|
|
2429
|
+
const file = await asyncBufferFromUrl({ url });
|
|
2430
|
+
const metadata = await parquetMetadataAsync(file);
|
|
2431
|
+
const rowCount = metadata.row_groups.reduce(
|
|
2432
|
+
(sum, rg) => sum + Number(rg.num_rows),
|
|
2433
|
+
0
|
|
2434
|
+
);
|
|
2435
|
+
const schema = metadata.schema.slice(1).filter((col) => col.num_children === void 0).map((col) => ({
|
|
2436
|
+
name: col.name,
|
|
2437
|
+
type: mapParquetType(col)
|
|
2438
|
+
}));
|
|
2439
|
+
let geo = null;
|
|
2440
|
+
let legacyGeoParquet = false;
|
|
2441
|
+
const geoKv = metadata.key_value_metadata?.find((kv) => kv.key === "geo");
|
|
2442
|
+
if (geoKv) {
|
|
2443
|
+
try {
|
|
2444
|
+
const geoJson = JSON.parse(geoKv.value ?? "");
|
|
2445
|
+
if (geoJson.schema_version && !geoJson.version) {
|
|
2446
|
+
legacyGeoParquet = true;
|
|
2447
|
+
}
|
|
2448
|
+
geo = {
|
|
2449
|
+
primaryColumn: geoJson.primary_column ?? "geometry",
|
|
2450
|
+
columns: {}
|
|
2451
|
+
};
|
|
2452
|
+
if (geoJson.columns) {
|
|
2453
|
+
for (const [colName, colMeta] of Object.entries(geoJson.columns)) {
|
|
2454
|
+
geo.columns[colName] = {
|
|
2455
|
+
encoding: colMeta.encoding ?? "WKB",
|
|
2456
|
+
geometryTypes: colMeta.geometry_types ?? [],
|
|
2457
|
+
crs: colMeta.crs ?? null,
|
|
2458
|
+
bbox: colMeta.bbox
|
|
2459
|
+
};
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
} catch {
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
const createdBy = metadata.created_by ?? null;
|
|
2466
|
+
const numRowGroups = metadata.row_groups.length;
|
|
2467
|
+
let compression = null;
|
|
2468
|
+
if (numRowGroups > 0 && metadata.row_groups[0].columns) {
|
|
2469
|
+
const codecs = /* @__PURE__ */ new Set();
|
|
2470
|
+
for (const col of metadata.row_groups[0].columns) {
|
|
2471
|
+
const codec = col.meta_data?.codec;
|
|
2472
|
+
if (codec) codecs.add(codec);
|
|
2473
|
+
}
|
|
2474
|
+
if (codecs.size === 1) {
|
|
2475
|
+
compression = [...codecs][0];
|
|
2476
|
+
} else if (codecs.size > 1) {
|
|
2477
|
+
compression = [...codecs].join(", ");
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
return { rowCount, schema, geo, legacyGeoParquet, createdBy, numRowGroups, compression };
|
|
2481
|
+
}
|
|
2482
|
+
function extractEpsgFromGeoMeta(geo) {
|
|
2483
|
+
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2484
|
+
if (!primaryCol?.crs) return null;
|
|
2485
|
+
const crs = primaryCol.crs;
|
|
2486
|
+
if (crs.type === "name" && crs.properties?.name?.includes("CRS84")) return null;
|
|
2487
|
+
if (crs.id?.authority === "EPSG") {
|
|
2488
|
+
const code = crs.id.code;
|
|
2489
|
+
if (WGS84_CODES.has(code)) return null;
|
|
2490
|
+
return `EPSG:${code}`;
|
|
2491
|
+
}
|
|
2492
|
+
return null;
|
|
2493
|
+
}
|
|
2494
|
+
function extractGeometryTypes(geo) {
|
|
2495
|
+
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2496
|
+
if (!primaryCol?.geometryTypes?.length) return [];
|
|
2497
|
+
const typeMap = {
|
|
2498
|
+
Point: "point",
|
|
2499
|
+
LineString: "linestring",
|
|
2500
|
+
Polygon: "polygon",
|
|
2501
|
+
MultiPoint: "multipoint",
|
|
2502
|
+
MultiLineString: "multilinestring",
|
|
2503
|
+
MultiPolygon: "multipolygon"
|
|
2504
|
+
};
|
|
2505
|
+
const types = [];
|
|
2506
|
+
for (const raw of primaryCol.geometryTypes) {
|
|
2507
|
+
const base = raw.split(" ")[0];
|
|
2508
|
+
const mapped = typeMap[base];
|
|
2509
|
+
if (mapped && !types.includes(mapped)) types.push(mapped);
|
|
2510
|
+
}
|
|
2511
|
+
return types;
|
|
2512
|
+
}
|
|
2513
|
+
function extractBounds(geo) {
|
|
2514
|
+
const primaryCol = geo.columns[geo.primaryColumn];
|
|
2515
|
+
if (!primaryCol?.bbox || primaryCol.bbox.length < 4) return null;
|
|
2516
|
+
return [primaryCol.bbox[0], primaryCol.bbox[1], primaryCol.bbox[2], primaryCol.bbox[3]];
|
|
2517
|
+
}
|
|
2273
2518
|
|
|
2274
2519
|
// ../../src/lib/utils/storage-url.ts
|
|
2275
2520
|
function buildSchemeMap() {
|
|
@@ -2847,6 +3092,6 @@ function isWKT(value) {
|
|
|
2847
3092
|
return WKT_TYPES.some((t) => s.startsWith(t) || s.startsWith(`MULTI${t}`));
|
|
2848
3093
|
}
|
|
2849
3094
|
|
|
2850
|
-
export { COPY_FEEDBACK_MS, DEFAULT_TARGET_CRS, DUCKDB_INIT_TIMEOUT_MS, LAYER_HUE_MULTIPLIER, MAX_QUERY_HISTORY_ENTRIES, QueryCancelledError, SQL_PREVIEW_LENGTH, STORAGE_KEYS, UrlAdapter, VIEWER_DIR_EXTENSIONS, WGS84_CODES, buildDuckDbSource, buildGeoArrowTables, classifyType, describeParseResult, extractBounds, extractEpsgFromGeoMeta, extractGeometryTypes, findGeoColumn, findGeoColumnFromRows, formatDate, formatFileSize, formatValue, generateHexDump, getDuckDbReadFn, getFileExtension, getFileTypeInfo, getMimeType, getViewerKind, handleLoadError, isCloudNativeFormat, isQueryable, jsonReplacerBigInt, looksLikeUrl, normalizeGeomType, parseStorageUrl, parseWKB, readParquetMetadata, toBinary, typeBadgeClass, typeColor, typeLabel };
|
|
3095
|
+
export { COPY_FEEDBACK_MS, DEFAULT_TARGET_CRS, DUCKDB_INIT_TIMEOUT_MS, LAYER_HUE_MULTIPLIER, MAX_QUERY_HISTORY_ENTRIES, PROVIDERS, PROVIDER_IDS, QueryCancelledError, SF_LABELS, SQL_PREVIEW_LENGTH, STORAGE_KEYS, UrlAdapter, VIEWER_DIR_EXTENSIONS, WGS84_CODES, buildDataTypeLabel, buildDuckDbSource, buildEndpointFromTemplate, buildGeoArrowTables, buildProviderBaseUrl, clampBounds, classifyType, describeParseResult, escapeCsvField, extractBounds, extractEpsgFromGeoMeta, extractGeometryTypes, findGeoColumn, findGeoColumnFromRows, formatDate, formatFileSize, formatValue, generateHexDump, getDuckDbReadFn, getFileExtension, getFileTypeInfo, getMimeType, getNativeScheme, getProvider, getViewerKind, handleLoadError, interpolateTemplates, isCloudNativeFormat, isGcsProvider, isQueryable, jsonReplacerBigInt, loadFromStorage, looksLikeUrl, markSqlBlocks, normalizeGeomType, parseMarkdownDocument, parseStorageUrl, parseWKB, persistToStorage, readParquetMetadata, resolveCloudUrl, safeClamp, safeDecodeURIComponent, serializeToCsv, serializeToJson, sortFileEntries, toBinary, toggleSortField, typeBadgeClass, typeColor, typeLabel };
|
|
2851
3096
|
//# sourceMappingURL=index.js.map
|
|
2852
3097
|
//# sourceMappingURL=index.js.map
|