@loaders.gl/flatgeobuf 4.2.0-alpha.4 → 4.2.0-alpha.6
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 +264 -218
- package/dist/dist.min.js +30 -0
- 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 +1 -2
- package/dist/flatgeobuf/3.27.2/config.js +13 -13
- package/dist/flatgeobuf/3.27.2/constants.js +3 -2
- package/dist/flatgeobuf/3.27.2/crs-meta.js +1 -2
- package/dist/flatgeobuf/3.27.2/dumptree.js +28 -23
- 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 +2 -3
- package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js +19 -19
- 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 +115 -117
- package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js +74 -76
- 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 +94 -90
- package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js +22 -22
- 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 +222 -210
- 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 +164 -160
- 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 +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 +195 -205
- 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 +150 -128
- 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 +78 -66
- 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 +18 -18
- package/dist/flatgeobuf/3.27.2/generic/index.d.ts +4 -4
- package/dist/flatgeobuf/3.27.2/generic/index.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/generic/index.js +2 -1
- 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 +11 -3
- 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 +8 -9
- 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 +40 -38
- 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 +107 -103
- package/dist/flatgeobuf/3.27.2/geojson/index.d.ts +3 -3
- package/dist/flatgeobuf/3.27.2/geojson/index.d.ts.map +1 -1
- package/dist/flatgeobuf/3.27.2/geojson/index.js +2 -1
- 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 +17 -5
- 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 +46 -43
- 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 +2 -3
- 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 +241 -171
- 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 +5 -13
- package/dist/flatgeobuf/3.27.2/logger.js +36 -56
- package/dist/flatgeobuf/3.27.2/packedrtree.js +176 -123
- package/dist/flatgeobuf/3.27.2/streams/utils.js +59 -58
- package/dist/flatgeobuf-loader.js +29 -23
- package/dist/flatgeobuf-worker.js +40 -35
- package/dist/index.cjs +191 -213
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/binary-geometries.js +115 -117
- package/dist/lib/get-schema-from-fgb-header.js +110 -85
- package/dist/lib/parse-flatgeobuf.d.ts +1 -1
- package/dist/lib/parse-flatgeobuf.d.ts.map +1 -1
- package/dist/lib/parse-flatgeobuf.js +125 -109
- package/dist/workers/flatgeobuf-worker.js +3 -1
- package/package.json +11 -6
- package/dist/LICENSE +0 -9
- package/dist/flatgeobuf/3.27.2/LICENSE +0 -29
- package/dist/flatgeobuf/3.27.2/README.md +0 -45
- package/dist/flatgeobuf/3.27.2/column-meta.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/config.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/constants.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/crs-meta.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/dumptree.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/feature.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/flat-geobuf.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/generic/feature.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/generic/featurecollection.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/generic/geometry.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/generic/header.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/generic/index.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/generic.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/geojson/feature.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/geojson/geometry.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/geojson/index.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/geojson.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/header-meta.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/header.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/http-reader.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/index.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/logger.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/packedrtree.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/streams/utils.js.map +0 -1
- package/dist/flatgeobuf/3.27.2/types/jsts.d.ts +0 -23
- package/dist/flatgeobuf/3.27.2/types/slice.d.ts +0 -16
- package/dist/flatgeobuf-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-geometries.js.map +0 -1
- package/dist/lib/get-schema-from-fgb-header.js.map +0 -1
- package/dist/lib/parse-flatgeobuf.js.map +0 -1
- package/dist/workers/flatgeobuf-worker.js.map +0 -1
|
@@ -12,151 +12,173 @@ import { calcTreeSize } from "../packedrtree.js";
|
|
|
12
12
|
import { parseGeometry } from "./geometry.js";
|
|
13
13
|
import { magicbytes, SIZE_PREFIX_LEN } from "../constants.js";
|
|
14
14
|
import { inferGeometryType } from "./header.js";
|
|
15
|
+
/**
|
|
16
|
+
* Serialize generic features to FlatGeobuf
|
|
17
|
+
* @param features
|
|
18
|
+
*/
|
|
15
19
|
export function serialize(features) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
const headerMeta = introspectHeaderMeta(features);
|
|
21
|
+
const header = buildHeader(headerMeta);
|
|
22
|
+
const featureBuffers = features.map((f) => {
|
|
23
|
+
if (!f.getGeometry)
|
|
24
|
+
throw new Error('Missing getGeometry implementation');
|
|
25
|
+
if (!f.getProperties)
|
|
26
|
+
throw new Error('Missing getProperties implementation');
|
|
27
|
+
return buildFeature(parseGeometry(f.getGeometry(), headerMeta.geometryType), f.getProperties(), headerMeta);
|
|
28
|
+
});
|
|
29
|
+
const featuresLength = featureBuffers.map((f) => f.length).reduce((a, b) => a + b);
|
|
30
|
+
const uint8 = new Uint8Array(magicbytes.length + header.length + featuresLength);
|
|
31
|
+
uint8.set(header, magicbytes.length);
|
|
32
|
+
let offset = magicbytes.length + header.length;
|
|
33
|
+
for (const feature of featureBuffers) {
|
|
34
|
+
uint8.set(feature, offset);
|
|
35
|
+
offset += feature.length;
|
|
36
|
+
}
|
|
37
|
+
uint8.set(magicbytes);
|
|
38
|
+
return uint8;
|
|
33
39
|
}
|
|
34
40
|
export function deserialize(bytes, fromFeature, headerMetaFn) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
featuresCount
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
if (!bytes.subarray(0, 3).every((v, i) => magicbytes[i] === v))
|
|
42
|
+
throw new Error('Not a FlatGeobuf file');
|
|
43
|
+
const bb = new flatbuffers.ByteBuffer(bytes);
|
|
44
|
+
const headerLength = bb.readUint32(magicbytes.length);
|
|
45
|
+
bb.setPosition(magicbytes.length + SIZE_PREFIX_LEN);
|
|
46
|
+
const headerMeta = fromByteBuffer(bb);
|
|
47
|
+
if (headerMetaFn)
|
|
48
|
+
headerMetaFn(headerMeta);
|
|
49
|
+
let offset = magicbytes.length + SIZE_PREFIX_LEN + headerLength;
|
|
50
|
+
const { indexNodeSize, featuresCount } = headerMeta;
|
|
51
|
+
if (indexNodeSize > 0)
|
|
52
|
+
offset += calcTreeSize(featuresCount, indexNodeSize);
|
|
53
|
+
const features = [];
|
|
54
|
+
while (offset < bb.capacity()) {
|
|
55
|
+
const featureLength = bb.readUint32(offset);
|
|
56
|
+
bb.setPosition(offset + SIZE_PREFIX_LEN);
|
|
57
|
+
const feature = Feature.getRootAsFeature(bb);
|
|
58
|
+
features.push(fromFeature(feature, headerMeta));
|
|
59
|
+
offset += SIZE_PREFIX_LEN + featureLength;
|
|
60
|
+
}
|
|
61
|
+
return features;
|
|
56
62
|
}
|
|
57
63
|
export async function* deserializeStream(stream, fromFeature, headerMetaFn) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
featuresCount
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
const reader = slice(stream);
|
|
65
|
+
const read = async (size) => await reader.slice(size);
|
|
66
|
+
let bytes = new Uint8Array(await read(8, 'magic bytes'));
|
|
67
|
+
if (!bytes.subarray(0, 3).every((v, i) => magicbytes[i] === v))
|
|
68
|
+
throw new Error('Not a FlatGeobuf file');
|
|
69
|
+
bytes = new Uint8Array(await read(4, 'header length'));
|
|
70
|
+
let bb = new flatbuffers.ByteBuffer(bytes);
|
|
71
|
+
const headerLength = bb.readUint32(0);
|
|
72
|
+
bytes = new Uint8Array(await read(headerLength, 'header data'));
|
|
73
|
+
bb = new flatbuffers.ByteBuffer(bytes);
|
|
74
|
+
const headerMeta = fromByteBuffer(bb);
|
|
75
|
+
if (headerMetaFn)
|
|
76
|
+
headerMetaFn(headerMeta);
|
|
77
|
+
const { indexNodeSize, featuresCount } = headerMeta;
|
|
78
|
+
if (indexNodeSize > 0) {
|
|
79
|
+
const treeSize = calcTreeSize(featuresCount, indexNodeSize);
|
|
80
|
+
await read(treeSize, 'entire index, w/o rect');
|
|
81
|
+
}
|
|
82
|
+
let feature;
|
|
83
|
+
while ((feature = await readFeature(read, headerMeta, fromFeature)))
|
|
84
|
+
yield feature;
|
|
79
85
|
}
|
|
80
86
|
export async function* deserializeFiltered(url, rect, fromFeature, headerMetaFn) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
const reader = await HttpReader.open(url);
|
|
88
|
+
Logger.debug('opened reader');
|
|
89
|
+
if (headerMetaFn)
|
|
90
|
+
headerMetaFn(reader.header);
|
|
91
|
+
for await (const feature of reader.selectBbox(rect)) {
|
|
92
|
+
yield fromFeature(feature, reader.header);
|
|
93
|
+
}
|
|
87
94
|
}
|
|
88
95
|
async function readFeature(read, headerMeta, fromFeature) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
let bytes = new Uint8Array(await read(4, 'feature length'));
|
|
97
|
+
if (bytes.byteLength === 0)
|
|
98
|
+
return;
|
|
99
|
+
let bb = new flatbuffers.ByteBuffer(bytes);
|
|
100
|
+
const featureLength = bb.readUint32(0);
|
|
101
|
+
bytes = new Uint8Array(await read(featureLength, 'feature data'));
|
|
102
|
+
const bytesAligned = new Uint8Array(featureLength + 4);
|
|
103
|
+
bytesAligned.set(bytes, 4);
|
|
104
|
+
bb = new flatbuffers.ByteBuffer(bytesAligned);
|
|
105
|
+
bb.setPosition(SIZE_PREFIX_LEN);
|
|
106
|
+
const feature = Feature.getRootAsFeature(bb);
|
|
107
|
+
return fromFeature(feature, headerMeta);
|
|
100
108
|
}
|
|
101
109
|
function buildColumn(builder, column) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
const nameOffset = builder.createString(column.name);
|
|
111
|
+
Column.startColumn(builder);
|
|
112
|
+
Column.addName(builder, nameOffset);
|
|
113
|
+
Column.addType(builder, column.type);
|
|
114
|
+
return Column.endColumn(builder);
|
|
107
115
|
}
|
|
108
116
|
export function buildHeader(header) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
const builder = new flatbuffers.Builder();
|
|
118
|
+
let columnOffsets = null;
|
|
119
|
+
if (header.columns)
|
|
120
|
+
columnOffsets = Header.createColumnsVector(builder, header.columns.map((c) => buildColumn(builder, c)));
|
|
121
|
+
const nameOffset = builder.createString('L1');
|
|
122
|
+
Header.startHeader(builder);
|
|
123
|
+
Header.addFeaturesCount(builder, BigInt(header.featuresCount));
|
|
124
|
+
Header.addGeometryType(builder, header.geometryType);
|
|
125
|
+
Header.addIndexNodeSize(builder, 0);
|
|
126
|
+
if (columnOffsets)
|
|
127
|
+
Header.addColumns(builder, columnOffsets);
|
|
128
|
+
Header.addName(builder, nameOffset);
|
|
129
|
+
const offset = Header.endHeader(builder);
|
|
130
|
+
builder.finishSizePrefixed(offset);
|
|
131
|
+
return builder.asUint8Array();
|
|
122
132
|
}
|
|
123
133
|
function valueToType(value) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
if (typeof value === 'boolean')
|
|
135
|
+
return ColumnType.Bool;
|
|
136
|
+
else if (typeof value === 'number')
|
|
137
|
+
if (value % 1 === 0)
|
|
138
|
+
return ColumnType.Int;
|
|
139
|
+
else
|
|
140
|
+
return ColumnType.Double;
|
|
141
|
+
else if (typeof value === 'string')
|
|
142
|
+
return ColumnType.String;
|
|
143
|
+
else if (value === null)
|
|
144
|
+
return ColumnType.String;
|
|
145
|
+
else if (typeof value === 'object')
|
|
146
|
+
return ColumnType.Json;
|
|
147
|
+
throw new Error(`Unknown type (value '${value}')`);
|
|
128
148
|
}
|
|
129
149
|
export function mapColumn(properties, k) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
return {
|
|
151
|
+
name: k,
|
|
152
|
+
type: valueToType(properties[k]),
|
|
153
|
+
title: null,
|
|
154
|
+
description: null,
|
|
155
|
+
width: -1,
|
|
156
|
+
precision: -1,
|
|
157
|
+
scale: -1,
|
|
158
|
+
nullable: true,
|
|
159
|
+
unique: false,
|
|
160
|
+
primary_key: false
|
|
161
|
+
};
|
|
142
162
|
}
|
|
143
163
|
function introspectHeaderMeta(features) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
const sampleFeature = features[0];
|
|
165
|
+
const properties = sampleFeature.getProperties ? sampleFeature.getProperties() : {};
|
|
166
|
+
let columns = null;
|
|
167
|
+
if (properties)
|
|
168
|
+
columns = Object.keys(properties)
|
|
169
|
+
.filter((key) => key !== 'geometry')
|
|
170
|
+
.map((k) => mapColumn(properties, k));
|
|
171
|
+
const geometryType = inferGeometryType(features);
|
|
172
|
+
const headerMeta = {
|
|
173
|
+
geometryType,
|
|
174
|
+
columns,
|
|
175
|
+
envelope: null,
|
|
176
|
+
featuresCount: features.length,
|
|
177
|
+
indexNodeSize: 0,
|
|
178
|
+
crs: null,
|
|
179
|
+
title: null,
|
|
180
|
+
description: null,
|
|
181
|
+
metadata: null
|
|
182
|
+
};
|
|
183
|
+
return headerMeta;
|
|
161
184
|
}
|
|
162
|
-
//# sourceMappingURL=featurecollection.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as flatbuffers from 'flatbuffers';
|
|
2
|
-
import { GeometryType } from
|
|
3
|
-
import { Geometry } from
|
|
2
|
+
import { GeometryType } from "../flat-geobuf/geometry-type.js";
|
|
3
|
+
import { Geometry } from "../flat-geobuf/geometry.js";
|
|
4
4
|
export interface IParsedGeometry {
|
|
5
5
|
xy: number[];
|
|
6
6
|
z: number[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../../src/flatgeobuf/3.27.2/generic/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAC,YAAY,EAAC,
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../../src/flatgeobuf/3.27.2/generic/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAC,YAAY,EAAC,wCAAqC;AAC1D,OAAO,EAAC,QAAQ,EAAC,mCAAgC;AAEjD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,kBAAkB,CAAC,IAAI,MAAM,EAAE,CAAC;IAChC,OAAO,IAAI,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAS,SAAQ,eAAe;IAC/C,OAAO,IAAI,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,OAAO,IAAI,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,QAAQ,IAAI,MAAM,EAAE,EAAE,CAAC;IACvB,WAAW,IAAI,QAAQ,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,IAAI,EAAE,YAAY,GAAG,eAAe,GAAG,SAAS,CAAC;CAC9E;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,GAAG,GAAG,CAyBhG;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,CAS9E;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,eAAe,EACzB,cAAc,EAAE,YAAY,GAC3B,eAAe,CA4BjB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,EAAE,EAAE,CAQlF;AAED,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAI1D"}
|
|
@@ -1,81 +1,93 @@
|
|
|
1
1
|
import { GeometryType } from "../flat-geobuf/geometry-type.js";
|
|
2
2
|
import { Geometry } from "../flat-geobuf/geometry.js";
|
|
3
3
|
export function buildGeometry(builder, parsedGeometry) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
4
|
+
const { xy, z, ends, parts, type } = parsedGeometry;
|
|
5
|
+
if (parts) {
|
|
6
|
+
const partOffsets = parts.map((part) => buildGeometry(builder, part));
|
|
7
|
+
const partsOffset = Geometry.createPartsVector(builder, partOffsets);
|
|
8
|
+
Geometry.startGeometry(builder);
|
|
9
|
+
Geometry.addParts(builder, partsOffset);
|
|
10
|
+
Geometry.addType(builder, type);
|
|
11
|
+
return Geometry.endGeometry(builder);
|
|
12
|
+
}
|
|
13
|
+
const xyOffset = Geometry.createXyVector(builder, xy);
|
|
14
|
+
let zOffset;
|
|
15
|
+
if (z)
|
|
16
|
+
zOffset = Geometry.createZVector(builder, z);
|
|
17
|
+
let endsOffset;
|
|
18
|
+
if (ends)
|
|
19
|
+
endsOffset = Geometry.createEndsVector(builder, ends);
|
|
14
20
|
Geometry.startGeometry(builder);
|
|
15
|
-
|
|
21
|
+
if (endsOffset)
|
|
22
|
+
Geometry.addEnds(builder, endsOffset);
|
|
23
|
+
Geometry.addXy(builder, xyOffset);
|
|
24
|
+
if (zOffset)
|
|
25
|
+
Geometry.addZ(builder, zOffset);
|
|
16
26
|
Geometry.addType(builder, type);
|
|
17
27
|
return Geometry.endGeometry(builder);
|
|
18
|
-
}
|
|
19
|
-
const xyOffset = Geometry.createXyVector(builder, xy);
|
|
20
|
-
let zOffset;
|
|
21
|
-
if (z) zOffset = Geometry.createZVector(builder, z);
|
|
22
|
-
let endsOffset;
|
|
23
|
-
if (ends) endsOffset = Geometry.createEndsVector(builder, ends);
|
|
24
|
-
Geometry.startGeometry(builder);
|
|
25
|
-
if (endsOffset) Geometry.addEnds(builder, endsOffset);
|
|
26
|
-
Geometry.addXy(builder, xyOffset);
|
|
27
|
-
if (zOffset) Geometry.addZ(builder, zOffset);
|
|
28
|
-
Geometry.addType(builder, type);
|
|
29
|
-
return Geometry.endGeometry(builder);
|
|
30
28
|
}
|
|
31
29
|
export function flat(a, xy, z) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
if (a.length === 0)
|
|
31
|
+
return;
|
|
32
|
+
if (Array.isArray(a[0])) {
|
|
33
|
+
for (const sa of a)
|
|
34
|
+
flat(sa, xy, z);
|
|
35
|
+
}
|
|
36
|
+
else if (a.length === 2)
|
|
37
|
+
xy.push(...a);
|
|
38
|
+
else {
|
|
39
|
+
xy.push(a[0], a[1]);
|
|
40
|
+
z.push(a[2]);
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
export function parseGeometry(geometry, headerGeomType) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
44
|
+
let xy;
|
|
45
|
+
let ends;
|
|
46
|
+
let parts;
|
|
47
|
+
let type = headerGeomType;
|
|
48
|
+
if (type === GeometryType.Unknown) {
|
|
49
|
+
type = toGeometryType(geometry.getType());
|
|
50
|
+
}
|
|
51
|
+
if (type === GeometryType.MultiLineString) {
|
|
52
|
+
if (geometry.getFlatCoordinates)
|
|
53
|
+
xy = geometry.getFlatCoordinates();
|
|
54
|
+
const mlsEnds = geometry.getEnds();
|
|
55
|
+
if (mlsEnds.length > 1)
|
|
56
|
+
ends = mlsEnds.map((e) => e >> 1);
|
|
57
|
+
}
|
|
58
|
+
else if (type === GeometryType.Polygon) {
|
|
59
|
+
if (geometry.getFlatCoordinates)
|
|
60
|
+
xy = geometry.getFlatCoordinates();
|
|
61
|
+
const pEnds = geometry.getEnds();
|
|
62
|
+
if (pEnds.length > 1)
|
|
63
|
+
ends = pEnds.map((e) => e >> 1);
|
|
64
|
+
}
|
|
65
|
+
else if (type === GeometryType.MultiPolygon) {
|
|
66
|
+
const mp = geometry;
|
|
67
|
+
parts = mp.getPolygons().map((p) => parseGeometry(p, GeometryType.Polygon));
|
|
68
|
+
}
|
|
69
|
+
else if (geometry.getFlatCoordinates)
|
|
70
|
+
xy = geometry.getFlatCoordinates();
|
|
71
|
+
return {
|
|
72
|
+
xy,
|
|
73
|
+
ends,
|
|
74
|
+
type,
|
|
75
|
+
parts
|
|
76
|
+
};
|
|
66
77
|
}
|
|
67
78
|
export function pairFlatCoordinates(xy, z) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
const newArray = [];
|
|
80
|
+
for (let i = 0; i < xy.length; i += 2) {
|
|
81
|
+
const a = [xy[i], xy[i + 1]];
|
|
82
|
+
if (z)
|
|
83
|
+
a.push(z[i >> 1]);
|
|
84
|
+
newArray.push(a);
|
|
85
|
+
}
|
|
86
|
+
return newArray;
|
|
75
87
|
}
|
|
76
88
|
export function toGeometryType(name) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
if (!name)
|
|
90
|
+
return GeometryType.Unknown;
|
|
91
|
+
const type = GeometryType[name];
|
|
92
|
+
return type;
|
|
80
93
|
}
|
|
81
|
-
//# sourceMappingURL=geometry.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GeometryType } from
|
|
2
|
-
import { IFeature } from
|
|
3
|
-
import { IGeoJsonFeature } from
|
|
1
|
+
import { GeometryType } from "../flat-geobuf/geometry-type.js";
|
|
2
|
+
import { IFeature } from "./feature.js";
|
|
3
|
+
import { IGeoJsonFeature } from "../geojson/feature.js";
|
|
4
4
|
export declare function inferGeometryType(features: (IFeature | IGeoJsonFeature)[]): GeometryType;
|
|
5
5
|
//# sourceMappingURL=header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../../src/flatgeobuf/3.27.2/generic/header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,
|
|
1
|
+
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../../src/flatgeobuf/3.27.2/generic/header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,wCAAqC;AAE1D,OAAO,EAAC,QAAQ,EAAC,qBAAkB;AACnC,OAAO,EAAC,eAAe,EAAC,8BAA2B;AASnD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,CAAC,QAAQ,GAAG,eAAe,CAAC,EAAE,GAAG,YAAY,CAmBxF"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { GeometryType } from "../flat-geobuf/geometry-type.js";
|
|
2
2
|
import { toGeometryType } from "../generic/geometry.js";
|
|
3
3
|
function featureGeomType(feature) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
if (feature.getGeometry) {
|
|
5
|
+
return toGeometryType(feature.getGeometry().getType());
|
|
6
|
+
}
|
|
7
|
+
return toGeometryType(feature.geometry.type);
|
|
8
8
|
}
|
|
9
9
|
export function inferGeometryType(features) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
let geometryType;
|
|
11
|
+
for (const f of features) {
|
|
12
|
+
if (geometryType === GeometryType.Unknown) {
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
const gtype = featureGeomType(f);
|
|
16
|
+
if (geometryType === undefined) {
|
|
17
|
+
geometryType = gtype;
|
|
18
|
+
}
|
|
19
|
+
else if (geometryType !== gtype) {
|
|
20
|
+
geometryType = GeometryType.Unknown;
|
|
21
|
+
}
|
|
14
22
|
}
|
|
15
|
-
const gtype = featureGeomType(f);
|
|
16
23
|
if (geometryType === undefined) {
|
|
17
|
-
|
|
18
|
-
} else if (geometryType !== gtype) {
|
|
19
|
-
geometryType = GeometryType.Unknown;
|
|
24
|
+
throw new Error('Could not infer geometry type for collection of features.');
|
|
20
25
|
}
|
|
21
|
-
|
|
22
|
-
if (geometryType === undefined) {
|
|
23
|
-
throw new Error('Could not infer geometry type for collection of features.');
|
|
24
|
-
}
|
|
25
|
-
return geometryType;
|
|
26
|
+
return geometryType;
|
|
26
27
|
}
|
|
27
|
-
//# sourceMappingURL=header.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./feature.js";
|
|
2
|
+
export * from "./featurecollection.js";
|
|
3
|
+
export * from "./geometry.js";
|
|
4
|
+
export * from "./header.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/flatgeobuf/3.27.2/generic/index.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/flatgeobuf/3.27.2/generic/index.ts"],"names":[],"mappings":"AAGA,6BAA0B;AAC1B,uCAAoC;AACpC,8BAA2B;AAC3B,4BAAyB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FromFeatureFn } from
|
|
2
|
-
import { Rect } from
|
|
3
|
-
import { IFeature } from
|
|
4
|
-
import HeaderMeta from
|
|
1
|
+
import { FromFeatureFn } from "./generic/featurecollection.js";
|
|
2
|
+
import { Rect } from "./packedrtree.js";
|
|
3
|
+
import { IFeature } from "./generic/feature.js";
|
|
4
|
+
import HeaderMeta from "./header-meta.js";
|
|
5
5
|
export type HeaderMetaFn = (headerMeta: HeaderMeta) => void;
|
|
6
6
|
/**
|
|
7
7
|
* Deserialize FlatGeobuf into generic features
|
|
@@ -10,7 +10,7 @@ export type HeaderMetaFn = (headerMeta: HeaderMeta) => void;
|
|
|
10
10
|
* @param rect Filter rectangle
|
|
11
11
|
*/
|
|
12
12
|
export declare function deserialize(input: Uint8Array | ReadableStream | string, fromFeature: FromFeatureFn, rect?: Rect): any[] | AsyncGenerator<IFeature>;
|
|
13
|
-
export { serialize } from
|
|
14
|
-
export { GeometryType } from
|
|
15
|
-
export { ColumnType } from
|
|
13
|
+
export { serialize } from "./generic/featurecollection.js";
|
|
14
|
+
export { GeometryType } from "./flat-geobuf/geometry-type.js";
|
|
15
|
+
export { ColumnType } from "./flat-geobuf/column-type.js";
|
|
16
16
|
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/flatgeobuf/3.27.2/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,aAAa,EACd,
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/flatgeobuf/3.27.2/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,aAAa,EACd,uCAAoC;AAErC,OAAO,EAAC,IAAI,EAAC,yBAAsB;AACnC,OAAO,EAAC,QAAQ,EAAC,6BAA0B;AAC3C,OAAO,UAAU,yBAAsB;AAEvC,MAAM,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,UAAU,GAAG,cAAc,GAAG,MAAM,EAC3C,WAAW,EAAE,aAAa,EAC1B,IAAI,CAAC,EAAE,IAAI,GACV,GAAG,EAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,CAIlC;AAED,OAAO,EAAC,SAAS,EAAC,uCAAoC;AAEtD,OAAO,EAAC,YAAY,EAAC,uCAAoC;AACzD,OAAO,EAAC,UAAU,EAAC,qCAAkC"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { deserialize as deserializeArray, deserializeStream, deserializeFiltered } from "./generic/featurecollection.js";
|
|
2
|
+
/**
|
|
3
|
+
* Deserialize FlatGeobuf into generic features
|
|
4
|
+
* @param input Input byte array, stream or string
|
|
5
|
+
* @param fromFeature Callback that recieves generic features
|
|
6
|
+
* @param rect Filter rectangle
|
|
7
|
+
*/
|
|
2
8
|
export function deserialize(input, fromFeature, rect) {
|
|
3
|
-
|
|
4
|
-
|
|
9
|
+
if (input instanceof Uint8Array)
|
|
10
|
+
return deserializeArray(input, fromFeature);
|
|
11
|
+
else if (input instanceof ReadableStream)
|
|
12
|
+
return deserializeStream(input, fromFeature);
|
|
13
|
+
return deserializeFiltered(input, rect, fromFeature);
|
|
5
14
|
}
|
|
6
15
|
export { serialize } from "./generic/featurecollection.js";
|
|
7
16
|
export { GeometryType } from "./flat-geobuf/geometry-type.js";
|
|
8
17
|
export { ColumnType } from "./flat-geobuf/column-type.js";
|
|
9
|
-
//# sourceMappingURL=generic.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Feature } from
|
|
2
|
-
import HeaderMeta from
|
|
3
|
-
import { IFeature } from
|
|
1
|
+
import { Feature } from "../flat-geobuf/feature.js";
|
|
2
|
+
import HeaderMeta from "../header-meta.js";
|
|
3
|
+
import { IFeature } from "../generic/feature.js";
|
|
4
4
|
import { Feature as GeoJsonFeature } from 'geojson';
|
|
5
5
|
export interface IGeoJsonFeature extends IFeature, GeoJsonFeature {
|
|
6
6
|
}
|