@loaders.gl/gis 4.3.1 → 4.4.0-alpha.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/index.cjs +2411 -469
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +31 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -15
- package/dist/lib/binary-geometry-api/binary-geometry-info.d.ts +21 -0
- package/dist/lib/binary-geometry-api/binary-geometry-info.d.ts.map +1 -0
- package/dist/lib/binary-geometry-api/binary-geometry-info.js +48 -0
- package/dist/lib/binary-geometry-api/concat-binary-geometry.d.ts +5 -0
- package/dist/lib/binary-geometry-api/concat-binary-geometry.d.ts.map +1 -0
- package/dist/lib/binary-geometry-api/concat-binary-geometry.js +50 -0
- package/dist/lib/{binary-features/transform.d.ts → binary-geometry-api/transform-coordinates.d.ts} +1 -2
- package/dist/lib/binary-geometry-api/transform-coordinates.d.ts.map +1 -0
- package/dist/lib/{binary-features/transform.js → binary-geometry-api/transform-coordinates.js} +0 -1
- package/dist/lib/feature-collection-converters/convert-binary-features-to-geojson.d.ts +16 -0
- package/dist/lib/feature-collection-converters/convert-binary-features-to-geojson.d.ts.map +1 -0
- package/dist/lib/{binary-features/binary-to-geojson.js → feature-collection-converters/convert-binary-features-to-geojson.js} +3 -90
- package/dist/lib/{binary-features/flat-geojson-to-binary.d.ts → feature-collection-converters/convert-flat-geojson-to-binary-features.d.ts} +6 -9
- package/dist/lib/feature-collection-converters/convert-flat-geojson-to-binary-features.d.ts.map +1 -0
- package/dist/lib/{binary-features/flat-geojson-to-binary.js → feature-collection-converters/convert-flat-geojson-to-binary-features.js} +5 -5
- package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.d.ts +74 -0
- package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.d.ts.map +1 -0
- package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.js +377 -0
- package/dist/lib/{binary-features/geojson-to-binary.d.ts → feature-collection-converters/convert-geojson-to-binary-features.d.ts} +2 -2
- package/dist/lib/feature-collection-converters/convert-geojson-to-binary-features.d.ts.map +1 -0
- package/dist/lib/feature-collection-converters/convert-geojson-to-binary-features.js +24 -0
- package/dist/lib/{binary-features/geojson-to-flat-geojson.d.ts → feature-collection-converters/convert-geojson-to-flat-geojson.d.ts} +2 -2
- package/dist/lib/feature-collection-converters/convert-geojson-to-flat-geojson.d.ts.map +1 -0
- package/dist/lib/{binary-features/geojson-to-flat-geojson.js → feature-collection-converters/convert-geojson-to-flat-geojson.js} +4 -1
- package/dist/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.d.ts.map +1 -0
- package/dist/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.js +4 -0
- package/dist/lib/geometry-api/geometry-info.d.ts +21 -0
- package/dist/lib/geometry-api/geometry-info.d.ts.map +1 -0
- package/dist/lib/{binary-features/extract-geometry-info.js → geometry-api/geometry-info.js} +4 -1
- package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.d.ts +4 -0
- package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.d.ts.map +1 -0
- package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.js +91 -0
- package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.d.ts +13 -0
- package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.d.ts.map +1 -0
- package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.js +164 -0
- package/dist/lib/geometry-converters/convert-to-geojson.d.ts +6 -0
- package/dist/lib/geometry-converters/convert-to-geojson.d.ts.map +1 -0
- package/dist/lib/geometry-converters/convert-to-geojson.js +39 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.d.ts +6 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.js +195 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.d.ts +9 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.js +273 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.d.ts +8 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.js +44 -0
- package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.d.ts +10 -0
- package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.js +254 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.d.ts +3 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js +164 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.d.ts +11 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.js +9 -0
- package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.d.ts +16 -0
- package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.js +258 -0
- package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts +43 -0
- package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +174 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-types.d.ts +64 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-types.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-types.js +46 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.d.ts +21 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.js +64 -0
- package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.d.ts +8 -0
- package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.js +33 -0
- package/dist/lib/table-converters/convert-geoarrow-table.d.ts +27 -0
- package/dist/lib/table-converters/convert-geoarrow-table.d.ts.map +1 -0
- package/dist/lib/table-converters/convert-geoarrow-table.js +154 -0
- package/dist/lib/table-converters/convert-wkb-table-to-geojson.d.ts +4 -0
- package/dist/lib/table-converters/convert-wkb-table-to-geojson.d.ts.map +1 -0
- package/dist/lib/{tables/convert-table-to-geojson.js → table-converters/convert-wkb-table-to-geojson.js} +10 -16
- package/dist/lib/table-converters/make-arrow-batch-iterator.d.ts +6 -0
- package/dist/lib/table-converters/make-arrow-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table-converters/make-arrow-batch-iterator.js +35 -0
- package/dist/lib/utils/base64-encoder.d.ts +5 -0
- package/dist/lib/utils/base64-encoder.d.ts.map +1 -0
- package/dist/lib/utils/base64-encoder.js +153 -0
- package/dist/lib/utils/binary-reader.d.ts +18 -0
- package/dist/lib/utils/binary-reader.d.ts.map +1 -0
- package/dist/lib/utils/binary-reader.js +69 -0
- package/dist/lib/utils/binary-writer.d.ts +30 -0
- package/dist/lib/utils/binary-writer.d.ts.map +1 -0
- package/dist/lib/utils/binary-writer.js +127 -0
- package/dist/lib/utils/concat-typed-arrays.d.ts +3 -0
- package/dist/lib/utils/concat-typed-arrays.d.ts.map +1 -0
- package/dist/lib/utils/concat-typed-arrays.js +18 -0
- package/dist/lib/utils/hex-encoder.d.ts +15 -0
- package/dist/lib/utils/hex-encoder.d.ts.map +1 -0
- package/dist/lib/utils/hex-encoder.js +54 -0
- package/dist/lib/utils/hex-transcoder.d.ts +15 -0
- package/dist/lib/utils/hex-transcoder.d.ts.map +1 -0
- package/dist/lib/utils/hex-transcoder.js +50 -0
- package/dist/lib/wkt-crs/encode-wkt-crs.d.ts +10 -0
- package/dist/lib/wkt-crs/encode-wkt-crs.d.ts.map +1 -0
- package/dist/lib/wkt-crs/encode-wkt-crs.js +35 -0
- package/dist/lib/wkt-crs/parse-wkt-crs.d.ts +15 -0
- package/dist/lib/wkt-crs/parse-wkt-crs.d.ts.map +1 -0
- package/dist/lib/wkt-crs/parse-wkt-crs.js +120 -0
- package/package.json +7 -5
- package/src/index.ts +87 -14
- package/src/lib/binary-geometry-api/binary-geometry-info.ts +75 -0
- package/src/lib/binary-geometry-api/concat-binary-geometry.ts +78 -0
- package/src/lib/{binary-features/transform.ts → binary-geometry-api/transform-coordinates.ts} +0 -1
- package/src/lib/{binary-features/binary-to-geojson.ts → feature-collection-converters/convert-binary-features-to-geojson.ts} +5 -142
- package/src/lib/{binary-features/flat-geojson-to-binary.ts → feature-collection-converters/convert-flat-geojson-to-binary-features.ts} +14 -9
- package/src/lib/feature-collection-converters/convert-geoarrow-to-binary-features.ts +496 -0
- package/src/lib/{binary-features/geojson-to-binary.ts → feature-collection-converters/convert-geojson-to-binary-features.ts} +11 -7
- package/src/lib/{binary-features/geojson-to-flat-geojson.ts → feature-collection-converters/convert-geojson-to-flat-geojson.ts} +5 -1
- package/src/lib/{binary-features → feature-collection-converters/helpers}/flat-geojson-to-binary-types.ts +4 -0
- package/src/lib/{binary-features/extract-geometry-info.ts → geometry-api/geometry-info.ts} +20 -2
- package/src/lib/geometry-converters/convert-binary-geometry-to-geojson.ts +148 -0
- package/src/lib/geometry-converters/convert-geoarrow-to-geojson.ts +193 -0
- package/src/lib/geometry-converters/convert-to-geojson.ts +52 -0
- package/src/lib/geometry-converters/wkb/convert-geometry-to-twkb.ts +308 -0
- package/src/lib/geometry-converters/wkb/convert-geometry-to-wkb.ts +365 -0
- package/src/lib/geometry-converters/wkb/convert-geometry-to-wkt.ts +54 -0
- package/src/lib/geometry-converters/wkb/convert-twkb-to-geometry.ts +366 -0
- package/src/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.ts +238 -0
- package/src/lib/geometry-converters/wkb/convert-wkb-to-geometry.ts +23 -0
- package/src/lib/geometry-converters/wkb/convert-wkt-to-geometry.ts +294 -0
- package/src/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +213 -0
- package/src/lib/geometry-converters/wkb/helpers/wkb-types.ts +82 -0
- package/src/lib/geometry-converters/wkb/helpers/wkb-utils.ts +85 -0
- package/src/lib/geometry-converters/wkb/helpers/write-wkb-header.ts +41 -0
- package/src/lib/table-converters/convert-geoarrow-table.ts +218 -0
- package/src/lib/{tables/convert-table-to-geojson.ts → table-converters/convert-wkb-table-to-geojson.ts} +10 -23
- package/src/lib/table-converters/make-arrow-batch-iterator.ts +53 -0
- package/src/lib/utils/base64-encoder.ts +157 -0
- package/src/lib/utils/binary-reader.ts +76 -0
- package/src/lib/utils/binary-writer.ts +136 -0
- package/src/lib/utils/concat-typed-arrays.ts +24 -0
- package/src/lib/utils/hex-encoder.ts +60 -0
- package/src/lib/utils/hex-transcoder.ts +54 -0
- package/src/lib/wkt-crs/encode-wkt-crs.ts +41 -0
- package/src/lib/wkt-crs/parse-wkt-crs.ts +149 -0
- package/dist/lib/binary-features/binary-to-geojson.d.ts +0 -18
- package/dist/lib/binary-features/binary-to-geojson.d.ts.map +0 -1
- package/dist/lib/binary-features/extract-geometry-info.d.ts +0 -8
- package/dist/lib/binary-features/extract-geometry-info.d.ts.map +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary-types.d.ts.map +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary-types.js +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary.d.ts.map +0 -1
- package/dist/lib/binary-features/geojson-to-binary.d.ts.map +0 -1
- package/dist/lib/binary-features/geojson-to-binary.js +0 -21
- package/dist/lib/binary-features/geojson-to-flat-geojson.d.ts.map +0 -1
- package/dist/lib/binary-features/transform.d.ts.map +0 -1
- package/dist/lib/geo/geoarrow-metadata.d.ts +0 -27
- package/dist/lib/geo/geoarrow-metadata.d.ts.map +0 -1
- package/dist/lib/geo/geoarrow-metadata.js +0 -70
- package/dist/lib/geo/geoparquet-metadata-schema.d.ts +0 -79
- package/dist/lib/geo/geoparquet-metadata-schema.d.ts.map +0 -1
- package/dist/lib/geo/geoparquet-metadata-schema.js +0 -69
- package/dist/lib/geo/geoparquet-metadata.d.ts +0 -45
- package/dist/lib/geo/geoparquet-metadata.d.ts.map +0 -1
- package/dist/lib/geo/geoparquet-metadata.js +0 -117
- package/dist/lib/tables/convert-table-to-geojson.d.ts +0 -5
- package/dist/lib/tables/convert-table-to-geojson.d.ts.map +0 -1
- package/src/lib/geo/geoarrow-metadata.ts +0 -100
- package/src/lib/geo/geoparquet-metadata-schema.json +0 -60
- package/src/lib/geo/geoparquet-metadata-schema.ts +0 -71
- package/src/lib/geo/geoparquet-metadata.ts +0 -191
- /package/dist/lib/{binary-features → feature-collection-converters/helpers}/flat-geojson-to-binary-types.d.ts +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integer codes for geometry types in WKB and related formats
|
|
3
|
+
* @see: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
4
|
+
*/
|
|
5
|
+
export declare enum WKBGeometryType {
|
|
6
|
+
Point = 1,
|
|
7
|
+
LineString = 2,
|
|
8
|
+
Polygon = 3,
|
|
9
|
+
MultiPoint = 4,
|
|
10
|
+
MultiLineString = 5,
|
|
11
|
+
MultiPolygon = 6,
|
|
12
|
+
GeometryCollection = 7
|
|
13
|
+
}
|
|
14
|
+
/** Parsed WKB header */
|
|
15
|
+
export type WKBHeader = {
|
|
16
|
+
/** WKB or TWKB */
|
|
17
|
+
type: 'wkb' | 'twkb';
|
|
18
|
+
/** WKB variant */
|
|
19
|
+
variant: 'wkb' | 'ewkb' | 'iso-wkb' | 'twkb';
|
|
20
|
+
/** geometry type encoded in this WKB: point, line, polygon etc */
|
|
21
|
+
geometryType: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
22
|
+
/** Number of dimensions for coordinate data */
|
|
23
|
+
dimensions: 2 | 3 | 4;
|
|
24
|
+
/** Coordinate names, Z and M are controlled by flags */
|
|
25
|
+
coordinates: 'xy' | 'xyz' | 'xym' | 'xyzm';
|
|
26
|
+
/** WKB Geometry has a spatial coordinate reference system id */
|
|
27
|
+
srid?: number;
|
|
28
|
+
/** true if binary data is stored as little endian */
|
|
29
|
+
littleEndian: boolean;
|
|
30
|
+
/** Offset to start of geometry */
|
|
31
|
+
byteOffset: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Options for writing WKB
|
|
35
|
+
*/
|
|
36
|
+
export type WKBOptions = {
|
|
37
|
+
/** Does the GeoJSON input have Z values? */
|
|
38
|
+
hasZ?: boolean;
|
|
39
|
+
/** Does the GeoJSON input have M values? */
|
|
40
|
+
hasM?: boolean;
|
|
41
|
+
/** Spatial reference for input GeoJSON */
|
|
42
|
+
srid?: any;
|
|
43
|
+
};
|
|
44
|
+
/** WKB Geometry has a z coordinate */
|
|
45
|
+
export declare const EWKB_FLAG_Z = 2147483648;
|
|
46
|
+
/** WKB Geometry has an m coordinate */
|
|
47
|
+
export declare const EWKB_FLAG_M = 1073741824;
|
|
48
|
+
/** WKB Geometry has a spatial coordinate reference system id */
|
|
49
|
+
export declare const EWKB_FLAG_SRID = 536870912;
|
|
50
|
+
/** @todo: Assume no more than 10K SRIDs are defined */
|
|
51
|
+
export declare const MAX_SRID = 10000;
|
|
52
|
+
/**
|
|
53
|
+
* @see: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
54
|
+
* @note Order matches WKBGeometryType enum (need to add 1)
|
|
55
|
+
* @note: We only support this "geojson" subset of the OGC simple features standard
|
|
56
|
+
*/
|
|
57
|
+
export declare const WKT_MAGIC_STRINGS: string[];
|
|
58
|
+
/**
|
|
59
|
+
* @see: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
60
|
+
* @note Order matches WKBGeometryType enum (need to add 1)
|
|
61
|
+
* @note: We only support this "geojson" subset of the OGC simple features standard
|
|
62
|
+
*/
|
|
63
|
+
export declare const WKT_MAGIC_BYTES: Uint8Array[];
|
|
64
|
+
//# sourceMappingURL=wkb-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wkb-types.d.ts","sourceRoot":"","sources":["../../../../../src/lib/geometry-converters/wkb/helpers/wkb-types.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,oBAAY,eAAe;IACzB,KAAK,IAAI;IACT,UAAU,IAAI;IACd,OAAO,IAAI;IACX,UAAU,IAAI;IACd,eAAe,IAAI;IACnB,YAAY,IAAI;IAChB,kBAAkB,IAAI;CACvB;AAED,wBAAwB;AACxB,MAAM,MAAM,SAAS,GAAG;IACtB,kBAAkB;IAClB,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,kBAAkB;IAClB,OAAO,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IAC7C,kEAAkE;IAClE,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,+CAA+C;IAC/C,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtB,wDAAwD;IACxD,WAAW,EAAE,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAC3C,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,YAAY,EAAE,OAAO,CAAC;IACtB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,4CAA4C;IAC5C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,0CAA0C;IAC1C,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,sCAAsC;AACtC,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,uCAAuC;AACvC,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,gEAAgE;AAChE,eAAO,MAAM,cAAc,YAAa,CAAC;AACzC,uDAAuD;AACvD,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UAQ7B,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,eAAe,cAAgE,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Integer codes for geometry types in WKB and related formats
|
|
6
|
+
* @see: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
7
|
+
*/
|
|
8
|
+
export var WKBGeometryType;
|
|
9
|
+
(function (WKBGeometryType) {
|
|
10
|
+
WKBGeometryType[WKBGeometryType["Point"] = 1] = "Point";
|
|
11
|
+
WKBGeometryType[WKBGeometryType["LineString"] = 2] = "LineString";
|
|
12
|
+
WKBGeometryType[WKBGeometryType["Polygon"] = 3] = "Polygon";
|
|
13
|
+
WKBGeometryType[WKBGeometryType["MultiPoint"] = 4] = "MultiPoint";
|
|
14
|
+
WKBGeometryType[WKBGeometryType["MultiLineString"] = 5] = "MultiLineString";
|
|
15
|
+
WKBGeometryType[WKBGeometryType["MultiPolygon"] = 6] = "MultiPolygon";
|
|
16
|
+
WKBGeometryType[WKBGeometryType["GeometryCollection"] = 7] = "GeometryCollection";
|
|
17
|
+
})(WKBGeometryType || (WKBGeometryType = {}));
|
|
18
|
+
/** WKB Geometry has a z coordinate */
|
|
19
|
+
export const EWKB_FLAG_Z = 0x80000000;
|
|
20
|
+
/** WKB Geometry has an m coordinate */
|
|
21
|
+
export const EWKB_FLAG_M = 0x40000000;
|
|
22
|
+
/** WKB Geometry has a spatial coordinate reference system id */
|
|
23
|
+
export const EWKB_FLAG_SRID = 0x20000000;
|
|
24
|
+
/** @todo: Assume no more than 10K SRIDs are defined */
|
|
25
|
+
export const MAX_SRID = 10000;
|
|
26
|
+
/**
|
|
27
|
+
* @see: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
28
|
+
* @note Order matches WKBGeometryType enum (need to add 1)
|
|
29
|
+
* @note: We only support this "geojson" subset of the OGC simple features standard
|
|
30
|
+
*/
|
|
31
|
+
export const WKT_MAGIC_STRINGS = [
|
|
32
|
+
'POINT(',
|
|
33
|
+
'LINESTRING(',
|
|
34
|
+
'POLYGON(',
|
|
35
|
+
'MULTIPOINT(',
|
|
36
|
+
'MULTILINESTRING(',
|
|
37
|
+
'MULTIPOLYGON(',
|
|
38
|
+
'GEOMETRYCOLLECTION('
|
|
39
|
+
];
|
|
40
|
+
const textEncoder = new TextEncoder();
|
|
41
|
+
/**
|
|
42
|
+
* @see: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
43
|
+
* @note Order matches WKBGeometryType enum (need to add 1)
|
|
44
|
+
* @note: We only support this "geojson" subset of the OGC simple features standard
|
|
45
|
+
*/
|
|
46
|
+
export const WKT_MAGIC_BYTES = WKT_MAGIC_STRINGS.map((string) => textEncoder.encode(string));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WKBOptions } from "./wkb-types.js";
|
|
2
|
+
import { WKBGeometryType } from "./wkb-types.js";
|
|
3
|
+
declare const WKBGeometryTypeNames: {
|
|
4
|
+
readonly Point: WKBGeometryType.Point;
|
|
5
|
+
readonly LineString: WKBGeometryType.LineString;
|
|
6
|
+
readonly Polygon: WKBGeometryType.Polygon;
|
|
7
|
+
readonly MultiPoint: WKBGeometryType.MultiPoint;
|
|
8
|
+
readonly MultiLineString: WKBGeometryType.MultiLineString;
|
|
9
|
+
readonly MultiPolygon: WKBGeometryType.MultiPolygon;
|
|
10
|
+
readonly GeometryCollection: WKBGeometryType.GeometryCollection;
|
|
11
|
+
};
|
|
12
|
+
/** Convert a WKB geometry type integer to GeoJSON style geometry type string*/
|
|
13
|
+
export declare function getGeometryTypeFromWKBType(wkbGeometryType: WKBGeometryType): keyof typeof WKBGeometryTypeNames;
|
|
14
|
+
/** Convert a GeoJSON style geometry type string to a WKB geometry type integer*/
|
|
15
|
+
export declare function getWKBTypeFromGeometryType(geometryType: keyof typeof WKBGeometryTypeNames): WKBGeometryType;
|
|
16
|
+
/** Sanity: Adjust Z/M dimensions with actual point size */
|
|
17
|
+
export declare function matchWKBOptionsToPointSize(pointSize: number, options?: WKBOptions): Required<WKBOptions>;
|
|
18
|
+
/** Get coordinate size given Z/M dimensions */
|
|
19
|
+
export declare function getCoordinateByteSize(options?: WKBOptions): number;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=wkb-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wkb-utils.d.ts","sourceRoot":"","sources":["../../../../../src/lib/geometry-converters/wkb/helpers/wkb-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,uBAAoB;AAC5C,OAAO,EAAC,eAAe,EAAC,uBAAoB;AAE5C,QAAA,MAAM,oBAAoB;;;;;;;;CAQ0B,CAAC;AAErD,+EAA+E;AAC/E,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,eAAe,GAC/B,MAAM,OAAO,oBAAoB,CAOnC;AAED,iFAAiF;AACjF,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,OAAO,oBAAoB,GAC9C,eAAe,CAEjB;AAED,2DAA2D;AAC3D,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,UAAU,GACnB,QAAQ,CAAC,UAAU,CAAC,CA8BtB;AAED,+CAA+C;AAC/C,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAWlE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { WKBGeometryType } from "./wkb-types.js";
|
|
5
|
+
const WKBGeometryTypeNames = {
|
|
6
|
+
Point: WKBGeometryType.Point,
|
|
7
|
+
LineString: WKBGeometryType.LineString,
|
|
8
|
+
Polygon: WKBGeometryType.Polygon,
|
|
9
|
+
MultiPoint: WKBGeometryType.MultiPoint,
|
|
10
|
+
MultiLineString: WKBGeometryType.MultiLineString,
|
|
11
|
+
MultiPolygon: WKBGeometryType.MultiPolygon,
|
|
12
|
+
GeometryCollection: WKBGeometryType.GeometryCollection
|
|
13
|
+
};
|
|
14
|
+
/** Convert a WKB geometry type integer to GeoJSON style geometry type string*/
|
|
15
|
+
export function getGeometryTypeFromWKBType(wkbGeometryType) {
|
|
16
|
+
for (const key in WKBGeometryTypeNames) {
|
|
17
|
+
if (WKBGeometryTypeNames[key] === wkbGeometryType) {
|
|
18
|
+
return key;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
throw new Error(String(wkbGeometryType));
|
|
22
|
+
}
|
|
23
|
+
/** Convert a GeoJSON style geometry type string to a WKB geometry type integer*/
|
|
24
|
+
export function getWKBTypeFromGeometryType(geometryType) {
|
|
25
|
+
return WKBGeometryTypeNames[geometryType];
|
|
26
|
+
}
|
|
27
|
+
/** Sanity: Adjust Z/M dimensions with actual point size */
|
|
28
|
+
export function matchWKBOptionsToPointSize(pointSize, options) {
|
|
29
|
+
const wkbOptions = { hasZ: false, hasM: false, srid: undefined, ...options };
|
|
30
|
+
// Align options with actual point size
|
|
31
|
+
switch (pointSize) {
|
|
32
|
+
case 4:
|
|
33
|
+
wkbOptions.hasZ = true;
|
|
34
|
+
wkbOptions.hasM = true;
|
|
35
|
+
break;
|
|
36
|
+
case 3:
|
|
37
|
+
// Prefer Z over M
|
|
38
|
+
if (wkbOptions.hasZ && wkbOptions.hasM) {
|
|
39
|
+
wkbOptions.hasM = false;
|
|
40
|
+
}
|
|
41
|
+
if (!wkbOptions.hasZ && !wkbOptions.hasM) {
|
|
42
|
+
wkbOptions.hasZ = true;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case 2:
|
|
46
|
+
wkbOptions.hasZ = false;
|
|
47
|
+
wkbOptions.hasM = false;
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
// ignore - broken input data?
|
|
51
|
+
}
|
|
52
|
+
return wkbOptions;
|
|
53
|
+
}
|
|
54
|
+
/** Get coordinate size given Z/M dimensions */
|
|
55
|
+
export function getCoordinateByteSize(options) {
|
|
56
|
+
let coordinateByteSize = 16;
|
|
57
|
+
if (options?.hasZ) {
|
|
58
|
+
coordinateByteSize += 8;
|
|
59
|
+
}
|
|
60
|
+
if (options?.hasM) {
|
|
61
|
+
coordinateByteSize += 8;
|
|
62
|
+
}
|
|
63
|
+
return coordinateByteSize;
|
|
64
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BinaryWriter } from "../../../utils/binary-writer.js";
|
|
2
|
+
import type { WKBOptions } from "./wkb-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Construct and write WKB integer code
|
|
5
|
+
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
6
|
+
*/
|
|
7
|
+
export declare function writeWkbHeader(writer: BinaryWriter, geometryType: number, options?: WKBOptions): void;
|
|
8
|
+
//# sourceMappingURL=write-wkb-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-wkb-header.d.ts","sourceRoot":"","sources":["../../../../../src/lib/geometry-converters/wkb/helpers/write-wkb-header.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,wCAAqC;AAC1D,OAAO,KAAK,EAAC,UAAU,EAAC,uBAAoB;AAE5C;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,UAAU,GACnB,IAAI,CAyBN"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Construct and write WKB integer code
|
|
6
|
+
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
7
|
+
*/
|
|
8
|
+
export function writeWkbHeader(writer, geometryType, options) {
|
|
9
|
+
// little endian
|
|
10
|
+
writer.writeInt8(1);
|
|
11
|
+
const { hasZ, hasM, srid } = options || {};
|
|
12
|
+
let dimensionType = 0;
|
|
13
|
+
if (!srid) {
|
|
14
|
+
if (hasZ && hasM) {
|
|
15
|
+
dimensionType += 3000;
|
|
16
|
+
}
|
|
17
|
+
else if (hasZ) {
|
|
18
|
+
dimensionType += 1000;
|
|
19
|
+
}
|
|
20
|
+
else if (hasM) {
|
|
21
|
+
dimensionType += 2000;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (hasZ) {
|
|
26
|
+
dimensionType |= 0x80000000;
|
|
27
|
+
}
|
|
28
|
+
if (hasM) {
|
|
29
|
+
dimensionType |= 0x40000000;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
writer.writeUInt32LE((dimensionType + geometryType) >>> 0);
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
import type { Table, ArrayRowTable, ColumnarTable, ObjectRowTable, GeoJSONTable, ArrowTable } from '@loaders.gl/schema';
|
|
3
|
+
/**
|
|
4
|
+
* * Convert a loaders.gl Table to an Apache Arrow Table
|
|
5
|
+
* @param mesh
|
|
6
|
+
* @param metadata
|
|
7
|
+
* @param batchSize
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertTableToArrow(table: Table, options?: {
|
|
11
|
+
batchSize?: number;
|
|
12
|
+
}): arrow.Table;
|
|
13
|
+
export declare function makeTableToArrowBatchesIterator(table: Table, options?: {
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
}): IterableIterator<arrow.RecordBatch>;
|
|
16
|
+
/**
|
|
17
|
+
* Convert an Apache Arrow table to a loaders.gl Table
|
|
18
|
+
* @note Currently does not convert schema
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertGeoArrowToTable(arrow: arrow.Table, shape: 'arrow-table'): ArrowTable;
|
|
21
|
+
export declare function convertGeoArrowToTable(arrow: arrow.Table, shape: 'columnar-table'): ColumnarTable;
|
|
22
|
+
export declare function convertGeoArrowToTable(arrow: arrow.Table, shape: 'object-row-table'): ObjectRowTable;
|
|
23
|
+
export declare function convertGeoArrowToTable(arrow: arrow.Table, shape: 'array-row-table'): ArrayRowTable;
|
|
24
|
+
export declare function convertGeoArrowToTable(arrow: arrow.Table, shape: 'geojson-table'): GeoJSONTable;
|
|
25
|
+
export declare function convertGeoArrowToTable(arrow: arrow.Table, shape: 'columnar-table'): ColumnarTable;
|
|
26
|
+
export declare function convertGeoArrowToTable(arrow: arrow.Table, shape: Table['shape']): Table;
|
|
27
|
+
//# sourceMappingURL=convert-geoarrow-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-geoarrow-table.d.ts","sourceRoot":"","sources":["../../../src/lib/table-converters/convert-geoarrow-table.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,UAAU,EAEX,MAAM,oBAAoB,CAAC;AAa5B;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,KAAK,CAAC,KAAK,CAe7F;AAED,wBAAiB,+BAA+B,CAC9C,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,GAC7B,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,CAoCrC;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,GAAG,UAAU,CAAC;AAC7F,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAAC;AACnG,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,KAAK,EAAE,kBAAkB,GACxB,cAAc,CAAC;AAClB,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAAC;AACpG,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,eAAe,GAAG,YAAY,CAAC;AACjG,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAAC;AACnG,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
import { convertTable, convertArrowToSchema, convertSchemaToArrow, getTableLength, getTableNumCols, getTableCellAt } from '@loaders.gl/schema-utils';
|
|
6
|
+
import { getGeometryColumnsFromSchema } from '@loaders.gl/geoarrow';
|
|
7
|
+
import { convertGeoArrowGeometryToGeoJSON } from "../geometry-converters/convert-geoarrow-to-geojson.js";
|
|
8
|
+
/**
|
|
9
|
+
* * Convert a loaders.gl Table to an Apache Arrow Table
|
|
10
|
+
* @param mesh
|
|
11
|
+
* @param metadata
|
|
12
|
+
* @param batchSize
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export function convertTableToArrow(table, options) {
|
|
16
|
+
switch (table.shape) {
|
|
17
|
+
case 'arrow-table':
|
|
18
|
+
return table.data;
|
|
19
|
+
case 'columnar-table':
|
|
20
|
+
// TODO - optimized implementation is possible
|
|
21
|
+
// return convertColumnarTableToArrow(table, options);
|
|
22
|
+
// fall through
|
|
23
|
+
default:
|
|
24
|
+
const arrowBatchIterator = makeTableToArrowBatchesIterator(table, options);
|
|
25
|
+
return new arrow.Table(arrowBatchIterator);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function* makeTableToArrowBatchesIterator(table, options) {
|
|
29
|
+
const arrowSchema = convertSchemaToArrow(table.schema);
|
|
30
|
+
const length = getTableLength(table);
|
|
31
|
+
const numColumns = getTableNumCols(table);
|
|
32
|
+
const batchSize = options?.batchSize || length;
|
|
33
|
+
const builders = arrowSchema?.fields.map((arrowField) => arrow.makeBuilder(arrowField));
|
|
34
|
+
const structField = new arrow.Struct(arrowSchema.fields);
|
|
35
|
+
let batchLength = 0;
|
|
36
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
37
|
+
for (let columnIndex = 0; columnIndex < numColumns; ++columnIndex) {
|
|
38
|
+
const value = getTableCellAt(table, rowIndex, columnIndex);
|
|
39
|
+
const builder = builders[columnIndex];
|
|
40
|
+
builder.append(value);
|
|
41
|
+
batchLength++;
|
|
42
|
+
if (batchLength >= batchSize) {
|
|
43
|
+
const datas = builders.map((builder) => builder.flush());
|
|
44
|
+
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
45
|
+
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
46
|
+
batchLength = 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (batchLength > 0) {
|
|
51
|
+
const datas = builders.map((builder) => builder.flush());
|
|
52
|
+
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
53
|
+
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
54
|
+
batchLength = 0;
|
|
55
|
+
}
|
|
56
|
+
builders.map((builder) => builder.finish());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Convert an Apache Arrow table to a loaders.gl Table
|
|
60
|
+
* @note Currently does not convert schema
|
|
61
|
+
*/
|
|
62
|
+
export function convertGeoArrowToTable(arrowTable, shape) {
|
|
63
|
+
switch (shape) {
|
|
64
|
+
case 'arrow-table':
|
|
65
|
+
return convertArrowToArrowTable(arrowTable);
|
|
66
|
+
case 'array-row-table':
|
|
67
|
+
return convertArrowToArrayRowTable(arrowTable);
|
|
68
|
+
case 'object-row-table':
|
|
69
|
+
return convertArrowToObjectRowTable(arrowTable);
|
|
70
|
+
case 'columnar-table':
|
|
71
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
72
|
+
case 'geojson-table':
|
|
73
|
+
return convertArrowToGeoJSONTable(arrowTable);
|
|
74
|
+
default:
|
|
75
|
+
throw new Error(shape);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Wrap an apache arrow table in a loaders.gl table wrapper.
|
|
80
|
+
* From this additional conversions are available.
|
|
81
|
+
* @param arrowTable
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
function convertArrowToArrowTable(arrowTable) {
|
|
85
|
+
return {
|
|
86
|
+
shape: 'arrow-table',
|
|
87
|
+
schema: convertArrowToSchema(arrowTable.schema),
|
|
88
|
+
data: arrowTable
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function convertArrowToArrayRowTable(arrowTable) {
|
|
92
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
93
|
+
return convertTable(columnarTable, 'array-row-table');
|
|
94
|
+
}
|
|
95
|
+
function convertArrowToObjectRowTable(arrowTable) {
|
|
96
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
97
|
+
return convertTable(columnarTable, 'object-row-table');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Convert an Apache Arrow table to a ColumnarTable
|
|
101
|
+
* @note Currently does not convert schema
|
|
102
|
+
*/
|
|
103
|
+
function convertArrowToColumnarTable(arrowTable) {
|
|
104
|
+
// TODO - avoid calling `getColumn` on columns we are not interested in?
|
|
105
|
+
// Add options object?
|
|
106
|
+
const columns = {};
|
|
107
|
+
for (const field of arrowTable.schema.fields) {
|
|
108
|
+
// This (is intended to) coalesce all record batches into a single typed array
|
|
109
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
110
|
+
const values = arrowColumn?.toArray();
|
|
111
|
+
columns[field.name] = values;
|
|
112
|
+
}
|
|
113
|
+
const schema = convertArrowToSchema(arrowTable.schema);
|
|
114
|
+
return {
|
|
115
|
+
shape: 'columnar-table',
|
|
116
|
+
schema,
|
|
117
|
+
data: columns
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Convert an Apache Arrow table to a GeoJSONTable
|
|
122
|
+
* @note Currently does not convert schema
|
|
123
|
+
*/
|
|
124
|
+
function convertArrowToGeoJSONTable(arrowTable) {
|
|
125
|
+
const schema = convertArrowToSchema(arrowTable.schema);
|
|
126
|
+
const geometryColumns = getGeometryColumnsFromSchema(schema);
|
|
127
|
+
// get encoding from geometryColumns['geometry']
|
|
128
|
+
const encoding = geometryColumns.geometry.encoding;
|
|
129
|
+
const features = [];
|
|
130
|
+
// Remove geometry columns
|
|
131
|
+
const propertyColumnNames = arrowTable.schema.fields
|
|
132
|
+
.map((field) => field.name)
|
|
133
|
+
// TODO - this deletes all geometry columns
|
|
134
|
+
.filter((name) => !(name in geometryColumns));
|
|
135
|
+
const propertiesTable = arrowTable.select(propertyColumnNames);
|
|
136
|
+
const arrowGeometryColumn = arrowTable.getChild('geometry');
|
|
137
|
+
for (let row = 0; row < arrowTable.numRows; row++) {
|
|
138
|
+
// get the geometry value from arrow geometry column
|
|
139
|
+
// Note that type can vary
|
|
140
|
+
const arrowGeometry = arrowGeometryColumn?.get(row);
|
|
141
|
+
// parse arrow geometry to geojson feature
|
|
142
|
+
const feature = convertGeoArrowGeometryToGeoJSON(arrowGeometry, encoding);
|
|
143
|
+
if (feature) {
|
|
144
|
+
const properties = propertiesTable.get(row)?.toJSON() || {};
|
|
145
|
+
features.push({ type: 'Feature', geometry: feature, properties });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
shape: 'geojson-table',
|
|
150
|
+
type: 'FeatureCollection',
|
|
151
|
+
schema,
|
|
152
|
+
features
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ArrayRowTable, GeoJSONTable, ObjectRowTable, Schema } from '@loaders.gl/schema';
|
|
2
|
+
/** TODO - move to loaders.gl/gis? */
|
|
3
|
+
export declare function convertWKBTableToGeoJSON(table: ArrayRowTable | ObjectRowTable, schema: Schema): GeoJSONTable;
|
|
4
|
+
//# sourceMappingURL=convert-wkb-table-to-geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-wkb-table-to-geojson.d.ts","sourceRoot":"","sources":["../../../src/lib/table-converters/convert-wkb-table-to-geojson.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,cAAc,EACd,MAAM,EAGP,MAAM,oBAAoB,CAAC;AAM5B,qCAAqC;AACrC,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,aAAa,GAAG,cAAc,EACrC,MAAM,EAAE,MAAM,GACb,YAAY,CAoBd"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { getTableLength, getTableRowAsObject } from '@loaders.gl/schema';
|
|
5
|
-
import { getGeoMetadata } from
|
|
4
|
+
import { getTableLength, getTableRowAsObject } from '@loaders.gl/schema-utils';
|
|
5
|
+
import { getGeoMetadata } from '@loaders.gl/geoarrow';
|
|
6
|
+
import { convertWKBToGeometry } from "../geometry-converters/wkb/convert-wkb-to-geometry.js";
|
|
7
|
+
import { convertWKTToGeometry } from "../geometry-converters/wkb/convert-wkt-to-geometry.js";
|
|
6
8
|
/** TODO - move to loaders.gl/gis? */
|
|
7
|
-
export function convertWKBTableToGeoJSON(table, schema
|
|
8
|
-
const geoMetadata = getGeoMetadata(schema);
|
|
9
|
+
export function convertWKBTableToGeoJSON(table, schema) {
|
|
10
|
+
const geoMetadata = getGeoMetadata(schema.metadata);
|
|
9
11
|
const primaryColumn = geoMetadata?.primary_column;
|
|
10
12
|
if (!primaryColumn) {
|
|
11
13
|
throw new Error('no geometry column');
|
|
@@ -15,30 +17,22 @@ export function convertWKBTableToGeoJSON(table, schema, loaders) {
|
|
|
15
17
|
const length = getTableLength(table);
|
|
16
18
|
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
17
19
|
const row = getTableRowAsObject(table, rowIndex);
|
|
18
|
-
const geometry = parseGeometry(row[primaryColumn], columnMetadata
|
|
20
|
+
const geometry = parseGeometry(row[primaryColumn], columnMetadata);
|
|
19
21
|
delete row[primaryColumn];
|
|
20
22
|
const feature = { type: 'Feature', geometry: geometry, properties: row };
|
|
21
23
|
features.push(feature);
|
|
22
24
|
}
|
|
23
25
|
return { shape: 'geojson-table', schema, type: 'FeatureCollection', features };
|
|
24
26
|
}
|
|
25
|
-
function parseGeometry(geometry, columnMetadata
|
|
27
|
+
function parseGeometry(geometry, columnMetadata) {
|
|
26
28
|
switch (columnMetadata.encoding) {
|
|
27
29
|
case 'wkt':
|
|
28
|
-
|
|
29
|
-
return wktLoader?.parseTextSync?.(geometry) || null;
|
|
30
|
+
return convertWKTToGeometry(geometry) || null;
|
|
30
31
|
case 'wkb':
|
|
31
32
|
default:
|
|
32
|
-
const wkbLoader = loaders.find((loader) => loader.id === 'wkb');
|
|
33
33
|
const arrayBuffer = ArrayBuffer.isView(geometry)
|
|
34
34
|
? geometry.buffer.slice(geometry.byteOffset, geometry.byteOffset + geometry.byteLength)
|
|
35
35
|
: geometry;
|
|
36
|
-
|
|
37
|
-
wkb: { shape: 'geojson-geometry' }
|
|
38
|
-
});
|
|
39
|
-
return geojson; // binaryGeometry ? binaryToGeometry(binaryGeometry) : null;
|
|
40
|
-
// const binaryGeometry = WKBLoader.parseSync?.(geometry);
|
|
41
|
-
// ts-ignore
|
|
42
|
-
// return binaryGeometry ? binaryToGeometry(binaryGeometry) : null;
|
|
36
|
+
return convertWKBToGeometry(arrayBuffer);
|
|
43
37
|
}
|
|
44
38
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
import type { Table } from '@loaders.gl/schema';
|
|
3
|
+
export declare function makeTableToArrowBatchesIterator(table: Table, options?: {
|
|
4
|
+
batchSize?: number;
|
|
5
|
+
}): IterableIterator<arrow.RecordBatch>;
|
|
6
|
+
//# sourceMappingURL=make-arrow-batch-iterator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-arrow-batch-iterator.d.ts","sourceRoot":"","sources":["../../../src/lib/table-converters/make-arrow-batch-iterator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAQ9C,wBAAiB,+BAA+B,CAC9C,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,GAC7B,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,CAoCrC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
import { convertSchemaToArrow, getTableLength, getTableNumCols, getTableCellAt } from '@loaders.gl/schema-utils';
|
|
6
|
+
export function* makeTableToArrowBatchesIterator(table, options) {
|
|
7
|
+
const arrowSchema = convertSchemaToArrow(table.schema);
|
|
8
|
+
const length = getTableLength(table);
|
|
9
|
+
const numColumns = getTableNumCols(table);
|
|
10
|
+
const batchSize = options?.batchSize || length;
|
|
11
|
+
const builders = arrowSchema?.fields.map((arrowField) => arrow.makeBuilder(arrowField));
|
|
12
|
+
const structField = new arrow.Struct(arrowSchema.fields);
|
|
13
|
+
let batchLength = 0;
|
|
14
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
15
|
+
for (let columnIndex = 0; columnIndex < numColumns; ++columnIndex) {
|
|
16
|
+
const value = getTableCellAt(table, rowIndex, columnIndex);
|
|
17
|
+
const builder = builders[columnIndex];
|
|
18
|
+
builder.append(value);
|
|
19
|
+
batchLength++;
|
|
20
|
+
if (batchLength >= batchSize) {
|
|
21
|
+
const datas = builders.map((builder) => builder.flush());
|
|
22
|
+
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
23
|
+
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
24
|
+
batchLength = 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (batchLength > 0) {
|
|
29
|
+
const datas = builders.map((builder) => builder.flush());
|
|
30
|
+
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
31
|
+
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
32
|
+
batchLength = 0;
|
|
33
|
+
}
|
|
34
|
+
builders.map((builder) => builder.finish());
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/base64-encoder.ts"],"names":[],"mappings":"AA0BA,qBAAa,aAAa;IACxB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAI3C,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW;CAC/C"}
|