@loaders.gl/json 4.0.0-alpha.24 → 4.0.0-alpha.26
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/dist/dist.min.js +96 -56
- package/dist/es5/geojson-loader.js +14 -5
- package/dist/es5/geojson-loader.js.map +1 -1
- package/dist/es5/geojson-writer.js.map +1 -1
- package/dist/es5/json-loader.js +1 -1
- package/dist/es5/json-writer.js +1 -1
- package/dist/es5/json-writer.js.map +1 -1
- package/dist/es5/lib/encoder-utils/encode-table-row.js +54 -0
- package/dist/es5/lib/encoder-utils/encode-table-row.js.map +1 -0
- package/dist/es5/lib/encoder-utils/encode-utils.js.map +1 -0
- package/dist/es5/lib/encoder-utils/utf8-encoder.js.map +1 -0
- package/dist/es5/lib/encoders/geojson-encoder.js +47 -84
- package/dist/es5/lib/encoders/geojson-encoder.js.map +1 -1
- package/dist/es5/lib/encoders/json-encoder.js +3 -3
- package/dist/es5/lib/encoders/json-encoder.js.map +1 -1
- package/dist/es5/ndgeoson-loader.js +1 -1
- package/dist/es5/ndjson-loader.js +1 -1
- package/dist/esm/geojson-loader.js +14 -5
- package/dist/esm/geojson-loader.js.map +1 -1
- package/dist/esm/geojson-writer.js.map +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/json-writer.js +1 -1
- package/dist/esm/json-writer.js.map +1 -1
- package/dist/esm/lib/encoder-utils/encode-table-row.js +44 -0
- package/dist/esm/lib/encoder-utils/encode-table-row.js.map +1 -0
- package/dist/esm/lib/encoder-utils/encode-utils.js.map +1 -0
- package/dist/esm/lib/encoder-utils/utf8-encoder.js.map +1 -0
- package/dist/esm/lib/encoders/geojson-encoder.js +9 -52
- package/dist/esm/lib/encoders/geojson-encoder.js.map +1 -1
- package/dist/esm/lib/encoders/json-encoder.js +3 -3
- package/dist/esm/lib/encoders/json-encoder.js.map +1 -1
- package/dist/esm/ndgeoson-loader.js +1 -1
- package/dist/esm/ndjson-loader.js +1 -1
- package/dist/geojson-loader.d.ts.map +1 -1
- package/dist/geojson-worker.js +13 -182
- package/dist/geojson-writer.d.ts +8 -3
- package/dist/geojson-writer.d.ts.map +1 -1
- package/dist/json-writer.d.ts +13 -3
- package/dist/json-writer.d.ts.map +1 -1
- package/dist/lib/encoder-utils/encode-table-row.d.ts +7 -0
- package/dist/lib/encoder-utils/encode-table-row.d.ts.map +1 -0
- package/dist/lib/encoder-utils/encode-utils.d.ts.map +1 -0
- package/dist/lib/encoder-utils/utf8-encoder.d.ts.map +1 -0
- package/dist/lib/encoders/geojson-encoder.d.ts +2 -8
- package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/json-encoder.d.ts +1 -10
- package/dist/lib/encoders/json-encoder.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/geojson-loader.ts +19 -5
- package/src/geojson-writer.ts +8 -3
- package/src/json-writer.ts +12 -4
- package/src/lib/encoder-utils/encode-table-row.ts +69 -0
- package/src/lib/encoders/geojson-encoder.ts +15 -78
- package/src/lib/encoders/json-encoder.ts +3 -11
- package/dist/es5/lib/encoders/encode-utils.js.map +0 -1
- package/dist/es5/lib/encoders/utf8-encoder.js.map +0 -1
- package/dist/esm/lib/encoders/encode-utils.js.map +0 -1
- package/dist/esm/lib/encoders/utf8-encoder.js.map +0 -1
- package/dist/lib/encoders/encode-utils.d.ts.map +0 -1
- package/dist/lib/encoders/utf8-encoder.d.ts.map +0 -1
- /package/dist/es5/lib/{encoders → encoder-utils}/encode-utils.js +0 -0
- /package/dist/es5/lib/{encoders → encoder-utils}/utf8-encoder.js +0 -0
- /package/dist/esm/lib/{encoders → encoder-utils}/encode-utils.js +0 -0
- /package/dist/esm/lib/{encoders → encoder-utils}/utf8-encoder.js +0 -0
- /package/dist/lib/{encoders → encoder-utils}/encode-utils.d.ts +0 -0
- /package/dist/lib/{encoders → encoder-utils}/utf8-encoder.d.ts +0 -0
- /package/src/lib/{encoders → encoder-utils}/encode-utils.ts +0 -0
- /package/src/lib/{encoders → encoder-utils}/utf8-encoder.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-encoder.js","names":["getTableLength","
|
|
1
|
+
{"version":3,"file":"geojson-encoder.js","names":["getTableLength","detectGeometryColumnIndex","encodeTableRow","Utf8ArrayBufferEncoder","encodeTableAsGeojsonInBatches","batchIterator","inputOpts","arguments","length","undefined","options","geojson","chunkSize","utf8Encoder","featureArray","push","geometryColumn","isFirstLine","start","tableBatch","end","rowIndex","isFull","getArrayBufferBatch","arrayBufferBatch","byteLength","e","Promise","reject"],"sources":["../../../../src/lib/encoders/geojson-encoder.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright 2022 Foursquare Labs, Inc.\n\nimport type {TableBatch} from '@loaders.gl/schema';\nimport {getTableLength} from '@loaders.gl/schema';\nimport {detectGeometryColumnIndex} from '../encoder-utils/encode-utils';\nimport {encodeTableRow} from '../encoder-utils/encode-table-row';\nimport {Utf8ArrayBufferEncoder} from '../encoder-utils/utf8-encoder';\nimport type {GeoJSONWriterOptions} from '../../geojson-writer';\n\n/**\n * Encode a table as GeoJSON\n */\n// eslint-disable-next-line max-statements\nexport async function* encodeTableAsGeojsonInBatches(\n batchIterator: AsyncIterable<TableBatch>, // | Iterable<TableBatch>,\n inputOpts: GeoJSONWriterOptions = {}\n): AsyncIterable<ArrayBuffer> {\n // @ts-expect-error\n const options: Required<GeoJSONWriterOptions> = {geojson: {}, chunkSize: 10000, ...inputOpts};\n\n const utf8Encoder = new Utf8ArrayBufferEncoder(options.chunkSize);\n\n if (!options.geojson.featureArray) {\n utf8Encoder.push('{\\n', '\"type\": \"FeatureCollection\",\\n', '\"features\":\\n');\n }\n utf8Encoder.push('['); // Note no newline\n\n let geometryColumn = options.geojson.geometryColumn;\n\n let isFirstLine = true;\n\n let start = 0;\n for await (const tableBatch of batchIterator) {\n const end = start + getTableLength(tableBatch);\n\n // Deduce geometry column if not already done\n if (!geometryColumn) {\n geometryColumn = geometryColumn || detectGeometryColumnIndex(tableBatch);\n }\n\n for (let rowIndex = start; rowIndex < end; ++rowIndex) {\n // Add a comma except on final feature\n if (!isFirstLine) {\n utf8Encoder.push(',');\n }\n utf8Encoder.push('\\n');\n isFirstLine = false;\n\n encodeTableRow(tableBatch, rowIndex, geometryColumn, utf8Encoder);\n\n // eslint-disable-next-line max-depth\n if (utf8Encoder.isFull()) {\n yield utf8Encoder.getArrayBufferBatch();\n }\n\n start = end;\n }\n\n const arrayBufferBatch = utf8Encoder.getArrayBufferBatch();\n if (arrayBufferBatch.byteLength > 0) {\n yield arrayBufferBatch;\n }\n }\n\n utf8Encoder.push('\\n');\n\n // Add completing rows and emit final batch\n utf8Encoder.push(']\\n');\n if (!options.geojson.featureArray) {\n utf8Encoder.push('}');\n }\n\n // Note: Since we pushed a few final lines, the last batch will always exist, no need to check first\n yield utf8Encoder.getArrayBufferBatch();\n}\n"],"mappings":"AAIA,SAAQA,cAAc,QAAO,oBAAoB;AACjD,SAAQC,yBAAyB,QAAO,+BAA+B;AACvE,SAAQC,cAAc,QAAO,mCAAmC;AAChE,SAAQC,sBAAsB,QAAO,+BAA+B;AAOpE,OAAO,SAAgBC,6BAA6BA,CAClDC,aAAwC;EAAA;IAAA,IACxCC,SAA+B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAA,0BACR;MAE5B,MAAMG,OAAuC,GAAG;QAACC,OAAO,EAAE,CAAC,CAAC;QAAEC,SAAS,EAAE,KAAK;QAAE,GAAGN;MAAS,CAAC;MAE7F,MAAMO,WAAW,GAAG,IAAIV,sBAAsB,CAACO,OAAO,CAACE,SAAS,CAAC;MAEjE,IAAI,CAACF,OAAO,CAACC,OAAO,CAACG,YAAY,EAAE;QACjCD,WAAW,CAACE,IAAI,CAAC,KAAK,EAAE,gCAAgC,EAAE,eAAe,CAAC;MAC5E;MACAF,WAAW,CAACE,IAAI,CAAC,GAAG,CAAC;MAErB,IAAIC,cAAc,GAAGN,OAAO,CAACC,OAAO,CAACK,cAAc;MAEnD,IAAIC,WAAW,GAAG,IAAI;MAEtB,IAAIC,KAAK,GAAG,CAAC;MACb,WAAW,MAAMC,UAAU,IAAId,aAAa,EAAE;QAC5C,MAAMe,GAAG,GAAGF,KAAK,GAAGlB,cAAc,CAACmB,UAAU,CAAC;QAG9C,IAAI,CAACH,cAAc,EAAE;UACnBA,cAAc,GAAGA,cAAc,IAAIf,yBAAyB,CAACkB,UAAU,CAAC;QAC1E;QAEA,KAAK,IAAIE,QAAQ,GAAGH,KAAK,EAAEG,QAAQ,GAAGD,GAAG,EAAE,EAAEC,QAAQ,EAAE;UAErD,IAAI,CAACJ,WAAW,EAAE;YAChBJ,WAAW,CAACE,IAAI,CAAC,GAAG,CAAC;UACvB;UACAF,WAAW,CAACE,IAAI,CAAC,IAAI,CAAC;UACtBE,WAAW,GAAG,KAAK;UAEnBf,cAAc,CAACiB,UAAU,EAAEE,QAAQ,EAAEL,cAAc,EAAEH,WAAW,CAAC;UAGjE,IAAIA,WAAW,CAACS,MAAM,CAAC,CAAC,EAAE;YACxB,MAAMT,WAAW,CAACU,mBAAmB,CAAC,CAAC;UACzC;UAEAL,KAAK,GAAGE,GAAG;QACb;QAEA,MAAMI,gBAAgB,GAAGX,WAAW,CAACU,mBAAmB,CAAC,CAAC;QAC1D,IAAIC,gBAAgB,CAACC,UAAU,GAAG,CAAC,EAAE;UACnC,MAAMD,gBAAgB;QACxB;MACF;MAEAX,WAAW,CAACE,IAAI,CAAC,IAAI,CAAC;MAGtBF,WAAW,CAACE,IAAI,CAAC,KAAK,CAAC;MACvB,IAAI,CAACL,OAAO,CAACC,OAAO,CAACG,YAAY,EAAE;QACjCD,WAAW,CAACE,IAAI,CAAC,GAAG,CAAC;MACvB;MAGA,MAAMF,WAAW,CAACU,mBAAmB,CAAC,CAAC;IACzC,CAAC;EAAA,SAAAG,CAAA;IAAA,OAAAC,OAAA,CAAAC,MAAA,CAAAF,CAAA;EAAA;AAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { makeRowIterator } from '@loaders.gl/schema';
|
|
2
|
-
export function encodeTableAsJSON(table) {
|
|
3
|
-
|
|
4
|
-
const shape = options.shape || 'object-row-table';
|
|
2
|
+
export function encodeTableAsJSON(table, options) {
|
|
3
|
+
var _options$json;
|
|
4
|
+
const shape = (options === null || options === void 0 ? void 0 : (_options$json = options.json) === null || _options$json === void 0 ? void 0 : _options$json.shape) || 'object-row-table';
|
|
5
5
|
const strings = [];
|
|
6
6
|
const rowIterator = makeRowIterator(table, shape);
|
|
7
7
|
for (const row of rowIterator) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-encoder.js","names":["makeRowIterator","encodeTableAsJSON","table","options","
|
|
1
|
+
{"version":3,"file":"json-encoder.js","names":["makeRowIterator","encodeTableAsJSON","table","options","_options$json","shape","json","strings","rowIterator","row","push","JSON","stringify","concat","join"],"sources":["../../../../src/lib/encoders/json-encoder.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright 2022 Foursquare Labs, Inc.\n\nimport {Table, makeRowIterator} from '@loaders.gl/schema';\nimport type {JSONWriterOptions} from '../../json-writer';\n\n/**\n * Encode a table as a JSON string\n */\nexport function encodeTableAsJSON(table: Table, options?: JSONWriterOptions): string {\n const shape = options?.json?.shape || 'object-row-table';\n\n const strings: string[] = [];\n const rowIterator = makeRowIterator(table, shape);\n for (const row of rowIterator) {\n // Round elements etc\n // processRow(wrappedRow, table.schema);\n // const wrappedRow = options.wrapper ? options.wrapper(row) : row;\n strings.push(JSON.stringify(row));\n }\n return `[${strings.join(',')}]`;\n}\n"],"mappings":"AAGA,SAAeA,eAAe,QAAO,oBAAoB;AAMzD,OAAO,SAASC,iBAAiBA,CAACC,KAAY,EAAEC,OAA2B,EAAU;EAAA,IAAAC,aAAA;EACnF,MAAMC,KAAK,GAAG,CAAAF,OAAO,aAAPA,OAAO,wBAAAC,aAAA,GAAPD,OAAO,CAAEG,IAAI,cAAAF,aAAA,uBAAbA,aAAA,CAAeC,KAAK,KAAI,kBAAkB;EAExD,MAAME,OAAiB,GAAG,EAAE;EAC5B,MAAMC,WAAW,GAAGR,eAAe,CAACE,KAAK,EAAEG,KAAK,CAAC;EACjD,KAAK,MAAMI,GAAG,IAAID,WAAW,EAAE;IAI7BD,OAAO,CAACG,IAAI,CAACC,IAAI,CAACC,SAAS,CAACH,GAAG,CAAC,CAAC;EACnC;EACA,WAAAI,MAAA,CAAWN,OAAO,CAACO,IAAI,CAAC,GAAG,CAAC;AAC9B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseNDJSONSync } from './lib/parsers/parse-ndjson';
|
|
2
2
|
import { parseNDJSONInBatches } from './lib/parsers/parse-ndjson-in-batches';
|
|
3
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
3
|
+
const VERSION = typeof "4.0.0-alpha.26" !== 'undefined' ? "4.0.0-alpha.26" : 'latest';
|
|
4
4
|
export const NDJSONLoader = {
|
|
5
5
|
name: 'NDJSON',
|
|
6
6
|
id: 'ndjson',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseNDJSONSync } from './lib/parsers/parse-ndjson';
|
|
2
2
|
import { parseNDJSONInBatches } from './lib/parsers/parse-ndjson-in-batches';
|
|
3
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
3
|
+
const VERSION = typeof "4.0.0-alpha.26" !== 'undefined' ? "4.0.0-alpha.26" : 'latest';
|
|
4
4
|
export const NDJSONLoader = {
|
|
5
5
|
name: 'NDJSON',
|
|
6
6
|
id: 'ndjson',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-loader.d.ts","sourceRoot":"","sources":["../src/geojson-loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"geojson-loader.d.ts","sourceRoot":"","sources":["../src/geojson-loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAC,OAAO,EAAgB,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AASrD,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG;IACrD,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,kBAAkB,CAAC;KAC5B,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,MAAM,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;KAC/B,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,oBAAoB,CAsBjF,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,oBAAoB,CAOrF,CAAC"}
|
package/dist/geojson-worker.js
CHANGED
|
@@ -1479,184 +1479,6 @@
|
|
|
1479
1479
|
}
|
|
1480
1480
|
};
|
|
1481
1481
|
|
|
1482
|
-
// ../schema/src/lib/table/simple-table/data-type.ts
|
|
1483
|
-
function getDataTypeFromValue(value, defaultNumberType = "float32") {
|
|
1484
|
-
if (value instanceof Date) {
|
|
1485
|
-
return "date-millisecond";
|
|
1486
|
-
}
|
|
1487
|
-
if (value instanceof Number) {
|
|
1488
|
-
return defaultNumberType;
|
|
1489
|
-
}
|
|
1490
|
-
if (typeof value === "string") {
|
|
1491
|
-
return "utf8";
|
|
1492
|
-
}
|
|
1493
|
-
if (value === null || value === "undefined") {
|
|
1494
|
-
return "null";
|
|
1495
|
-
}
|
|
1496
|
-
return "null";
|
|
1497
|
-
}
|
|
1498
|
-
function getDataTypeFromArray(array) {
|
|
1499
|
-
let type = getDataTypeFromTypedArray(array);
|
|
1500
|
-
if (type !== "null") {
|
|
1501
|
-
return { type, nullable: false };
|
|
1502
|
-
}
|
|
1503
|
-
if (array.length > 0) {
|
|
1504
|
-
type = getDataTypeFromValue(array[0]);
|
|
1505
|
-
return { type, nullable: true };
|
|
1506
|
-
}
|
|
1507
|
-
return { type: "null", nullable: true };
|
|
1508
|
-
}
|
|
1509
|
-
function getDataTypeFromTypedArray(array) {
|
|
1510
|
-
switch (array.constructor) {
|
|
1511
|
-
case Int8Array:
|
|
1512
|
-
return "int8";
|
|
1513
|
-
case Uint8Array:
|
|
1514
|
-
case Uint8ClampedArray:
|
|
1515
|
-
return "uint8";
|
|
1516
|
-
case Int16Array:
|
|
1517
|
-
return "int16";
|
|
1518
|
-
case Uint16Array:
|
|
1519
|
-
return "uint16";
|
|
1520
|
-
case Int32Array:
|
|
1521
|
-
return "int32";
|
|
1522
|
-
case Uint32Array:
|
|
1523
|
-
return "uint32";
|
|
1524
|
-
case Float32Array:
|
|
1525
|
-
return "float32";
|
|
1526
|
-
case Float64Array:
|
|
1527
|
-
return "float64";
|
|
1528
|
-
default:
|
|
1529
|
-
return "null";
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
// ../schema/src/lib/table/simple-table/table-schema.ts
|
|
1534
|
-
function deduceTableSchema(table) {
|
|
1535
|
-
switch (table.shape) {
|
|
1536
|
-
case "array-row-table":
|
|
1537
|
-
case "object-row-table":
|
|
1538
|
-
return deduceSchemaFromRows(table.data);
|
|
1539
|
-
case "columnar-table":
|
|
1540
|
-
return deduceSchemaFromColumns(table.data);
|
|
1541
|
-
case "arrow-table":
|
|
1542
|
-
default:
|
|
1543
|
-
throw new Error("Deduce schema");
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
function deduceSchemaFromColumns(columnarTable) {
|
|
1547
|
-
const fields = [];
|
|
1548
|
-
for (const [columnName, column] of Object.entries(columnarTable)) {
|
|
1549
|
-
const field = deduceFieldFromColumn(column, columnName);
|
|
1550
|
-
fields.push(field);
|
|
1551
|
-
}
|
|
1552
|
-
return { fields, metadata: {} };
|
|
1553
|
-
}
|
|
1554
|
-
function deduceSchemaFromRows(rowTable) {
|
|
1555
|
-
if (!rowTable.length) {
|
|
1556
|
-
throw new Error("deduce from empty table");
|
|
1557
|
-
}
|
|
1558
|
-
const fields = [];
|
|
1559
|
-
const row0 = rowTable[0];
|
|
1560
|
-
for (const [columnName, value] of Object.entries(row0)) {
|
|
1561
|
-
fields.push(deduceFieldFromValue(value, columnName));
|
|
1562
|
-
}
|
|
1563
|
-
return { fields, metadata: {} };
|
|
1564
|
-
}
|
|
1565
|
-
function deduceFieldFromColumn(column, name) {
|
|
1566
|
-
if (ArrayBuffer.isView(column)) {
|
|
1567
|
-
const type = getDataTypeFromArray(column);
|
|
1568
|
-
return {
|
|
1569
|
-
name,
|
|
1570
|
-
type: type.type || "null",
|
|
1571
|
-
nullable: type.nullable
|
|
1572
|
-
};
|
|
1573
|
-
}
|
|
1574
|
-
if (Array.isArray(column) && column.length > 0) {
|
|
1575
|
-
const value = column[0];
|
|
1576
|
-
const type = getDataTypeFromValue(value);
|
|
1577
|
-
return {
|
|
1578
|
-
name,
|
|
1579
|
-
type,
|
|
1580
|
-
nullable: true
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
throw new Error("empty table");
|
|
1584
|
-
}
|
|
1585
|
-
function deduceFieldFromValue(value, name) {
|
|
1586
|
-
const type = getDataTypeFromValue(value);
|
|
1587
|
-
return {
|
|
1588
|
-
name,
|
|
1589
|
-
type,
|
|
1590
|
-
nullable: true
|
|
1591
|
-
};
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
|
-
// ../schema/src/lib/table/simple-table/make-table.ts
|
|
1595
|
-
function makeTableFromData(data) {
|
|
1596
|
-
let table;
|
|
1597
|
-
switch (getTableShapeFromData(data)) {
|
|
1598
|
-
case "array-row-table":
|
|
1599
|
-
table = { shape: "array-row-table", data };
|
|
1600
|
-
break;
|
|
1601
|
-
case "object-row-table":
|
|
1602
|
-
table = { shape: "object-row-table", data };
|
|
1603
|
-
break;
|
|
1604
|
-
case "columnar-table":
|
|
1605
|
-
table = { shape: "columnar-table", data };
|
|
1606
|
-
break;
|
|
1607
|
-
default:
|
|
1608
|
-
throw new Error("table");
|
|
1609
|
-
}
|
|
1610
|
-
const schema = deduceTableSchema(table);
|
|
1611
|
-
return { ...table, schema };
|
|
1612
|
-
}
|
|
1613
|
-
function getTableShapeFromData(data) {
|
|
1614
|
-
if (Array.isArray(data)) {
|
|
1615
|
-
if (data.length === 0) {
|
|
1616
|
-
throw new Error("cannot deduce type of empty table");
|
|
1617
|
-
}
|
|
1618
|
-
const firstRow = data[0];
|
|
1619
|
-
if (Array.isArray(firstRow)) {
|
|
1620
|
-
return "array-row-table";
|
|
1621
|
-
}
|
|
1622
|
-
if (firstRow && typeof firstRow === "object") {
|
|
1623
|
-
return "object-row-table";
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
if (data && typeof data === "object") {
|
|
1627
|
-
return "columnar-table";
|
|
1628
|
-
}
|
|
1629
|
-
throw new Error("invalid table");
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
// src/lib/parsers/parse-json.ts
|
|
1633
|
-
function parseJSONSync(jsonText, options) {
|
|
1634
|
-
try {
|
|
1635
|
-
const json = JSON.parse(jsonText);
|
|
1636
|
-
if (options.json?.table) {
|
|
1637
|
-
const data = getFirstArray(json) || json;
|
|
1638
|
-
return makeTableFromData(data);
|
|
1639
|
-
}
|
|
1640
|
-
return json;
|
|
1641
|
-
} catch (error) {
|
|
1642
|
-
throw new Error("JSONLoader: failed to parse JSON");
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
function getFirstArray(json) {
|
|
1646
|
-
if (Array.isArray(json)) {
|
|
1647
|
-
return json;
|
|
1648
|
-
}
|
|
1649
|
-
if (json && typeof json === "object") {
|
|
1650
|
-
for (const value of Object.values(json)) {
|
|
1651
|
-
const array = getFirstArray(value);
|
|
1652
|
-
if (array) {
|
|
1653
|
-
return array;
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
return null;
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
1482
|
// src/lib/clarinet/clarinet.ts
|
|
1661
1483
|
var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
1662
1484
|
var STATE;
|
|
@@ -2432,7 +2254,7 @@ Char: ${this.c}`;
|
|
|
2432
2254
|
}
|
|
2433
2255
|
|
|
2434
2256
|
// src/geojson-loader.ts
|
|
2435
|
-
var VERSION = true ? "4.0.0-alpha.
|
|
2257
|
+
var VERSION = true ? "4.0.0-alpha.26" : "latest";
|
|
2436
2258
|
var GeoJSONWorkerLoader = {
|
|
2437
2259
|
name: "GeoJSON",
|
|
2438
2260
|
id: "geojson",
|
|
@@ -2469,11 +2291,20 @@ Char: ${this.c}`;
|
|
|
2469
2291
|
options = { ...GeoJSONLoader.options, ...options };
|
|
2470
2292
|
options.geojson = { ...GeoJSONLoader.options.geojson, ...options.geojson };
|
|
2471
2293
|
options.gis = options.gis || {};
|
|
2472
|
-
|
|
2473
|
-
|
|
2294
|
+
let geojson;
|
|
2295
|
+
try {
|
|
2296
|
+
geojson = JSON.parse(text);
|
|
2297
|
+
} catch {
|
|
2298
|
+
geojson = {};
|
|
2299
|
+
}
|
|
2300
|
+
const table = {
|
|
2301
|
+
shape: "geojson-table",
|
|
2302
|
+
type: "FeatureCollection",
|
|
2303
|
+
features: geojson?.features || []
|
|
2304
|
+
};
|
|
2474
2305
|
switch (options.gis.format) {
|
|
2475
2306
|
case "binary":
|
|
2476
|
-
return geojsonToBinary(table.
|
|
2307
|
+
return geojsonToBinary(table.features);
|
|
2477
2308
|
default:
|
|
2478
2309
|
return table;
|
|
2479
2310
|
}
|
package/dist/geojson-writer.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type { Writer } from '@loaders.gl/loader-utils';
|
|
1
|
+
import type { Writer, WriterOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
import type { Table, TableBatch } from '@loaders.gl/schema';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export type GeoJSONWriterOptions = WriterOptions & {
|
|
4
|
+
geojson?: {
|
|
5
|
+
featureArray?: boolean;
|
|
6
|
+
geometryColumn?: number | null;
|
|
7
|
+
};
|
|
8
|
+
chunkSize?: number;
|
|
9
|
+
};
|
|
5
10
|
export declare const GeoJSONWriter: Writer<Table, TableBatch, GeoJSONWriterOptions>;
|
|
6
11
|
//# sourceMappingURL=geojson-writer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-writer.d.ts","sourceRoot":"","sources":["../src/geojson-writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"geojson-writer.d.ts","sourceRoot":"","sources":["../src/geojson-writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAC,KAAK,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAG1D,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IACjD,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAChC,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,oBAAoB,CAgBzE,CAAC"}
|
package/dist/json-writer.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import type { Writer } from '@loaders.gl/loader-utils';
|
|
1
|
+
import type { Writer, WriterOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
import type { Table, TableBatch } from '@loaders.gl/schema';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export type JSONWriterOptions = WriterOptions & {
|
|
4
|
+
json?: {
|
|
5
|
+
shape?: 'object-row-table' | 'array-row-table';
|
|
6
|
+
wrapper?: (table: TableJSON) => unknown;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type RowArray = unknown[];
|
|
10
|
+
type RowObject = {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
type TableJSON = RowArray[] | RowObject[];
|
|
5
14
|
export declare const JSONWriter: Writer<Table, TableBatch, JSONWriterOptions>;
|
|
15
|
+
export {};
|
|
6
16
|
//# sourceMappingURL=json-writer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-writer.d.ts","sourceRoot":"","sources":["../src/json-writer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"json-writer.d.ts","sourceRoot":"","sources":["../src/json-writer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAC,KAAK,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAG1D,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG;IAC9C,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,kBAAkB,GAAG,iBAAiB,CAAC;QAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC;KACzC,CAAC;CACH,CAAC;AAEF,KAAK,QAAQ,GAAG,OAAO,EAAE,CAAC;AAC1B,KAAK,SAAS,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC;AAC1C,KAAK,SAAS,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAC;AAE1C,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,iBAAiB,CAYnE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Table } from '@loaders.gl/schema';
|
|
2
|
+
import { Utf8ArrayBufferEncoder } from './utf8-encoder';
|
|
3
|
+
/**
|
|
4
|
+
* Encode a row. Currently this ignores properties in the geometry column.
|
|
5
|
+
*/
|
|
6
|
+
export declare function encodeTableRow(table: Table, rowIndex: number, geometryColumnIndex: number, utf8Encoder: Utf8ArrayBufferEncoder): void;
|
|
7
|
+
//# sourceMappingURL=encode-table-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-table-row.d.ts","sourceRoot":"","sources":["../../../src/lib/encoder-utils/encode-table-row.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAC,sBAAsB,EAAC,MAAM,gBAAgB,CAAC;AAMtD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,WAAW,EAAE,sBAAsB,GAClC,IAAI,CAMN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/encoder-utils/encode-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,EAAsD,MAAM,oBAAoB,CAAC;AAE9F,KAAK,GAAG,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAsB9D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,oBAAoB,GAAE,MAAM,EAAO,GAClC;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CASjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoder-utils/utf8-encoder.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,WAAW,CAAkC;gBAEzC,SAAS,EAAE,MAAM;IAI7B,IAAI,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAOhC,MAAM,IAAI,OAAO;IAIjB,mBAAmB,IAAI,eAAe;IAItC,cAAc,IAAI,MAAM;CAMzB"}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { TableBatch } from '@loaders.gl/schema';
|
|
2
|
-
|
|
3
|
-
geojson?: {
|
|
4
|
-
featureArray?: boolean;
|
|
5
|
-
geometryColumn?: number | null;
|
|
6
|
-
};
|
|
7
|
-
chunkSize?: number;
|
|
8
|
-
};
|
|
1
|
+
import type { TableBatch } from '@loaders.gl/schema';
|
|
2
|
+
import type { GeoJSONWriterOptions } from '../../geojson-writer';
|
|
9
3
|
/**
|
|
10
4
|
* Encode a table as GeoJSON
|
|
11
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/geojson-encoder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geojson-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/geojson-encoder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAKnD,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAE/D;;GAEG;AAEH,wBAAuB,6BAA6B,CAClD,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,0BAA0B;AACpE,SAAS,GAAE,oBAAyB,GACnC,aAAa,CAAC,WAAW,CAAC,CA0D5B"}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { Table } from '@loaders.gl/schema';
|
|
2
|
-
type
|
|
3
|
-
type RowObject = {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
};
|
|
6
|
-
type TableJSON = RowArray[] | RowObject[];
|
|
7
|
-
export type JSONWriterOptions = {
|
|
8
|
-
shape?: 'object-row-table' | 'array-row-table';
|
|
9
|
-
wrapper?: (table: TableJSON) => unknown;
|
|
10
|
-
};
|
|
2
|
+
import type { JSONWriterOptions } from '../../json-writer';
|
|
11
3
|
/**
|
|
12
4
|
* Encode a table as a JSON string
|
|
13
5
|
*/
|
|
14
6
|
export declare function encodeTableAsJSON(table: Table, options?: JSONWriterOptions): string;
|
|
15
|
-
export {};
|
|
16
7
|
//# sourceMappingURL=json-encoder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/json-encoder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,EAAkB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"json-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/json-encoder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,EAAkB,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEzD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAYnF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/json",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.26",
|
|
4
4
|
"description": "Framework-independent loader for JSON and streaming JSON formats",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"build-worker": "esbuild src/workers/geojson-worker.ts --bundle --outfile=dist/geojson-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@loaders.gl/gis": "4.0.0-alpha.
|
|
39
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
40
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
38
|
+
"@loaders.gl/gis": "4.0.0-alpha.26",
|
|
39
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.26",
|
|
40
|
+
"@loaders.gl/schema": "4.0.0-alpha.26"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "91adce71f74dacc7c8bfc379f0d122f2beae70d9"
|
|
43
43
|
}
|
package/src/geojson-loader.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// loaders.gl, MIT license
|
|
2
2
|
|
|
3
3
|
import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
4
|
-
import type {GeoJSON,
|
|
4
|
+
import type {GeoJSON, GeoJSONTable, TableBatch} from '@loaders.gl/schema';
|
|
5
5
|
import type {JSONLoaderOptions} from './json-loader';
|
|
6
6
|
import {geojsonToBinary} from '@loaders.gl/gis';
|
|
7
|
-
import {parseJSONSync} from './lib/parsers/parse-json';
|
|
7
|
+
// import {parseJSONSync} from './lib/parsers/parse-json';
|
|
8
8
|
import {parseJSONInBatches} from './lib/parsers/parse-json-in-batches';
|
|
9
9
|
|
|
10
10
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
@@ -65,11 +65,25 @@ function parseTextSync(text: string, options?: GeoJSONLoaderOptions) {
|
|
|
65
65
|
options = {...GeoJSONLoader.options, ...options};
|
|
66
66
|
options.geojson = {...GeoJSONLoader.options.geojson, ...options.geojson};
|
|
67
67
|
options.gis = options.gis || {};
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
|
|
69
|
+
let geojson;
|
|
70
|
+
try {
|
|
71
|
+
geojson = JSON.parse(text);
|
|
72
|
+
} catch {
|
|
73
|
+
geojson = {};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const table: GeoJSONTable = {
|
|
77
|
+
shape: 'geojson-table',
|
|
78
|
+
// TODO - deduce schema from geojson
|
|
79
|
+
// TODO check that parsed data is of type FeatureCollection
|
|
80
|
+
type: 'FeatureCollection',
|
|
81
|
+
features: geojson?.features || []
|
|
82
|
+
};
|
|
83
|
+
|
|
70
84
|
switch (options.gis.format) {
|
|
71
85
|
case 'binary':
|
|
72
|
-
return geojsonToBinary(table.
|
|
86
|
+
return geojsonToBinary(table.features);
|
|
73
87
|
default:
|
|
74
88
|
return table;
|
|
75
89
|
}
|
package/src/geojson-writer.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// loaders.gl, MIT license
|
|
2
2
|
// Copyright Foursquare, Inc 20222
|
|
3
3
|
|
|
4
|
-
import type {Writer} from '@loaders.gl/loader-utils';
|
|
4
|
+
import type {Writer, WriterOptions} from '@loaders.gl/loader-utils';
|
|
5
5
|
import type {Table, TableBatch} from '@loaders.gl/schema';
|
|
6
|
-
import type {GeoJSONWriterOptions} from './lib/encoders/geojson-encoder';
|
|
7
6
|
import {encodeTableAsGeojsonInBatches} from './lib/encoders/geojson-encoder';
|
|
8
7
|
|
|
9
|
-
export type {
|
|
8
|
+
export type GeoJSONWriterOptions = WriterOptions & {
|
|
9
|
+
geojson?: {
|
|
10
|
+
featureArray?: boolean;
|
|
11
|
+
geometryColumn?: number | null;
|
|
12
|
+
};
|
|
13
|
+
chunkSize?: number;
|
|
14
|
+
};
|
|
10
15
|
|
|
11
16
|
export const GeoJSONWriter: Writer<Table, TableBatch, GeoJSONWriterOptions> = {
|
|
12
17
|
id: 'geojson',
|
package/src/json-writer.ts
CHANGED
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
// Copyright 2022 Foursquare Labs, Inc.
|
|
3
3
|
|
|
4
4
|
/* global TextEncoder */
|
|
5
|
-
import type {Writer} from '@loaders.gl/loader-utils';
|
|
5
|
+
import type {Writer, WriterOptions} from '@loaders.gl/loader-utils';
|
|
6
6
|
import type {Table, TableBatch} from '@loaders.gl/schema';
|
|
7
|
-
import type {JSONWriterOptions} from './lib/encoders/json-encoder';
|
|
8
7
|
import {encodeTableAsJSON} from './lib/encoders/json-encoder';
|
|
9
8
|
|
|
10
|
-
export type {
|
|
9
|
+
export type JSONWriterOptions = WriterOptions & {
|
|
10
|
+
json?: {
|
|
11
|
+
shape?: 'object-row-table' | 'array-row-table';
|
|
12
|
+
wrapper?: (table: TableJSON) => unknown;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type RowArray = unknown[];
|
|
17
|
+
type RowObject = {[key: string]: unknown};
|
|
18
|
+
type TableJSON = RowArray[] | RowObject[];
|
|
11
19
|
|
|
12
20
|
export const JSONWriter: Writer<Table, TableBatch, JSONWriterOptions> = {
|
|
13
21
|
id: 'json',
|
|
@@ -20,5 +28,5 @@ export const JSONWriter: Writer<Table, TableBatch, JSONWriterOptions> = {
|
|
|
20
28
|
text: true,
|
|
21
29
|
encode: async (table: Table, options: JSONWriterOptions) =>
|
|
22
30
|
new TextEncoder().encode(encodeTableAsJSON(table, options)).buffer,
|
|
23
|
-
|
|
31
|
+
encodeTextSync: (table: Table, options: JSONWriterOptions) => encodeTableAsJSON(table, options)
|
|
24
32
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
// Copyright 2022 Foursquare Labs, Inc.
|
|
3
|
+
|
|
4
|
+
import {Feature} from '@loaders.gl/schema';
|
|
5
|
+
import {Table, getTableRowAsObject} from '@loaders.gl/schema';
|
|
6
|
+
import {getRowPropertyObject} from './encode-utils';
|
|
7
|
+
import {Utf8ArrayBufferEncoder} from './utf8-encoder';
|
|
8
|
+
|
|
9
|
+
type Row = {[key: string]: unknown};
|
|
10
|
+
|
|
11
|
+
// Helpers
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Encode a row. Currently this ignores properties in the geometry column.
|
|
15
|
+
*/
|
|
16
|
+
export function encodeTableRow(
|
|
17
|
+
table: Table,
|
|
18
|
+
rowIndex: number,
|
|
19
|
+
geometryColumnIndex: number,
|
|
20
|
+
utf8Encoder: Utf8ArrayBufferEncoder
|
|
21
|
+
): void {
|
|
22
|
+
const row = getTableRowAsObject(table, rowIndex);
|
|
23
|
+
if (!row) return;
|
|
24
|
+
const featureWithProperties = getFeatureFromRow(table, row, geometryColumnIndex);
|
|
25
|
+
const featureString = JSON.stringify(featureWithProperties);
|
|
26
|
+
utf8Encoder.push(featureString);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Encode a row as a Feature. Currently this ignores properties objects in the geometry column.
|
|
31
|
+
*/
|
|
32
|
+
function getFeatureFromRow(table: Table, row: Row, geometryColumnIndex: number): Feature {
|
|
33
|
+
// Extract non-feature/geometry properties
|
|
34
|
+
const properties = getRowPropertyObject(table, row, [geometryColumnIndex]);
|
|
35
|
+
|
|
36
|
+
// Extract geometry feature
|
|
37
|
+
const columnName = table.schema?.fields[geometryColumnIndex].name;
|
|
38
|
+
let featureOrGeometry =
|
|
39
|
+
columnName && (row[columnName] as {[key: string]: unknown} | string | null | undefined);
|
|
40
|
+
|
|
41
|
+
// GeoJSON support null geometries
|
|
42
|
+
if (!featureOrGeometry) {
|
|
43
|
+
// @ts-ignore Feature type does not support null geometries
|
|
44
|
+
return {type: 'Feature', geometry: null, properties};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Support string geometries?
|
|
48
|
+
// TODO: This assumes GeoJSON strings, which may not be the correct format
|
|
49
|
+
// (could be WKT, encoded WKB...)
|
|
50
|
+
if (typeof featureOrGeometry === 'string') {
|
|
51
|
+
try {
|
|
52
|
+
featureOrGeometry = JSON.parse(featureOrGeometry);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
throw new Error('Invalid string geometry');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (typeof featureOrGeometry !== 'object' || typeof featureOrGeometry?.type !== 'string') {
|
|
59
|
+
throw new Error('invalid geometry column value');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (featureOrGeometry?.type === 'Feature') {
|
|
63
|
+
// @ts-ignore Feature type does not support null geometries
|
|
64
|
+
return {...featureOrGeometry, properties};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// @ts-ignore Feature type does not support null geometries
|
|
68
|
+
return {type: 'Feature', geometry: featureOrGeometry, properties};
|
|
69
|
+
}
|