@loaders.gl/flatgeobuf 4.1.0-alpha.9 → 4.1.1
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.dev.js +1 -1
- package/dist/flatgeobuf/3.27.2/column-meta.d.ts +1 -1
- package/dist/flatgeobuf/3.27.2/column-meta.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/column-meta.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/dumptree.js +3 -3
- package/dist/flatgeobuf/3.27.2/dumptree.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/feature.d.ts +1 -1
- package/dist/flatgeobuf/3.27.2/feature.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/feature.js +1 -1
- package/dist/flatgeobuf/3.27.2/feature.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts +2 -2
- package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js +2 -2
- package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js +3 -3
- package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts +5 -5
- package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf.js +5 -5
- package/dist/flatgeobuf/3.27.2/flat-geobuf.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/feature.d.ts +4 -4
- package/dist/flatgeobuf/3.27.2/generic/feature.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/feature.js +3 -3
- package/dist/flatgeobuf/3.27.2/generic/feature.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts +6 -6
- package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/featurecollection.js +12 -12
- package/dist/flatgeobuf/3.27.2/generic/featurecollection.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts +2 -2
- package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/geometry.js +2 -2
- package/dist/flatgeobuf/3.27.2/generic/geometry.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/header.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/generic/header.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/header.js +2 -2
- package/dist/flatgeobuf/3.27.2/generic/header.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/index.d.ts +5 -0
- package/dist/flatgeobuf/3.27.2/generic/index.d.ts.map +1 -0
- package/dist/flatgeobuf/3.27.2/generic/index.js +5 -0
- package/dist/flatgeobuf/3.27.2/generic/index.js.map +1 -0
- package/dist/flatgeobuf/3.27.2/generic.d.ts +7 -7
- package/dist/flatgeobuf/3.27.2/generic.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic.js +4 -4
- package/dist/flatgeobuf/3.27.2/generic.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/feature.js +2 -2
- package/dist/flatgeobuf/3.27.2/geojson/feature.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts +2 -2
- package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js +6 -6
- package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/geometry.js +2 -2
- package/dist/flatgeobuf/3.27.2/geojson/geometry.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/index.d.ts +4 -0
- package/dist/flatgeobuf/3.27.2/geojson/index.d.ts.map +1 -0
- package/dist/flatgeobuf/3.27.2/geojson/index.js +4 -0
- package/dist/flatgeobuf/3.27.2/geojson/index.js.map +1 -0
- package/dist/flatgeobuf/3.27.2/geojson.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/geojson.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson.js +1 -1
- package/dist/flatgeobuf/3.27.2/geojson.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/header-meta.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/header-meta.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/header-meta.js +1 -1
- package/dist/flatgeobuf/3.27.2/header-meta.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/header.d.ts +1 -1
- package/dist/flatgeobuf/3.27.2/header.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/header.js +1 -1
- package/dist/flatgeobuf/3.27.2/header.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/http-reader.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/http-reader.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/http-reader.js +6 -6
- package/dist/flatgeobuf/3.27.2/http-reader.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/index.d.ts +13 -13
- package/dist/flatgeobuf/3.27.2/index.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/index.js +13 -13
- package/dist/flatgeobuf/3.27.2/index.js.map +1 -1
- package/dist/flatgeobuf/3.27.2/packedrtree.js +2 -2
- package/dist/flatgeobuf/3.27.2/packedrtree.js.map +1 -1
- package/dist/flatgeobuf-loader.js +1 -1
- package/dist/flatgeobuf-loader.js.map +1 -1
- package/dist/flatgeobuf-worker.js +1 -1
- package/dist/lib/get-schema-from-fgb-header.d.ts.map +1 -1
- package/dist/lib/get-schema-from-fgb-header.js.map +1 -1
- package/dist/lib/parse-flatgeobuf.js +2 -2
- package/dist/lib/parse-flatgeobuf.js.map +1 -1
- package/package.json +6 -6
- package/src/flatgeobuf/3.27.2/.DS_Store +0 -0
- package/src/flatgeobuf/3.27.2/column-meta.ts +1 -1
- package/src/flatgeobuf/3.27.2/dumptree.ts +3 -3
- package/src/flatgeobuf/3.27.2/feature.ts +1 -1
- package/src/flatgeobuf/3.27.2/flat-geobuf/column.ts +1 -1
- package/src/flatgeobuf/3.27.2/flat-geobuf/feature.ts +2 -2
- package/src/flatgeobuf/3.27.2/flat-geobuf/geometry.ts +1 -1
- package/src/flatgeobuf/3.27.2/flat-geobuf/header.ts +3 -3
- package/src/flatgeobuf/3.27.2/flat-geobuf.ts +5 -5
- package/src/flatgeobuf/3.27.2/generic/feature.ts +5 -5
- package/src/flatgeobuf/3.27.2/generic/featurecollection.ts +17 -17
- package/src/flatgeobuf/3.27.2/generic/geometry.ts +2 -2
- package/src/flatgeobuf/3.27.2/generic/header.ts +4 -4
- package/src/flatgeobuf/3.27.2/generic/index.ts +7 -0
- package/src/flatgeobuf/3.27.2/generic.ts +7 -7
- package/src/flatgeobuf/3.27.2/geojson/feature.ts +5 -5
- package/src/flatgeobuf/3.27.2/geojson/featurecollection.ts +10 -10
- package/src/flatgeobuf/3.27.2/geojson/geometry.ts +3 -3
- package/src/flatgeobuf/3.27.2/geojson/index.ts +6 -0
- package/src/flatgeobuf/3.27.2/geojson.ts +4 -4
- package/src/flatgeobuf/3.27.2/header-meta.ts +4 -4
- package/src/flatgeobuf/3.27.2/header.ts +1 -1
- package/src/flatgeobuf/3.27.2/http-reader.ts +6 -6
- package/src/flatgeobuf/3.27.2/index.ts +17 -14
- package/src/flatgeobuf/3.27.2/packedrtree.ts +2 -2
- package/src/lib/get-schema-from-fgb-header.ts +2 -0
- package/src/lib/parse-flatgeobuf.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packedrtree.js","names":["Config","Logger","NODE_ITEM_BYTE_LEN","NODE_ITEM_LEN","DEFAULT_NODE_SIZE","calcTreeSize","numItems","nodeSize","Math","min","max","Number","n","numNodes","ceil","generateLevelBounds","Error","levelNumNodes","push","levelOffsets","size","levelBounds","i","length","streamSearch","rect","readNode","NodeRange","constructor","nodes","level","_level","startNodeIdx","endNodeIdx","extendEndNodeIdx","newIdx","console","assert","toString","minX","minY","maxX","maxY","info","firstLeafNodeIdx","rootNodeRange","range","queue","debug","nodeRange","shift","nodeRangeStartIdx","isLeafNode","nodeRangeEndIdx","levelBound","nodeIdx","numNodesInRange","buffer","dataView","DataView","nodeIdxInDataView","dataViewByteStart","getFloat64","offset","getBigUint64","featureByteOffset","featureLength","nextPos","nextOffset","featureIdx","firstChildNodeIdx","extraRequestThresholdNodes","global","extraRequestThreshold","nearestNodeRange","undefined","newNodeRange"],"sources":["../../../src/flatgeobuf/3.27.2/packedrtree.ts"],"sourcesContent":["import Config from './config.js';\nimport Logger from './logger.js';\n\nexport const NODE_ITEM_BYTE_LEN: number = 8 * 4 + 8;\n/**\n * @deprecated Use `NODE_ITEM_BYTE_LEN` instead.\n */\nexport const NODE_ITEM_LEN = NODE_ITEM_BYTE_LEN;\n\n// default branching factor of a node in the rtree\n//\n// actual value will be specified in the header but\n// this can be useful for having reasonably sized guesses for fetch-sizes when\n// streaming results\nexport const DEFAULT_NODE_SIZE = 16;\n\nexport interface Rect {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n}\n\nexport function calcTreeSize(numItems: number, nodeSize: number): number {\n nodeSize = Math.min(Math.max(Number(nodeSize), 2), 65535);\n let n = numItems;\n let numNodes = n;\n do {\n n = Math.ceil(n / nodeSize);\n numNodes += n;\n } while (n !== 1);\n return numNodes * NODE_ITEM_BYTE_LEN;\n}\n\n/**\n * returns [levelOffset, numNodes] for each level\n */\nexport function generateLevelBounds(numItems: number, nodeSize: number): Array<[number, number]> {\n if (nodeSize < 2) throw new Error('Node size must be at least 2');\n if (numItems === 0) throw new Error('Number of items must be greater than 0');\n\n // number of nodes per level in bottom-up order\n let n = numItems;\n let numNodes = n;\n const levelNumNodes = [n];\n do {\n n = Math.ceil(n / nodeSize);\n numNodes += n;\n levelNumNodes.push(n);\n } while (n !== 1);\n\n // bounds per level in reversed storage order (top-down)\n const levelOffsets: Array<number> = [];\n n = numNodes;\n for (const size of levelNumNodes) {\n levelOffsets.push(n - size);\n n -= size;\n }\n const levelBounds: Array<[number, number]> = [];\n for (let i = 0; i < levelNumNodes.length; i++)\n levelBounds.push([levelOffsets[i], levelOffsets[i] + levelNumNodes[i]]);\n return levelBounds;\n}\n\ntype ReadNodeFn = (treeOffset: number, size: number) => Promise<ArrayBuffer>;\n\n/**\n * A feature found to be within the bounding box `rect`\n *\n * (offset, index)\n * `offset`: Byte offset in feature data section\n * `index`: feature number\n * `featureLength`: featureLength, except for the last element\n */\nexport type SearchResult = [number, number, number | null];\n\n/**\n * Yield's a `SearchResult` for each feature within the bounds of `rect`.\n *\n * Every node in the FGB index tree has a bounding rect, all of the nodes children\n * are contained within that bounding rect. The leaf nodes of the tree represent\n * the features of the collection.\n *\n * As we traverse the tree, starting from the root, we'll need to read more data\n * from the index. When we don't already have this range data buffered locally,\n * an HTTP fetch is triggered. For performance, we merge adjacent and nearby\n * request ranges into a single request, reasoning that fetching a few extra\n * bytes is a good tradeoff if it means we can reduce the number of requests.\n */\nexport async function* streamSearch(\n numItems: number,\n nodeSize: number,\n rect: Rect,\n readNode: ReadNodeFn\n): AsyncGenerator<SearchResult, void, unknown> {\n type NodeIdx = number;\n class NodeRange {\n _level: number;\n nodes: [NodeIdx, NodeIdx];\n constructor(nodes: [NodeIdx, NodeIdx], level: number) {\n this._level = level;\n this.nodes = nodes;\n }\n\n level(): number {\n return this._level;\n }\n\n startNodeIdx(): NodeIdx {\n return this.nodes[0];\n }\n\n endNodeIdx(): NodeIdx {\n return this.nodes[1];\n }\n\n extendEndNodeIdx(newIdx: number) {\n console.assert(newIdx > this.nodes[1]);\n this.nodes[1] = newIdx;\n }\n\n toString(): string {\n return `[NodeRange level: ${this._level}, nodes: ${this.nodes[0]}-${this.nodes[1]}]`;\n }\n }\n\n const {minX, minY, maxX, maxY} = rect;\n Logger.info(`tree items: ${numItems}, nodeSize: ${nodeSize}`);\n const levelBounds = generateLevelBounds(numItems, nodeSize);\n const firstLeafNodeIdx = levelBounds[0][0];\n\n const rootNodeRange: NodeRange = (() => {\n const range: [number, number] = [0, 1];\n const level = levelBounds.length - 1;\n return new NodeRange(range, level);\n })();\n\n const queue: Array<NodeRange> = [rootNodeRange];\n\n Logger.debug(\n `starting stream search with queue: ${queue}, numItems: ${numItems}, nodeSize: ${nodeSize}, levelBounds: ${levelBounds}`\n );\n\n while (queue.length != 0) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nodeRange = queue.shift()!;\n\n Logger.debug(`popped node: ${nodeRange}, queueLength: ${queue.length}`);\n\n const nodeRangeStartIdx = nodeRange.startNodeIdx();\n const isLeafNode = nodeRangeStartIdx >= firstLeafNodeIdx;\n\n // find the end index of the node\n const nodeRangeEndIdx = (() => {\n const [, levelBound] = levelBounds[nodeRange.level()];\n const nodeIdx = Math.min(nodeRange.endNodeIdx() + nodeSize, levelBound);\n\n if (isLeafNode && nodeIdx < levelBound) {\n // We can infer the length of *this* feature by getting the start of the *next*\n // feature, so we get an extra node.\n // This approach doesn't work for the final node in the index,\n // but in that case we know that the feature runs to the end of the FGB file and\n // could make an open ended range request to get \"the rest of the data\".\n return nodeIdx + 1;\n }\n return nodeIdx;\n })();\n\n const numNodesInRange = nodeRangeEndIdx - nodeRangeStartIdx;\n\n const buffer = await readNode(\n nodeRangeStartIdx * NODE_ITEM_BYTE_LEN,\n numNodesInRange * NODE_ITEM_BYTE_LEN\n );\n\n const dataView = new DataView(buffer);\n for (let nodeIdx = nodeRangeStartIdx; nodeIdx < nodeRangeEndIdx; nodeIdx++) {\n const nodeIdxInDataView = nodeIdx - nodeRangeStartIdx;\n const dataViewByteStart = nodeIdxInDataView * NODE_ITEM_BYTE_LEN;\n if (maxX < dataView.getFloat64(dataViewByteStart + 0, true)) continue; // maxX < nodeMinX\n if (maxY < dataView.getFloat64(dataViewByteStart + 8, true)) continue; // maxY < nodeMinY\n if (minX > dataView.getFloat64(dataViewByteStart + 16, true)) continue; // minX > nodeMaxX\n if (minY > dataView.getFloat64(dataViewByteStart + 24, true)) continue; // minY > nodeMaxY\n\n // `offset` is:\n // For leaf nodes: the byte-offset into the feature buffer.\n // For inner nodes: the node-idx of its first child.\n const offset = dataView.getBigUint64(dataViewByteStart + 32, true);\n\n if (isLeafNode) {\n const featureByteOffset = offset;\n const featureLength = (() => {\n if (nodeIdx < numItems - 1) {\n // Since features are tightly packed, we infer the\n // length of _this_ feature by measuring to the _next_\n // feature's start.\n const nextPos = (nodeIdxInDataView + 1) * NODE_ITEM_BYTE_LEN;\n // console.debug(`nodeIdx: ${nodeIdx} of ${numItems}, nodeRangeStartIdx: ${nodeRangeStartIdx}, nextPos: ${nextPos}, dataView.byteLength: ${dataView.byteLength}`,);\n const nextOffset = dataView.getBigUint64(nextPos + 32, true);\n return nextOffset - featureByteOffset;\n }\n // This is the last feature - there's no \"next\" feature\n // to measure to, so we can't know it's length.\n return null;\n })();\n\n // Logger.debug(`featureByteOffset: ${featureByteOffset}, nodeIdx: ${nodeIdx}, featureLength: ${featureLength}`);\n const featureIdx = nodeIdx - firstLeafNodeIdx;\n yield [Number(featureByteOffset), featureIdx, Number(featureLength)];\n continue;\n }\n\n const firstChildNodeIdx = offset;\n\n // request up to this many nodes if it means we can eliminate an\n // extra request\n const extraRequestThresholdNodes = Config.global.extraRequestThreshold() / NODE_ITEM_BYTE_LEN;\n\n // Since we're traversing the tree by monotonically increasing byte\n // offset, the most recently enqueued node range will be the\n // nearest, and thus presents the best candidate for merging.\n const nearestNodeRange = queue[queue.length - 1];\n if (\n nearestNodeRange !== undefined &&\n nearestNodeRange.level() == nodeRange.level() - 1 &&\n firstChildNodeIdx < nearestNodeRange.endNodeIdx() + extraRequestThresholdNodes\n ) {\n Logger.debug(\n `Merging \"nodeRange\" request into existing range: ${nearestNodeRange}, newEndNodeIdx: ${nearestNodeRange.endNodeIdx()} -> ${firstChildNodeIdx}`\n );\n nearestNodeRange.extendEndNodeIdx(Number(firstChildNodeIdx));\n continue;\n }\n\n const newNodeRange: NodeRange = (() => {\n const level = nodeRange.level() - 1;\n const range: [number, number] = [Number(firstChildNodeIdx), Number(firstChildNodeIdx) + 1];\n return new NodeRange(range, level);\n })();\n\n // We're going to add a new node range - log the reason\n if (nearestNodeRange !== undefined && nearestNodeRange.level() == newNodeRange.level()) {\n Logger.info(\n `Same level, but too far away. Pushing new request for nodeIdx: ${firstChildNodeIdx} rather than merging with distant ${nearestNodeRange}`\n );\n } else {\n Logger.info(\n `Pushing new level for ${newNodeRange} onto queue with nearestNodeRange: ${nearestNodeRange} since there's not already a range for this level.`\n );\n }\n\n queue.push(newNodeRange);\n }\n }\n}\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,aAAa;AAChC,OAAOC,MAAM,MAAM,aAAa;AAEhC,OAAO,MAAMC,kBAA0B,G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O,IAAI3C,SAAS,CAACmB,KAAK,EAAEhB,KAAK,CAAC;MACpC,CAAC,EAAE,CAAC;MAGJ,IAAI4C,gBAAgB,KAAKC,SAAS,IAAID,gBAAgB,CAAC5C,KAAK,CAAC,CAAC,IAAI8C,YAAY,CAAC9C,KAAK,CAAC,CAAC,EAAE;QACtF7B,MAAM,CAAC0C,IAAI,CACR,kEAAiE2B,iBAAkB,qCAAoCI,gBAAiB,EAC3I,CAAC;MACH,CAAC,MAAM;QACLzE,MAAM,CAAC0C,IAAI,CACR,yBAAwBiC,YAAa,sCAAqCF,gBAAiB,oDAC9F,CAAC;MACH;MAEA3B,KAAK,CAAC7B,IAAI,CAAC0D,YAAY,CAAC;IAC1B;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"packedrtree.js","names":["Config","Logger","NODE_ITEM_BYTE_LEN","NODE_ITEM_LEN","DEFAULT_NODE_SIZE","calcTreeSize","numItems","nodeSize","Math","min","max","Number","n","numNodes","ceil","generateLevelBounds","Error","levelNumNodes","push","levelOffsets","size","levelBounds","i","length","streamSearch","rect","readNode","NodeRange","constructor","nodes","level","_level","startNodeIdx","endNodeIdx","extendEndNodeIdx","newIdx","console","assert","toString","minX","minY","maxX","maxY","info","firstLeafNodeIdx","rootNodeRange","range","queue","debug","nodeRange","shift","nodeRangeStartIdx","isLeafNode","nodeRangeEndIdx","levelBound","nodeIdx","numNodesInRange","buffer","dataView","DataView","nodeIdxInDataView","dataViewByteStart","getFloat64","offset","getBigUint64","featureByteOffset","featureLength","nextPos","nextOffset","featureIdx","firstChildNodeIdx","extraRequestThresholdNodes","global","extraRequestThreshold","nearestNodeRange","undefined","newNodeRange"],"sources":["../../../src/flatgeobuf/3.27.2/packedrtree.ts"],"sourcesContent":["import Config from './config';\nimport Logger from './logger';\n\nexport const NODE_ITEM_BYTE_LEN: number = 8 * 4 + 8;\n/**\n * @deprecated Use `NODE_ITEM_BYTE_LEN` instead.\n */\nexport const NODE_ITEM_LEN = NODE_ITEM_BYTE_LEN;\n\n// default branching factor of a node in the rtree\n//\n// actual value will be specified in the header but\n// this can be useful for having reasonably sized guesses for fetch-sizes when\n// streaming results\nexport const DEFAULT_NODE_SIZE = 16;\n\nexport interface Rect {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n}\n\nexport function calcTreeSize(numItems: number, nodeSize: number): number {\n nodeSize = Math.min(Math.max(Number(nodeSize), 2), 65535);\n let n = numItems;\n let numNodes = n;\n do {\n n = Math.ceil(n / nodeSize);\n numNodes += n;\n } while (n !== 1);\n return numNodes * NODE_ITEM_BYTE_LEN;\n}\n\n/**\n * returns [levelOffset, numNodes] for each level\n */\nexport function generateLevelBounds(numItems: number, nodeSize: number): Array<[number, number]> {\n if (nodeSize < 2) throw new Error('Node size must be at least 2');\n if (numItems === 0) throw new Error('Number of items must be greater than 0');\n\n // number of nodes per level in bottom-up order\n let n = numItems;\n let numNodes = n;\n const levelNumNodes = [n];\n do {\n n = Math.ceil(n / nodeSize);\n numNodes += n;\n levelNumNodes.push(n);\n } while (n !== 1);\n\n // bounds per level in reversed storage order (top-down)\n const levelOffsets: Array<number> = [];\n n = numNodes;\n for (const size of levelNumNodes) {\n levelOffsets.push(n - size);\n n -= size;\n }\n const levelBounds: Array<[number, number]> = [];\n for (let i = 0; i < levelNumNodes.length; i++)\n levelBounds.push([levelOffsets[i], levelOffsets[i] + levelNumNodes[i]]);\n return levelBounds;\n}\n\ntype ReadNodeFn = (treeOffset: number, size: number) => Promise<ArrayBuffer>;\n\n/**\n * A feature found to be within the bounding box `rect`\n *\n * (offset, index)\n * `offset`: Byte offset in feature data section\n * `index`: feature number\n * `featureLength`: featureLength, except for the last element\n */\nexport type SearchResult = [number, number, number | null];\n\n/**\n * Yield's a `SearchResult` for each feature within the bounds of `rect`.\n *\n * Every node in the FGB index tree has a bounding rect, all of the nodes children\n * are contained within that bounding rect. The leaf nodes of the tree represent\n * the features of the collection.\n *\n * As we traverse the tree, starting from the root, we'll need to read more data\n * from the index. When we don't already have this range data buffered locally,\n * an HTTP fetch is triggered. For performance, we merge adjacent and nearby\n * request ranges into a single request, reasoning that fetching a few extra\n * bytes is a good tradeoff if it means we can reduce the number of requests.\n */\nexport async function* streamSearch(\n numItems: number,\n nodeSize: number,\n rect: Rect,\n readNode: ReadNodeFn\n): AsyncGenerator<SearchResult, void, unknown> {\n type NodeIdx = number;\n class NodeRange {\n _level: number;\n nodes: [NodeIdx, NodeIdx];\n constructor(nodes: [NodeIdx, NodeIdx], level: number) {\n this._level = level;\n this.nodes = nodes;\n }\n\n level(): number {\n return this._level;\n }\n\n startNodeIdx(): NodeIdx {\n return this.nodes[0];\n }\n\n endNodeIdx(): NodeIdx {\n return this.nodes[1];\n }\n\n extendEndNodeIdx(newIdx: number) {\n console.assert(newIdx > this.nodes[1]);\n this.nodes[1] = newIdx;\n }\n\n toString(): string {\n return `[NodeRange level: ${this._level}, nodes: ${this.nodes[0]}-${this.nodes[1]}]`;\n }\n }\n\n const {minX, minY, maxX, maxY} = rect;\n Logger.info(`tree items: ${numItems}, nodeSize: ${nodeSize}`);\n const levelBounds = generateLevelBounds(numItems, nodeSize);\n const firstLeafNodeIdx = levelBounds[0][0];\n\n const rootNodeRange: NodeRange = (() => {\n const range: [number, number] = [0, 1];\n const level = levelBounds.length - 1;\n return new NodeRange(range, level);\n })();\n\n const queue: Array<NodeRange> = [rootNodeRange];\n\n Logger.debug(\n `starting stream search with queue: ${queue}, numItems: ${numItems}, nodeSize: ${nodeSize}, levelBounds: ${levelBounds}`\n );\n\n while (queue.length != 0) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nodeRange = queue.shift()!;\n\n Logger.debug(`popped node: ${nodeRange}, queueLength: ${queue.length}`);\n\n const nodeRangeStartIdx = nodeRange.startNodeIdx();\n const isLeafNode = nodeRangeStartIdx >= firstLeafNodeIdx;\n\n // find the end index of the node\n const nodeRangeEndIdx = (() => {\n const [, levelBound] = levelBounds[nodeRange.level()];\n const nodeIdx = Math.min(nodeRange.endNodeIdx() + nodeSize, levelBound);\n\n if (isLeafNode && nodeIdx < levelBound) {\n // We can infer the length of *this* feature by getting the start of the *next*\n // feature, so we get an extra node.\n // This approach doesn't work for the final node in the index,\n // but in that case we know that the feature runs to the end of the FGB file and\n // could make an open ended range request to get \"the rest of the data\".\n return nodeIdx + 1;\n }\n return nodeIdx;\n })();\n\n const numNodesInRange = nodeRangeEndIdx - nodeRangeStartIdx;\n\n const buffer = await readNode(\n nodeRangeStartIdx * NODE_ITEM_BYTE_LEN,\n numNodesInRange * NODE_ITEM_BYTE_LEN\n );\n\n const dataView = new DataView(buffer);\n for (let nodeIdx = nodeRangeStartIdx; nodeIdx < nodeRangeEndIdx; nodeIdx++) {\n const nodeIdxInDataView = nodeIdx - nodeRangeStartIdx;\n const dataViewByteStart = nodeIdxInDataView * NODE_ITEM_BYTE_LEN;\n if (maxX < dataView.getFloat64(dataViewByteStart + 0, true)) continue; // maxX < nodeMinX\n if (maxY < dataView.getFloat64(dataViewByteStart + 8, true)) continue; // maxY < nodeMinY\n if (minX > dataView.getFloat64(dataViewByteStart + 16, true)) continue; // minX > nodeMaxX\n if (minY > dataView.getFloat64(dataViewByteStart + 24, true)) continue; // minY > nodeMaxY\n\n // `offset` is:\n // For leaf nodes: the byte-offset into the feature buffer.\n // For inner nodes: the node-idx of its first child.\n const offset = dataView.getBigUint64(dataViewByteStart + 32, true);\n\n if (isLeafNode) {\n const featureByteOffset = offset;\n const featureLength = (() => {\n if (nodeIdx < numItems - 1) {\n // Since features are tightly packed, we infer the\n // length of _this_ feature by measuring to the _next_\n // feature's start.\n const nextPos = (nodeIdxInDataView + 1) * NODE_ITEM_BYTE_LEN;\n // console.debug(`nodeIdx: ${nodeIdx} of ${numItems}, nodeRangeStartIdx: ${nodeRangeStartIdx}, nextPos: ${nextPos}, dataView.byteLength: ${dataView.byteLength}`,);\n const nextOffset = dataView.getBigUint64(nextPos + 32, true);\n return nextOffset - featureByteOffset;\n }\n // This is the last feature - there's no \"next\" feature\n // to measure to, so we can't know it's length.\n return null;\n })();\n\n // Logger.debug(`featureByteOffset: ${featureByteOffset}, nodeIdx: ${nodeIdx}, featureLength: ${featureLength}`);\n const featureIdx = nodeIdx - firstLeafNodeIdx;\n yield [Number(featureByteOffset), featureIdx, Number(featureLength)];\n continue;\n }\n\n const firstChildNodeIdx = offset;\n\n // request up to this many nodes if it means we can eliminate an\n // extra request\n const extraRequestThresholdNodes = Config.global.extraRequestThreshold() / NODE_ITEM_BYTE_LEN;\n\n // Since we're traversing the tree by monotonically increasing byte\n // offset, the most recently enqueued node range will be the\n // nearest, and thus presents the best candidate for merging.\n const nearestNodeRange = queue[queue.length - 1];\n if (\n nearestNodeRange !== undefined &&\n nearestNodeRange.level() == nodeRange.level() - 1 &&\n firstChildNodeIdx < nearestNodeRange.endNodeIdx() + extraRequestThresholdNodes\n ) {\n Logger.debug(\n `Merging \"nodeRange\" request into existing range: ${nearestNodeRange}, newEndNodeIdx: ${nearestNodeRange.endNodeIdx()} -> ${firstChildNodeIdx}`\n );\n nearestNodeRange.extendEndNodeIdx(Number(firstChildNodeIdx));\n continue;\n }\n\n const newNodeRange: NodeRange = (() => {\n const level = nodeRange.level() - 1;\n const range: [number, number] = [Number(firstChildNodeIdx), Number(firstChildNodeIdx) + 1];\n return new NodeRange(range, level);\n })();\n\n // We're going to add a new node range - log the reason\n if (nearestNodeRange !== undefined && nearestNodeRange.level() == newNodeRange.level()) {\n Logger.info(\n `Same level, but too far away. Pushing new request for nodeIdx: ${firstChildNodeIdx} rather than merging with distant ${nearestNodeRange}`\n );\n } else {\n Logger.info(\n `Pushing new level for ${newNodeRange} onto queue with nearestNodeRange: ${nearestNodeRange} since there's not already a range for this level.`\n );\n }\n\n queue.push(newNodeRange);\n }\n }\n}\n"],"mappings":"OAAOA,MAAM;AAAA,OACNC,MAAM;AAEb,OAAO,MAAMC,kBAA0B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;AAInD,OAAO,MAAMC,aAAa,GAAGD,kBAAkB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MAGJ,IAAI4C,gBAAgB,KAAKC,SAAS,IAAID,gBAAgB,CAAC5C,KAAK,CAAC,CAAC,IAAI8C,YAAY,CAAC9C,KAAK,CAAC,CAAC,EAAE;QACtF7B,MAAM,CAAC0C,IAAI,CACR,kEAAiE2B,iBAAkB,qCAAoCI,gBAAiB,EAC3I,CAAC;MACH,CAAC,MAAM;QACLzE,MAAM,CAAC0C,IAAI,CACR,yBAAwBiC,YAAa,sCAAqCF,gBAAiB,oDAC9F,CAAC;MACH;MAEA3B,KAAK,CAAC7B,IAAI,CAAC0D,YAAY,CAAC;IAC1B;EACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseFlatGeobuf, parseFlatGeobufInBatches } from "./lib/parse-flatgeobuf.js";
|
|
2
|
-
const VERSION = typeof "4.1.
|
|
2
|
+
const VERSION = typeof "4.1.1" !== 'undefined' ? "4.1.1" : 'latest';
|
|
3
3
|
const FGB_MAGIC_NUMBER = [0x66, 0x67, 0x62, 0x03, 0x66, 0x67, 0x62, 0x01];
|
|
4
4
|
export const FlatGeobufWorkerLoader = {
|
|
5
5
|
id: 'flatgeobuf',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatgeobuf-loader.js","names":["parseFlatGeobuf","parseFlatGeobufInBatches","VERSION","FGB_MAGIC_NUMBER","FlatGeobufWorkerLoader","id","name","module","version","worker","extensions","mimeTypes","category","tests","Uint8Array","buffer","options","flatgeobuf","shape","gis","reproject","FlatGeobufLoader","parse","arrayBuffer","parseSync","parseInBatchesFromStream","binary"],"sources":["../src/flatgeobuf-loader.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {parseFlatGeobuf, parseFlatGeobufInBatches} from './lib/parse-flatgeobuf';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n// FGB\\3FGB\\1\nconst FGB_MAGIC_NUMBER = [0x66, 0x67, 0x62, 0x03, 0x66, 0x67, 0x62, 0x01];\n\nexport type FlatGeobufLoaderOptions = LoaderOptions & {\n flatgeobuf?: {\n shape?: 'geojson-table' | 'columnar-table' | 'binary';\n };\n gis?: {\n reproject?: boolean;\n _targetCrs?: string;\n };\n};\n\nexport const FlatGeobufWorkerLoader: Loader<any, any, FlatGeobufLoaderOptions> = {\n id: 'flatgeobuf',\n name: 'FlatGeobuf',\n module: 'flatgeobuf',\n version: VERSION,\n worker: true,\n extensions: ['fgb'],\n mimeTypes: ['application/octet-stream'],\n category: 'geometry',\n tests: [new Uint8Array(FGB_MAGIC_NUMBER).buffer],\n options: {\n flatgeobuf: {\n shape: 'geojson-table'\n },\n gis: {\n reproject: false\n }\n }\n};\n\nexport const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOptions> = {\n ...FlatGeobufWorkerLoader,\n parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),\n parseSync: parseFlatGeobuf,\n // @ts-expect-error this is a stream parser not an async iterator parser\n parseInBatchesFromStream: parseFlatGeobufInBatches,\n binary: true\n};\n"],"mappings":"SAKQA,eAAe,EAAEC,wBAAwB;AAIjD,MAAMC,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"flatgeobuf-loader.js","names":["parseFlatGeobuf","parseFlatGeobufInBatches","VERSION","FGB_MAGIC_NUMBER","FlatGeobufWorkerLoader","id","name","module","version","worker","extensions","mimeTypes","category","tests","Uint8Array","buffer","options","flatgeobuf","shape","gis","reproject","FlatGeobufLoader","parse","arrayBuffer","parseSync","parseInBatchesFromStream","binary"],"sources":["../src/flatgeobuf-loader.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {parseFlatGeobuf, parseFlatGeobufInBatches} from './lib/parse-flatgeobuf';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n// FGB\\3FGB\\1\nconst FGB_MAGIC_NUMBER = [0x66, 0x67, 0x62, 0x03, 0x66, 0x67, 0x62, 0x01];\n\nexport type FlatGeobufLoaderOptions = LoaderOptions & {\n flatgeobuf?: {\n shape?: 'geojson-table' | 'columnar-table' | 'binary';\n };\n gis?: {\n reproject?: boolean;\n _targetCrs?: string;\n };\n};\n\nexport const FlatGeobufWorkerLoader: Loader<any, any, FlatGeobufLoaderOptions> = {\n id: 'flatgeobuf',\n name: 'FlatGeobuf',\n module: 'flatgeobuf',\n version: VERSION,\n worker: true,\n extensions: ['fgb'],\n mimeTypes: ['application/octet-stream'],\n category: 'geometry',\n tests: [new Uint8Array(FGB_MAGIC_NUMBER).buffer],\n options: {\n flatgeobuf: {\n shape: 'geojson-table'\n },\n gis: {\n reproject: false\n }\n }\n};\n\nexport const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOptions> = {\n ...FlatGeobufWorkerLoader,\n parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),\n parseSync: parseFlatGeobuf,\n // @ts-expect-error this is a stream parser not an async iterator parser\n parseInBatchesFromStream: parseFlatGeobufInBatches,\n binary: true\n};\n"],"mappings":"SAKQA,eAAe,EAAEC,wBAAwB;AAIjD,MAAMC,OAAO,GAAG,cAAkB,KAAK,WAAW,aAAiB,QAAQ;AAG3E,MAAMC,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;AAYzE,OAAO,MAAMC,sBAAiE,GAAG;EAC/EC,EAAE,EAAE,YAAY;EAChBC,IAAI,EAAE,YAAY;EAClBC,MAAM,EAAE,YAAY;EACpBC,OAAO,EAAEN,OAAO;EAChBO,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE,CAAC,IAAIC,UAAU,CAACX,gBAAgB,CAAC,CAACY,MAAM,CAAC;EAChDC,OAAO,EAAE;IACPC,UAAU,EAAE;MACVC,KAAK,EAAE;IACT,CAAC;IACDC,GAAG,EAAE;MACHC,SAAS,EAAE;IACb;EACF;AACF,CAAC;AAED,OAAO,MAAMC,gBAAqE,GAAG;EACnF,GAAGjB,sBAAsB;EACzBkB,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEP,OAAO,KAAKhB,eAAe,CAACuB,WAAW,EAAEP,OAAO,CAAC;EAC5EQ,SAAS,EAAExB,eAAe;EAE1ByB,wBAAwB,EAAExB,wBAAwB;EAClDyB,MAAM,EAAE;AACV,CAAC"}
|
|
@@ -8855,7 +8855,7 @@
|
|
|
8855
8855
|
}
|
|
8856
8856
|
|
|
8857
8857
|
// src/flatgeobuf-loader.ts
|
|
8858
|
-
var VERSION = true ? "4.1.
|
|
8858
|
+
var VERSION = true ? "4.1.1" : "latest";
|
|
8859
8859
|
var FGB_MAGIC_NUMBER = [102, 103, 98, 3, 102, 103, 98, 1];
|
|
8860
8860
|
var FlatGeobufWorkerLoader = {
|
|
8861
8861
|
id: "flatgeobuf",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-schema-from-fgb-header.d.ts","sourceRoot":"","sources":["../../src/lib/get-schema-from-fgb-header.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-schema-from-fgb-header.d.ts","sourceRoot":"","sources":["../../src/lib/get-schema-from-fgb-header.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,MAAM,EAAkB,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,GAAG,CAAC,UAAU,GAAG,MAAM,CAcxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-schema-from-fgb-header.js","names":["getSchemaFromFGBHeader","fgbHeader","_fgbHeader$envelope","_fgbHeader$columns","metadata","title","description","crs","JSON","stringify","geometryType","String","indexNodeSize","featureCount","featuresCount","bounds","envelope","join","fields","columns","map","column","getFieldFromFGBColumn","fgbColumn","width","precision","scale","unique","primary_key","name","type","getTypeFromFGBType","nullable","fgbColumnType","fgbType","Byte","UByte","Bool","Short","UShort","Int","UInt","Long","ULong","Float","Double","Json","DateTime","Binary"],"sources":["../../src/lib/get-schema-from-fgb-header.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Schema, Field, DataType} from '@loaders.gl/schema';\nimport * as fgb from '../flatgeobuf/3.27.2';\n\n/**\n * @param fgbHeader\n * geometryType: GeometryType;\n * columns: ColumnMeta[] | null;\n * envelope: Float64Array | null;\n * featuresCount: number;\n * indexNodeSize: number;\n * crs: CrsMeta | null;\n * title: string | null;\n * description: string | null;\n * metadata: string | null;\n */\nexport function getSchemaFromFGBHeader(fgbHeader: fgb.HeaderMeta): Schema {\n const metadata: Record<string, string> = {\n title: fgbHeader.title || '',\n description: fgbHeader.description || '',\n crs: JSON.stringify(fgbHeader.crs) || '',\n metadata: fgbHeader.metadata || '',\n geometryType: String(fgbHeader.geometryType),\n indexNodeSize: String(fgbHeader.indexNodeSize),\n featureCount: String(fgbHeader.featuresCount),\n bounds: fgbHeader.envelope?.join(',') || ''\n };\n\n const fields: Field[] = fgbHeader.columns?.map((column) => getFieldFromFGBColumn(column)) || [];\n return {metadata, fields};\n}\n\n/**\n * name: string;\n * type: ColumnType;\n * title: string | null;\n * description: string | null;\n * width: number;\n * precision: number;\n * scale: number;\n * nullable: boolean;\n * unique: boolean;\n * primary_key: boolean;\n */\nfunction getFieldFromFGBColumn(fgbColumn: fgb.ColumnMeta): Field {\n const metadata: Record<string, string> = {\n title: fgbColumn.title || '',\n description: fgbColumn.description || '',\n width: String(fgbColumn.width),\n precision: String(fgbColumn.precision),\n scale: String(fgbColumn.scale),\n unique: String(fgbColumn.unique),\n primary_key: String(fgbColumn.primary_key)\n };\n\n return {\n name: fgbColumn.name,\n type: getTypeFromFGBType(fgbColumn.type as unknown as fgbColumnType),\n nullable: fgbColumn.nullable,\n metadata\n };\n}\n\n/** Note: fgb.ColumType does not appear to be exported */\nenum fgbColumnType {\n Byte = 0,\n UByte = 1,\n Bool = 2,\n Short = 3,\n UShort = 4,\n Int = 5,\n UInt = 6,\n Long = 7,\n ULong = 8,\n Float = 9,\n Double = 10,\n String = 11,\n Json = 12,\n DateTime = 13,\n Binary = 14\n}\n\n/** Convert FGB types to arrow like types */\nfunction getTypeFromFGBType(fgbType: fgbColumnType /* fgb.ColumnMeta['type'] */): DataType {\n switch (fgbType) {\n case fgbColumnType.Byte:\n return 'int8';\n case fgbColumnType.UByte:\n return 'uint8';\n case fgbColumnType.Bool:\n return 'bool';\n case fgbColumnType.Short:\n return 'int16';\n case fgbColumnType.UShort:\n return 'uint16';\n case fgbColumnType.Int:\n return 'int32';\n case fgbColumnType.UInt:\n return 'uint32';\n case fgbColumnType.Long:\n return 'int64';\n case fgbColumnType.ULong:\n return 'uint64';\n case fgbColumnType.Float:\n return 'float32';\n case fgbColumnType.Double:\n return 'float64';\n case fgbColumnType.String:\n return 'utf8';\n case fgbColumnType.Json:\n return 'null';\n case fgbColumnType.DateTime:\n return 'date-millisecond';\n case fgbColumnType.Binary:\n return 'binary';\n default:\n return 'null';\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-schema-from-fgb-header.js","names":["getSchemaFromFGBHeader","fgbHeader","_fgbHeader$envelope","_fgbHeader$columns","metadata","title","description","crs","JSON","stringify","geometryType","String","indexNodeSize","featureCount","featuresCount","bounds","envelope","join","fields","columns","map","column","getFieldFromFGBColumn","fgbColumn","width","precision","scale","unique","primary_key","name","type","getTypeFromFGBType","nullable","fgbColumnType","fgbType","Byte","UByte","Bool","Short","UShort","Int","UInt","Long","ULong","Float","Double","Json","DateTime","Binary"],"sources":["../../src/lib/get-schema-from-fgb-header.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/* eslint-disable camelcase */\n\nimport type {Schema, Field, DataType} from '@loaders.gl/schema';\nimport * as fgb from '../flatgeobuf/3.27.2';\n\n/**\n * @param fgbHeader\n * geometryType: GeometryType;\n * columns: ColumnMeta[] | null;\n * envelope: Float64Array | null;\n * featuresCount: number;\n * indexNodeSize: number;\n * crs: CrsMeta | null;\n * title: string | null;\n * description: string | null;\n * metadata: string | null;\n */\nexport function getSchemaFromFGBHeader(fgbHeader: fgb.HeaderMeta): Schema {\n const metadata: Record<string, string> = {\n title: fgbHeader.title || '',\n description: fgbHeader.description || '',\n crs: JSON.stringify(fgbHeader.crs) || '',\n metadata: fgbHeader.metadata || '',\n geometryType: String(fgbHeader.geometryType),\n indexNodeSize: String(fgbHeader.indexNodeSize),\n featureCount: String(fgbHeader.featuresCount),\n bounds: fgbHeader.envelope?.join(',') || ''\n };\n\n const fields: Field[] = fgbHeader.columns?.map((column) => getFieldFromFGBColumn(column)) || [];\n return {metadata, fields};\n}\n\n/**\n * name: string;\n * type: ColumnType;\n * title: string | null;\n * description: string | null;\n * width: number;\n * precision: number;\n * scale: number;\n * nullable: boolean;\n * unique: boolean;\n * primary_key: boolean;\n */\nfunction getFieldFromFGBColumn(fgbColumn: fgb.ColumnMeta): Field {\n const metadata: Record<string, string> = {\n title: fgbColumn.title || '',\n description: fgbColumn.description || '',\n width: String(fgbColumn.width),\n precision: String(fgbColumn.precision),\n scale: String(fgbColumn.scale),\n unique: String(fgbColumn.unique),\n primary_key: String(fgbColumn.primary_key)\n };\n\n return {\n name: fgbColumn.name,\n type: getTypeFromFGBType(fgbColumn.type as unknown as fgbColumnType),\n nullable: fgbColumn.nullable,\n metadata\n };\n}\n\n/** Note: fgb.ColumType does not appear to be exported */\nenum fgbColumnType {\n Byte = 0,\n UByte = 1,\n Bool = 2,\n Short = 3,\n UShort = 4,\n Int = 5,\n UInt = 6,\n Long = 7,\n ULong = 8,\n Float = 9,\n Double = 10,\n String = 11,\n Json = 12,\n DateTime = 13,\n Binary = 14\n}\n\n/** Convert FGB types to arrow like types */\nfunction getTypeFromFGBType(fgbType: fgbColumnType /* fgb.ColumnMeta['type'] */): DataType {\n switch (fgbType) {\n case fgbColumnType.Byte:\n return 'int8';\n case fgbColumnType.UByte:\n return 'uint8';\n case fgbColumnType.Bool:\n return 'bool';\n case fgbColumnType.Short:\n return 'int16';\n case fgbColumnType.UShort:\n return 'uint16';\n case fgbColumnType.Int:\n return 'int32';\n case fgbColumnType.UInt:\n return 'uint32';\n case fgbColumnType.Long:\n return 'int64';\n case fgbColumnType.ULong:\n return 'uint64';\n case fgbColumnType.Float:\n return 'float32';\n case fgbColumnType.Double:\n return 'float64';\n case fgbColumnType.String:\n return 'utf8';\n case fgbColumnType.Json:\n return 'null';\n case fgbColumnType.DateTime:\n return 'date-millisecond';\n case fgbColumnType.Binary:\n return 'binary';\n default:\n return 'null';\n }\n}\n"],"mappings":"AAqBA,OAAO,SAASA,sBAAsBA,CAACC,SAAyB,EAAU;EAAA,IAAAC,mBAAA,EAAAC,kBAAA;EACxE,MAAMC,QAAgC,GAAG;IACvCC,KAAK,EAAEJ,SAAS,CAACI,KAAK,IAAI,EAAE;IAC5BC,WAAW,EAAEL,SAAS,CAACK,WAAW,IAAI,EAAE;IACxCC,GAAG,EAAEC,IAAI,CAACC,SAAS,CAACR,SAAS,CAACM,GAAG,CAAC,IAAI,EAAE;IACxCH,QAAQ,EAAEH,SAAS,CAACG,QAAQ,IAAI,EAAE;IAClCM,YAAY,EAAEC,MA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OAAO,MAAM;EACjB;AACF"}
|
|
@@ -2,8 +2,8 @@ import { Proj4Projection } from '@math.gl/proj4';
|
|
|
2
2
|
import { transformGeoJsonCoords } from '@loaders.gl/gis';
|
|
3
3
|
import { fgbToBinaryGeometry } from "./binary-geometries.js";
|
|
4
4
|
import { getSchemaFromFGBHeader } from "./get-schema-from-fgb-header.js";
|
|
5
|
-
import * as geojson from
|
|
6
|
-
import * as generic from
|
|
5
|
+
import * as geojson from "../flatgeobuf/3.27.2/geojson/index.js";
|
|
6
|
+
import * as generic from "../flatgeobuf/3.27.2/generic/index.js";
|
|
7
7
|
import { parseProperties as parsePropertiesBinary } from "../flatgeobuf/3.27.2/generic/feature.js";
|
|
8
8
|
const deserializeGeoJson = geojson.deserialize;
|
|
9
9
|
const deserializeGeneric = generic.deserialize;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-flatgeobuf.js","names":["Proj4Projection","transformGeoJsonCoords","fgbToBinaryGeometry","getSchemaFromFGBHeader","geojson","generic","parseProperties","parsePropertiesBinary","deserializeGeoJson","deserialize","deserializeGeneric","binaryFromFeature","feature","header","geometry","geometryType","type","parsedGeometry","properties","columns","parseFlatGeobuf","arrayBuffer","options","_options$flatgeobuf","shape","flatgeobuf","parseFlatGeobufToGeoJSONTable","binary","parseFlatGeobufToBinary","data","Error","arguments","length","undefined","array","Uint8Array","byteLength","features","reproject","_targetCrs","gis","arr","fgbHeader","schema","headerMeta","crs","projection","from","wkt","to","e","coords","project","parseFlatGeobufInBatches","stream","_options$flatgeobuf2","parseFlatGeobufInBatchesToBinary","parseFlatGeobufInBatchesToGeoJSON","iterator","firstRecord"],"sources":["../../src/lib/parse-flatgeobuf.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {transformGeoJsonCoords} from '@loaders.gl/gis';\n\nimport type {FlatGeobufLoaderOptions} from '../flatgeobuf-loader';\nimport type {GeoJSONTable, Table, Schema} from '@loaders.gl/schema';\n\nimport {fgbToBinaryGeometry} from './binary-geometries';\nimport {getSchemaFromFGBHeader} from './get-schema-from-fgb-header';\n\nimport * as fgb from '../flatgeobuf/3.27.2';\nimport * as geojson from '../flatgeobuf/3.27.2/geojson.js';\nimport * as generic from '../flatgeobuf/3.27.2/generic.js';\nimport {parseProperties as parsePropertiesBinary} from '../flatgeobuf/3.27.2/generic/feature';\n\nconst deserializeGeoJson = geojson.deserialize;\nconst deserializeGeneric = generic.deserialize;\n// const parsePropertiesBinary = FlatgeobufFeature.parseProperties;\n\n// TODO: reproject binary features\nfunction binaryFromFeature(feature: fgb.Feature, header: fgb.HeaderMeta) {\n const geometry = feature.geometry();\n\n // FlatGeobuf files can only hold a single geometry type per file, otherwise\n // GeometryType is GeometryCollection\n // I believe geometry.type() is null (0) except when the geometry type isn't\n // known in the header?\n const geometryType = header.geometryType || geometry?.type();\n const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType!);\n // @ts-expect-error this looks wrong\n parsedGeometry.properties = parsePropertiesBinary(feature, header.columns);\n\n // TODO: wrap binary data either in points, lines, or polygons key\n return parsedGeometry;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object\n */\nexport function parseFlatGeobuf(\n arrayBuffer: ArrayBuffer,\n options?: FlatGeobufLoaderOptions\n): Table {\n const shape = options?.flatgeobuf?.shape;\n\n switch (shape) {\n case 'geojson-table': {\n return parseFlatGeobufToGeoJSONTable(arrayBuffer, options);\n }\n\n case 'columnar-table': // binary + some JS arrays\n const binary = parseFlatGeobufToBinary(arrayBuffer, options);\n // @ts-expect-error\n return {shape: 'columnar-table', data: binary};\n\n case 'binary':\n // @ts-expect-error\n return parseFlatGeobufToBinary(arrayBuffer, options);\n\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseFlatGeobufToBinary(arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions = {}) {\n // TODO: reproject binary features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const array = new Uint8Array(arrayBuffer);\n // @ts-expect-error\n return deserializeGeneric(array, fgbToBinaryGeometry);\n}\n\nfunction parseFlatGeobufToGeoJSONTable(\n arrayBuffer: ArrayBuffer,\n options: FlatGeobufLoaderOptions = {}\n): GeoJSONTable {\n if (arrayBuffer.byteLength === 0) {\n return {shape: 'geojson-table', type: 'FeatureCollection', features: []};\n }\n\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const arr = new Uint8Array(arrayBuffer);\n\n let fgbHeader;\n let schema: Schema | undefined;\n\n // @ts-expect-error this looks wrong\n let {features} = deserializeGeoJson(arr, undefined, (headerMeta) => {\n fgbHeader = headerMeta;\n schema = getSchemaFromFGBHeader(fgbHeader);\n });\n\n const crs = fgbHeader && fgbHeader.crs;\n let projection;\n if (reproject && crs) {\n // Constructing the projection may fail for some invalid WKT strings\n try {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n } catch (e) {\n // no op\n }\n }\n\n if (projection) {\n features = transformGeoJsonCoords(features, (coords) => projection.project(coords));\n }\n\n return {shape: 'geojson-table', schema, type: 'FeatureCollection', features};\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param {ReadableStream} _ A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object iterator\n */\n// eslint-disable-next-line complexity\nexport function parseFlatGeobufInBatches(stream, options: FlatGeobufLoaderOptions) {\n const shape = options.flatgeobuf?.shape;\n switch (shape) {\n case 'binary':\n return parseFlatGeobufInBatchesToBinary(stream, options);\n case 'geojson-table':\n return parseFlatGeobufInBatchesToGeoJSON(stream, options);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseFlatGeobufInBatchesToBinary(stream, options: FlatGeobufLoaderOptions) {\n // TODO: reproject binary streaming features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n // @ts-expect-error\n const iterator = deserializeGeneric(stream, binaryFromFeature);\n return iterator;\n}\n\n/**\n * @todo this does not return proper GeoJSONTable batches\n * @param stream\n * @param options\n */\n// eslint-disable-next-line complexity\nasync function* parseFlatGeobufInBatchesToGeoJSON(stream, options: FlatGeobufLoaderOptions) {\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n let fgbHeader;\n // let schema: Schema | undefined;\n const iterator = deserializeGeoJson(stream, undefined, (headerMeta) => {\n fgbHeader = headerMeta;\n // schema = getSchemaFromFGBHeader(fgbHeader);\n });\n\n let projection;\n let firstRecord = true;\n // @ts-expect-error this looks wrong\n for await (const feature of iterator) {\n if (firstRecord) {\n const crs = fgbHeader && fgbHeader.crs;\n if (reproject && crs) {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n }\n\n firstRecord = false;\n }\n\n if (reproject && projection) {\n // eslint-disable-next-line\n yield transformGeoJsonCoords([feature], (coords) => projection.project(coords));\n } else {\n yield feature;\n }\n }\n}\n"],"mappings":"AAIA,SAAQA,eAAe,QAAO,gBAAgB;AAC9C,SAAQC,sBAAsB,QAAO,iBAAiB;AAAC,SAK/CC,mBAAmB;AAAA,SACnBC,sBAAsB;AAG9B,OAAO,KAAKC,OAAO,MAAM,iCAAiC;AAC1D,OAAO,KAAKC,OAAO,MAAM,iCAAiC;AAAC,SACnDC,eAAe,IAAIC,qBAAqB;AAEhD,MAAMC,kBAAkB,GAAGJ,OAAO,CAACK,WAAW;AAC9C,MAAMC,kBAAkB,GAAGL,OAAO,CAACI,WAAW;AAI9C,SAASE,iBAAiBA,CAACC,OAAoB,EAAEC,MAAsB,EAAE;EACvE,MAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAQ,CAAC,CAAC;EAMnC,MAAMC,YAAY,GAAGF,MAAM,CAACE,YAAY,KAAID,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,CAAC,CAAC;EAC5D,MAAMC,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AAGuC,MAAM,IAAKL,UAAU,CAACM,OAAO,CAACD,MAAM,CAAC,CAAC;IACjF,CAAC,MAAM;MACL,MAAMvC,OAAO;IACf;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"parse-flatgeobuf.js","names":["Proj4Projection","transformGeoJsonCoords","fgbToBinaryGeometry","getSchemaFromFGBHeader","geojson","generic","parseProperties","parsePropertiesBinary","deserializeGeoJson","deserialize","deserializeGeneric","binaryFromFeature","feature","header","geometry","geometryType","type","parsedGeometry","properties","columns","parseFlatGeobuf","arrayBuffer","options","_options$flatgeobuf","shape","flatgeobuf","parseFlatGeobufToGeoJSONTable","binary","parseFlatGeobufToBinary","data","Error","arguments","length","undefined","array","Uint8Array","byteLength","features","reproject","_targetCrs","gis","arr","fgbHeader","schema","headerMeta","crs","projection","from","wkt","to","e","coords","project","parseFlatGeobufInBatches","stream","_options$flatgeobuf2","parseFlatGeobufInBatchesToBinary","parseFlatGeobufInBatchesToGeoJSON","iterator","firstRecord"],"sources":["../../src/lib/parse-flatgeobuf.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {transformGeoJsonCoords} from '@loaders.gl/gis';\n\nimport type {FlatGeobufLoaderOptions} from '../flatgeobuf-loader';\nimport type {GeoJSONTable, Table, Schema} from '@loaders.gl/schema';\n\nimport {fgbToBinaryGeometry} from './binary-geometries';\nimport {getSchemaFromFGBHeader} from './get-schema-from-fgb-header';\n\nimport * as fgb from '../flatgeobuf/3.27.2';\nimport * as geojson from '../flatgeobuf/3.27.2/geojson';\nimport * as generic from '../flatgeobuf/3.27.2/generic';\nimport {parseProperties as parsePropertiesBinary} from '../flatgeobuf/3.27.2/generic/feature';\n\nconst deserializeGeoJson = geojson.deserialize;\nconst deserializeGeneric = generic.deserialize;\n// const parsePropertiesBinary = FlatgeobufFeature.parseProperties;\n\n// TODO: reproject binary features\nfunction binaryFromFeature(feature: fgb.Feature, header: fgb.HeaderMeta) {\n const geometry = feature.geometry();\n\n // FlatGeobuf files can only hold a single geometry type per file, otherwise\n // GeometryType is GeometryCollection\n // I believe geometry.type() is null (0) except when the geometry type isn't\n // known in the header?\n const geometryType = header.geometryType || geometry?.type();\n const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType!);\n // @ts-expect-error this looks wrong\n parsedGeometry.properties = parsePropertiesBinary(feature, header.columns);\n\n // TODO: wrap binary data either in points, lines, or polygons key\n return parsedGeometry;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object\n */\nexport function parseFlatGeobuf(\n arrayBuffer: ArrayBuffer,\n options?: FlatGeobufLoaderOptions\n): Table {\n const shape = options?.flatgeobuf?.shape;\n\n switch (shape) {\n case 'geojson-table': {\n return parseFlatGeobufToGeoJSONTable(arrayBuffer, options);\n }\n\n case 'columnar-table': // binary + some JS arrays\n const binary = parseFlatGeobufToBinary(arrayBuffer, options);\n // @ts-expect-error\n return {shape: 'columnar-table', data: binary};\n\n case 'binary':\n // @ts-expect-error\n return parseFlatGeobufToBinary(arrayBuffer, options);\n\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseFlatGeobufToBinary(arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions = {}) {\n // TODO: reproject binary features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const array = new Uint8Array(arrayBuffer);\n // @ts-expect-error\n return deserializeGeneric(array, fgbToBinaryGeometry);\n}\n\nfunction parseFlatGeobufToGeoJSONTable(\n arrayBuffer: ArrayBuffer,\n options: FlatGeobufLoaderOptions = {}\n): GeoJSONTable {\n if (arrayBuffer.byteLength === 0) {\n return {shape: 'geojson-table', type: 'FeatureCollection', features: []};\n }\n\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const arr = new Uint8Array(arrayBuffer);\n\n let fgbHeader;\n let schema: Schema | undefined;\n\n // @ts-expect-error this looks wrong\n let {features} = deserializeGeoJson(arr, undefined, (headerMeta) => {\n fgbHeader = headerMeta;\n schema = getSchemaFromFGBHeader(fgbHeader);\n });\n\n const crs = fgbHeader && fgbHeader.crs;\n let projection;\n if (reproject && crs) {\n // Constructing the projection may fail for some invalid WKT strings\n try {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n } catch (e) {\n // no op\n }\n }\n\n if (projection) {\n features = transformGeoJsonCoords(features, (coords) => projection.project(coords));\n }\n\n return {shape: 'geojson-table', schema, type: 'FeatureCollection', features};\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param {ReadableStream} _ A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object iterator\n */\n// eslint-disable-next-line complexity\nexport function parseFlatGeobufInBatches(stream, options: FlatGeobufLoaderOptions) {\n const shape = options.flatgeobuf?.shape;\n switch (shape) {\n case 'binary':\n return parseFlatGeobufInBatchesToBinary(stream, options);\n case 'geojson-table':\n return parseFlatGeobufInBatchesToGeoJSON(stream, options);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseFlatGeobufInBatchesToBinary(stream, options: FlatGeobufLoaderOptions) {\n // TODO: reproject binary streaming features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n // @ts-expect-error\n const iterator = deserializeGeneric(stream, binaryFromFeature);\n return iterator;\n}\n\n/**\n * @todo this does not return proper GeoJSONTable batches\n * @param stream\n * @param options\n */\n// eslint-disable-next-line complexity\nasync function* parseFlatGeobufInBatchesToGeoJSON(stream, options: FlatGeobufLoaderOptions) {\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n let fgbHeader;\n // let schema: Schema | undefined;\n const iterator = deserializeGeoJson(stream, undefined, (headerMeta) => {\n fgbHeader = headerMeta;\n // schema = getSchemaFromFGBHeader(fgbHeader);\n });\n\n let projection;\n let firstRecord = true;\n // @ts-expect-error this looks wrong\n for await (const feature of iterator) {\n if (firstRecord) {\n const crs = fgbHeader && fgbHeader.crs;\n if (reproject && crs) {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n }\n\n firstRecord = false;\n }\n\n if (reproject && projection) {\n // eslint-disable-next-line\n yield transformGeoJsonCoords([feature], (coords) => projection.project(coords));\n } else {\n yield feature;\n }\n }\n}\n"],"mappings":"AAIA,SAAQA,eAAe,QAAO,gBAAgB;AAC9C,SAAQC,sBAAsB,QAAO,iBAAiB;AAAC,SAK/CC,mBAAmB;AAAA,SACnBC,sBAAsB;AAAA,OAGvB,KAAKC,OAAO;AAAA,OACZ,KAAKC,OAAO;AAAA,SACXC,eAAe,IAAIC,qBAAqB;AAEhD,MAAMC,kBAAkB,GAAGJ,OAAO,CAACK,WAAW;AAC9C,MAAMC,kBAAkB,GAAGL,OAAO,CAACI,WAAW;AAI9C,SAASE,iBAAiBA,CAACC,OAAoB,EAAEC,MAAsB,EAAE;EACvE,MAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAQ,CAAC,CAAC;EAMnC,MAAMC,YAAY,GAAGF,MAAM,CAACE,YAAY,KAAID,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,CAAC,CAAC;EAC5D,MAAMC,cAAc,GAAGf,mBAAmB,CAACY,QAAQ,EAAEC,YAAa,CAAC;EAEnEE,cAAc,CAACC,UAAU,GAAGX,qBAAqB,CAACK,OAAO,EAAEC,MAAM,CAACM,OAAO,CAAC;EAG1E,OAAOF,cAAc;AACvB;AAQA,OAAO,SAASG,eAAeA,CAC7BC,WAAwB,EACxBC,OAAiC,EAC1B;EAAA,IAAAC,mBAAA;EACP,MAAMC,KAAK,GAAGF,OAAO,aAAPA,OAAO,wBAAAC,mBAAA,GAAPD,OAAO,CAAEG,UAAU,cAAAF,mBAAA,uBAAnBA,mBAAA,CAAqBC,KAAK;EAExC,QAAQA,KAAK;IACX,KAAK,eAAe;MAAE;QACpB,OAAOE,6BAA6B,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CAAiCA,CAACH,MAAM,EAAEhC,OAAgC,EAAE;EAC1F,MAAM;IAACgB,SAAS,GAAG,KAAK;IAAEC,UAAU,GAAG;EAAO,CAAC,GAAIjB,OAAO,IAAIA,OAAO,CAACkB,GAAG,IAAK,CAAC,CAAC;EAEhF,IAAIE,SAAS;EAEb,MAAMgB,QAAQ,GAAGlD,kBAAkB,CAAC8C,MAAM,EAAErB,SAAS,EAAGW,UAAU,IAAK;IACrEF,SAAS,GAAGE,UAAU;EAExB,CAAC,CAAC;EAEF,IAAIE,UAAU;EACd,IAAIa,WAAW,GAAG,IAAI;EAEtB,WAAW,MAAM/C,OAAO,IAAI8C,QAAQ,EAAE;IACpC,IAAIC,WAAW,EAAE;MACf,MAAMd,GAAG,GAAGH,SAAS,IAAIA,SAAS,CAACG,GAAG;MACtC,IAAIP,SAAS,IAAIO,GAAG,EAAE;QACpBC,UAAU,GAAG,IAAI9C,eAAe,CAAC;UAAC+C,IAAI,EAAEF,GAAG,CAACG,GAAG;UAAEC,EAAE,EAAEV;QAAU,CAAC,CAAC;MACnE;MAEAoB,WAAW,GAAG,KAAK;IACrB;IAEA,IAAIrB,SAAS,IAAIQ,UAAU,EAAE;MAE3B,MAAM7C,sBAAsB,CAAC,CAACW,OAAO,CAAC,EAAGuC,MAAM,IAAKL,UAAU,CAACM,OAAO,CAACD,MAAM,CAAC,CAAC;IACjF,CAAC,MAAM;MACL,MAAMvC,OAAO;IACf;EACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/flatgeobuf",
|
|
3
3
|
"description": "Loader for FlatGeobuf",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"module": "dist/index.js",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
29
30
|
"import": "./dist/index.js",
|
|
30
|
-
"require": "./dist/index.cjs"
|
|
31
|
-
"types": "./dist/index.d.ts"
|
|
31
|
+
"require": "./dist/index.cjs"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"sideEffects": false,
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"build-worker": "esbuild src/workers/flatgeobuf-worker.ts --bundle --outfile=dist/flatgeobuf-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@loaders.gl/gis": "4.1.
|
|
47
|
-
"@loaders.gl/loader-utils": "4.1.
|
|
46
|
+
"@loaders.gl/gis": "4.1.1",
|
|
47
|
+
"@loaders.gl/loader-utils": "4.1.1",
|
|
48
48
|
"@math.gl/proj4": "^4.0.0",
|
|
49
49
|
"flatgeobuf": "3.27.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"stream-buffers": "3.0.2"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "b4a8cb4e5c2b67ac0e1afaa21ae45b3a45a91db0"
|
|
55
55
|
}
|
|
Binary file
|
|
@@ -7,9 +7,9 @@ import GeometryFactory from 'jsts/org/locationtech/jts/geom/GeometryFactory.js';
|
|
|
7
7
|
import GeoJSONWriter from 'jsts/org/locationtech/jts/io/GeoJSONWriter.js';
|
|
8
8
|
import {readFileSync, writeFileSync} from 'fs';
|
|
9
9
|
|
|
10
|
-
import {magicbytes, SIZE_PREFIX_LEN} from './constants
|
|
11
|
-
import {fromByteBuffer} from './header-meta
|
|
12
|
-
import {calcTreeSize, generateLevelBounds} from './packedrtree
|
|
10
|
+
import {magicbytes, SIZE_PREFIX_LEN} from './constants';
|
|
11
|
+
import {fromByteBuffer} from './header-meta';
|
|
12
|
+
import {calcTreeSize, generateLevelBounds} from './packedrtree';
|
|
13
13
|
|
|
14
14
|
const buffer = readFileSync('./test/data/tiger_roads.fgb');
|
|
15
15
|
const bytes = new Uint8Array(buffer);
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import * as flatbuffers from 'flatbuffers';
|
|
4
4
|
|
|
5
|
-
import {Column} from '../flat-geobuf/column
|
|
6
|
-
import {Geometry} from '../flat-geobuf/geometry
|
|
5
|
+
import {Column} from '../flat-geobuf/column';
|
|
6
|
+
import {Geometry} from '../flat-geobuf/geometry';
|
|
7
7
|
|
|
8
8
|
export class Feature {
|
|
9
9
|
bb: flatbuffers.ByteBuffer | null = null;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import * as flatbuffers from 'flatbuffers';
|
|
4
4
|
|
|
5
|
-
import {Column} from '../flat-geobuf/column
|
|
6
|
-
import {Crs} from '../flat-geobuf/crs
|
|
7
|
-
import {GeometryType} from '../flat-geobuf/geometry-type
|
|
5
|
+
import {Column} from '../flat-geobuf/column';
|
|
6
|
+
import {Crs} from '../flat-geobuf/crs';
|
|
7
|
+
import {GeometryType} from '../flat-geobuf/geometry-type';
|
|
8
8
|
|
|
9
9
|
export class Header {
|
|
10
10
|
bb: flatbuffers.ByteBuffer | null = null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// automatically generated by the FlatBuffers compiler, do not modify
|
|
2
2
|
|
|
3
|
-
export {Column} from './flat-geobuf/column
|
|
4
|
-
export {ColumnType} from './flat-geobuf/column-type
|
|
5
|
-
export {Crs} from './flat-geobuf/crs
|
|
6
|
-
export {GeometryType} from './flat-geobuf/geometry-type
|
|
7
|
-
export {Header} from './flat-geobuf/header
|
|
3
|
+
export {Column} from './flat-geobuf/column';
|
|
4
|
+
export {ColumnType} from './flat-geobuf/column-type';
|
|
5
|
+
export {Crs} from './flat-geobuf/crs';
|
|
6
|
+
export {GeometryType} from './flat-geobuf/geometry-type';
|
|
7
|
+
export {Header} from './flat-geobuf/header';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as flatbuffers from 'flatbuffers';
|
|
2
2
|
|
|
3
|
-
import ColumnMeta from '../column-meta
|
|
4
|
-
import {ColumnType} from '../flat-geobuf/column-type
|
|
5
|
-
import {Feature} from '../flat-geobuf/feature
|
|
6
|
-
import HeaderMeta from '../header-meta
|
|
7
|
-
import {buildGeometry, ISimpleGeometry, ICreateGeometry, IParsedGeometry} from './geometry
|
|
3
|
+
import ColumnMeta from '../column-meta';
|
|
4
|
+
import {ColumnType} from '../flat-geobuf/column-type';
|
|
5
|
+
import {Feature} from '../flat-geobuf/feature';
|
|
6
|
+
import HeaderMeta from '../header-meta';
|
|
7
|
+
import {buildGeometry, ISimpleGeometry, ICreateGeometry, IParsedGeometry} from './geometry';
|
|
8
8
|
|
|
9
9
|
const textEncoder = new TextEncoder();
|
|
10
10
|
const textDecoder = new TextDecoder();
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import * as flatbuffers from 'flatbuffers';
|
|
2
2
|
import slice from 'slice-source';
|
|
3
3
|
|
|
4
|
-
import ColumnMeta from '../column-meta
|
|
5
|
-
|
|
6
|
-
import {Header} from '../flat-geobuf/header
|
|
7
|
-
|
|
8
|
-
import {Column} from '../flat-geobuf/column
|
|
9
|
-
import {ColumnType} from '../flat-geobuf/column-type
|
|
10
|
-
import {Feature} from '../flat-geobuf/feature
|
|
11
|
-
import HeaderMeta, {fromByteBuffer} from '../header-meta
|
|
12
|
-
|
|
13
|
-
import {buildFeature, IFeature} from './feature
|
|
14
|
-
import {HttpReader} from '../http-reader
|
|
15
|
-
import Logger from '../logger
|
|
16
|
-
import {Rect, calcTreeSize} from '../packedrtree
|
|
17
|
-
import {parseGeometry} from './geometry
|
|
18
|
-
import {HeaderMetaFn} from '../generic
|
|
19
|
-
import {magicbytes, SIZE_PREFIX_LEN} from '../constants
|
|
20
|
-
import {inferGeometryType} from './header
|
|
4
|
+
import ColumnMeta from '../column-meta';
|
|
5
|
+
|
|
6
|
+
import {Header} from '../flat-geobuf/header';
|
|
7
|
+
|
|
8
|
+
import {Column} from '../flat-geobuf/column';
|
|
9
|
+
import {ColumnType} from '../flat-geobuf/column-type';
|
|
10
|
+
import {Feature} from '../flat-geobuf/feature';
|
|
11
|
+
import HeaderMeta, {fromByteBuffer} from '../header-meta';
|
|
12
|
+
|
|
13
|
+
import {buildFeature, IFeature} from './feature';
|
|
14
|
+
import {HttpReader} from '../http-reader';
|
|
15
|
+
import Logger from '../logger';
|
|
16
|
+
import {Rect, calcTreeSize} from '../packedrtree';
|
|
17
|
+
import {parseGeometry} from './geometry';
|
|
18
|
+
import {HeaderMetaFn} from '../generic';
|
|
19
|
+
import {magicbytes, SIZE_PREFIX_LEN} from '../constants';
|
|
20
|
+
import {inferGeometryType} from './header';
|
|
21
21
|
|
|
22
22
|
export type FromFeatureFn = (feature: Feature, header: HeaderMeta) => IFeature;
|
|
23
23
|
type ReadFn = (size: number, purpose: string) => Promise<ArrayBuffer>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as flatbuffers from 'flatbuffers';
|
|
2
|
-
import {GeometryType} from '../flat-geobuf/geometry-type
|
|
3
|
-
import {Geometry} from '../flat-geobuf/geometry
|
|
2
|
+
import {GeometryType} from '../flat-geobuf/geometry-type';
|
|
3
|
+
import {Geometry} from '../flat-geobuf/geometry';
|
|
4
4
|
|
|
5
5
|
export interface IParsedGeometry {
|
|
6
6
|
xy: number[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {GeometryType} from '../flat-geobuf/geometry-type
|
|
2
|
-
import {toGeometryType} from '../generic/geometry
|
|
3
|
-
import {IFeature} from './feature
|
|
4
|
-
import {IGeoJsonFeature} from '../geojson/feature
|
|
1
|
+
import {GeometryType} from '../flat-geobuf/geometry-type';
|
|
2
|
+
import {toGeometryType} from '../generic/geometry';
|
|
3
|
+
import {IFeature} from './feature';
|
|
4
|
+
import {IGeoJsonFeature} from '../geojson/feature';
|
|
5
5
|
|
|
6
6
|
function featureGeomType(feature: IFeature | IGeoJsonFeature): GeometryType {
|
|
7
7
|
if (feature.getGeometry) {
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
deserializeStream,
|
|
4
4
|
deserializeFiltered,
|
|
5
5
|
FromFeatureFn
|
|
6
|
-
} from './generic/featurecollection
|
|
6
|
+
} from './generic/featurecollection';
|
|
7
7
|
|
|
8
|
-
import {Rect} from './packedrtree
|
|
9
|
-
import {IFeature} from './generic/feature
|
|
10
|
-
import HeaderMeta from './header-meta
|
|
8
|
+
import {Rect} from './packedrtree';
|
|
9
|
+
import {IFeature} from './generic/feature';
|
|
10
|
+
import HeaderMeta from './header-meta';
|
|
11
11
|
|
|
12
12
|
export type HeaderMetaFn = (headerMeta: HeaderMeta) => void;
|
|
13
13
|
|
|
@@ -27,7 +27,7 @@ export function deserialize(
|
|
|
27
27
|
return deserializeFiltered(input, rect as Rect, fromFeature);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export {serialize} from './generic/featurecollection
|
|
30
|
+
export {serialize} from './generic/featurecollection';
|
|
31
31
|
|
|
32
|
-
export {GeometryType} from './flat-geobuf/geometry-type
|
|
33
|
-
export {ColumnType} from './flat-geobuf/column-type
|
|
32
|
+
export {GeometryType} from './flat-geobuf/geometry-type';
|
|
33
|
+
export {ColumnType} from './flat-geobuf/column-type';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {Feature} from '../flat-geobuf/feature
|
|
2
|
-
import {Geometry} from '../flat-geobuf/geometry
|
|
3
|
-
import HeaderMeta from '../header-meta
|
|
4
|
-
import {fromGeometry} from './geometry
|
|
5
|
-
import {IFeature, parseProperties} from '../generic/feature
|
|
1
|
+
import {Feature} from '../flat-geobuf/feature';
|
|
2
|
+
import {Geometry} from '../flat-geobuf/geometry';
|
|
3
|
+
import HeaderMeta from '../header-meta';
|
|
4
|
+
import {fromGeometry} from './geometry';
|
|
5
|
+
import {IFeature, parseProperties} from '../generic/feature';
|
|
6
6
|
|
|
7
7
|
import {Feature as GeoJsonFeature} from 'geojson';
|
|
8
8
|
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import ColumnMeta from '../column-meta
|
|
2
|
-
import HeaderMeta from '../header-meta
|
|
1
|
+
import ColumnMeta from '../column-meta';
|
|
2
|
+
import HeaderMeta from '../header-meta';
|
|
3
3
|
|
|
4
|
-
import {fromFeature} from './feature
|
|
5
|
-
import {parseGeometry, parseGC} from './geometry
|
|
4
|
+
import {fromFeature} from './feature';
|
|
5
|
+
import {parseGeometry, parseGC} from './geometry';
|
|
6
6
|
import {
|
|
7
7
|
buildHeader,
|
|
8
8
|
deserialize as genericDeserialize,
|
|
9
9
|
deserializeStream as genericDeserializeStream,
|
|
10
10
|
deserializeFiltered as genericDeserializeFiltered,
|
|
11
11
|
mapColumn
|
|
12
|
-
} from '../generic/featurecollection
|
|
13
|
-
import {Rect} from '../packedrtree
|
|
14
|
-
import {buildFeature, IProperties} from '../generic/feature
|
|
15
|
-
import {HeaderMetaFn} from '../generic
|
|
16
|
-
import {magicbytes} from '../constants
|
|
17
|
-
import {inferGeometryType} from '../generic/header
|
|
12
|
+
} from '../generic/featurecollection';
|
|
13
|
+
import {Rect} from '../packedrtree';
|
|
14
|
+
import {buildFeature, IProperties} from '../generic/feature';
|
|
15
|
+
import {HeaderMetaFn} from '../generic';
|
|
16
|
+
import {magicbytes} from '../constants';
|
|
17
|
+
import {inferGeometryType} from '../generic/header';
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
20
|
FeatureCollection as GeoJsonFeatureCollection,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {GeometryType} from '../flat-geobuf/geometry-type
|
|
2
|
-
import {Geometry} from '../flat-geobuf/geometry
|
|
1
|
+
import {GeometryType} from '../flat-geobuf/geometry-type';
|
|
2
|
+
import {Geometry} from '../flat-geobuf/geometry';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
Geometry as GeoJsonGeometry,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
GeometryCollection
|
|
13
13
|
} from 'geojson';
|
|
14
14
|
|
|
15
|
-
import {IParsedGeometry, flat, pairFlatCoordinates, toGeometryType} from '../generic/geometry
|
|
15
|
+
import {IParsedGeometry, flat, pairFlatCoordinates, toGeometryType} from '../generic/geometry';
|
|
16
16
|
|
|
17
17
|
export interface IGeoJsonGeometry {
|
|
18
18
|
type: string;
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
deserializeStream as fcDeserializeStream,
|
|
4
4
|
deserializeFiltered as fcDeserializeFiltered,
|
|
5
5
|
serialize as fcSerialize
|
|
6
|
-
} from './geojson/featurecollection
|
|
6
|
+
} from './geojson/featurecollection';
|
|
7
7
|
|
|
8
8
|
import {FeatureCollection as GeoJsonFeatureCollection} from 'geojson';
|
|
9
9
|
|
|
10
|
-
import {Rect} from './packedrtree
|
|
11
|
-
import {IGeoJsonFeature} from './geojson/feature
|
|
12
|
-
import {HeaderMetaFn} from './generic
|
|
10
|
+
import {Rect} from './packedrtree';
|
|
11
|
+
import {IGeoJsonFeature} from './geojson/feature';
|
|
12
|
+
import {HeaderMetaFn} from './generic';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Serialize GeoJSON to FlatGeobuf
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as flatbuffers from 'flatbuffers';
|
|
2
2
|
|
|
3
|
-
import ColumnMeta from './column-meta
|
|
4
|
-
import CrsMeta from './crs-meta
|
|
5
|
-
import {GeometryType} from './flat-geobuf/geometry-type
|
|
6
|
-
import {Header} from './flat-geobuf/header
|
|
3
|
+
import ColumnMeta from './column-meta';
|
|
4
|
+
import CrsMeta from './crs-meta';
|
|
5
|
+
import {GeometryType} from './flat-geobuf/geometry-type';
|
|
6
|
+
import {Header} from './flat-geobuf/header';
|
|
7
7
|
|
|
8
8
|
export default interface HeaderMeta {
|
|
9
9
|
geometryType: GeometryType;
|