@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,164 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { convertWKBToGeometry } from "./wkb/convert-wkb-to-geometry.js";
|
|
5
|
+
import { convertWKTToGeometry } from "./wkb/convert-wkt-to-geometry.js";
|
|
6
|
+
/**
|
|
7
|
+
* parse geometry from arrow data that is returned from processArrowData()
|
|
8
|
+
* NOTE: this function could be deduplicated with the binaryToGeometry() in deck.gl,
|
|
9
|
+
* it is currently used for deck.gl picking because currently deck.gl returns only the index of the feature
|
|
10
|
+
*
|
|
11
|
+
* @param data data extraced from arrow vector representing a geometry
|
|
12
|
+
* @param encoding the geoarrow encoding of the geometry column
|
|
13
|
+
* @returns Feature or null
|
|
14
|
+
*/
|
|
15
|
+
export function convertGeoArrowGeometryToGeoJSON(arrowCellValue, encoding) {
|
|
16
|
+
// sanity
|
|
17
|
+
encoding = encoding?.toLowerCase();
|
|
18
|
+
if (!encoding || !arrowCellValue) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
switch (encoding) {
|
|
22
|
+
case 'geoarrow.multipolygon':
|
|
23
|
+
return arrowMultiPolygonToGeometry(arrowCellValue);
|
|
24
|
+
case 'geoarrow.polygon':
|
|
25
|
+
return arrowPolygonToGeometry(arrowCellValue);
|
|
26
|
+
case 'geoarrow.multipoint':
|
|
27
|
+
return arrowMultiPointToGeometry(arrowCellValue);
|
|
28
|
+
case 'geoarrow.point':
|
|
29
|
+
return arrowPointToGeometry(arrowCellValue);
|
|
30
|
+
case 'geoarrow.multilinestring':
|
|
31
|
+
return arrowMultiLineStringToGeometry(arrowCellValue);
|
|
32
|
+
case 'geoarrow.linestring':
|
|
33
|
+
return arrowLineStringToGeometry(arrowCellValue);
|
|
34
|
+
case 'geoarrow.wkb':
|
|
35
|
+
return arrowWKBToGeometry(arrowCellValue);
|
|
36
|
+
case 'geoarrow.wkt':
|
|
37
|
+
return arrowWKTToGeometry(arrowCellValue);
|
|
38
|
+
default: {
|
|
39
|
+
throw Error(`GeoArrow encoding not supported ${encoding}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function arrowWKBToGeometry(arrowCellValue) {
|
|
44
|
+
// The actual WKB array buffer starts from byteOffset and ends at byteOffset + byteLength
|
|
45
|
+
const arrayBuffer = arrowCellValue.buffer.slice(arrowCellValue.byteOffset, arrowCellValue.byteOffset + arrowCellValue.byteLength);
|
|
46
|
+
return convertWKBToGeometry(arrayBuffer);
|
|
47
|
+
}
|
|
48
|
+
function arrowWKTToGeometry(arrowCellValue) {
|
|
49
|
+
const string = arrowCellValue;
|
|
50
|
+
return convertWKTToGeometry(string);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* convert Arrow MultiPolygon to geojson Feature
|
|
54
|
+
*/
|
|
55
|
+
function arrowMultiPolygonToGeometry(arrowMultiPolygon) {
|
|
56
|
+
const multiPolygon = [];
|
|
57
|
+
for (let m = 0; m < arrowMultiPolygon.length; m++) {
|
|
58
|
+
const arrowPolygon = arrowMultiPolygon.get(m);
|
|
59
|
+
const polygon = [];
|
|
60
|
+
for (let i = 0; arrowPolygon && i < arrowPolygon?.length; i++) {
|
|
61
|
+
const arrowRing = arrowPolygon?.get(i);
|
|
62
|
+
const ring = [];
|
|
63
|
+
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
64
|
+
const arrowCoord = arrowRing.get(j);
|
|
65
|
+
const coord = Array.from(arrowCoord);
|
|
66
|
+
ring.push(coord);
|
|
67
|
+
}
|
|
68
|
+
polygon.push(ring);
|
|
69
|
+
}
|
|
70
|
+
multiPolygon.push(polygon);
|
|
71
|
+
}
|
|
72
|
+
const geometry = {
|
|
73
|
+
type: 'MultiPolygon',
|
|
74
|
+
coordinates: multiPolygon
|
|
75
|
+
};
|
|
76
|
+
return geometry;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* convert Arrow Polygon to geojson Feature
|
|
80
|
+
*/
|
|
81
|
+
function arrowPolygonToGeometry(arrowPolygon) {
|
|
82
|
+
const polygon = [];
|
|
83
|
+
for (let i = 0; arrowPolygon && i < arrowPolygon.length; i++) {
|
|
84
|
+
const arrowRing = arrowPolygon.get(i);
|
|
85
|
+
const ring = [];
|
|
86
|
+
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
87
|
+
const arrowCoord = arrowRing.get(j);
|
|
88
|
+
const coords = Array.from(arrowCoord);
|
|
89
|
+
ring.push(coords);
|
|
90
|
+
}
|
|
91
|
+
polygon.push(ring);
|
|
92
|
+
}
|
|
93
|
+
const geometry = {
|
|
94
|
+
type: 'Polygon',
|
|
95
|
+
coordinates: polygon
|
|
96
|
+
};
|
|
97
|
+
return geometry;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* convert Arrow MultiPoint to geojson MultiPoint
|
|
101
|
+
*/
|
|
102
|
+
function arrowMultiPointToGeometry(arrowMultiPoint) {
|
|
103
|
+
const multiPoint = [];
|
|
104
|
+
for (let i = 0; arrowMultiPoint && i < arrowMultiPoint.length; i++) {
|
|
105
|
+
const arrowPoint = arrowMultiPoint.get(i);
|
|
106
|
+
if (arrowPoint) {
|
|
107
|
+
const coord = Array.from(arrowPoint);
|
|
108
|
+
multiPoint.push(coord);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
type: 'MultiPoint',
|
|
113
|
+
coordinates: multiPoint
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* convert Arrow Point to geojson Point
|
|
118
|
+
*/
|
|
119
|
+
function arrowPointToGeometry(arrowPoint) {
|
|
120
|
+
const point = Array.from(arrowPoint);
|
|
121
|
+
return {
|
|
122
|
+
type: 'Point',
|
|
123
|
+
coordinates: point
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* convert Arrow MultiLineString to geojson MultiLineString
|
|
128
|
+
*/
|
|
129
|
+
function arrowMultiLineStringToGeometry(arrowMultiLineString) {
|
|
130
|
+
const multiLineString = [];
|
|
131
|
+
for (let i = 0; arrowMultiLineString && i < arrowMultiLineString.length; i++) {
|
|
132
|
+
const arrowLineString = arrowMultiLineString.get(i);
|
|
133
|
+
const lineString = [];
|
|
134
|
+
for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
|
|
135
|
+
const arrowCoord = arrowLineString.get(j);
|
|
136
|
+
if (arrowCoord) {
|
|
137
|
+
const coords = Array.from(arrowCoord);
|
|
138
|
+
lineString.push(coords);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
multiLineString.push(lineString);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
type: 'MultiLineString',
|
|
145
|
+
coordinates: multiLineString
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* convert Arrow LineString to geojson LineString
|
|
150
|
+
*/
|
|
151
|
+
function arrowLineStringToGeometry(arrowLineString) {
|
|
152
|
+
const lineString = [];
|
|
153
|
+
for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
|
|
154
|
+
const arrowCoord = arrowLineString.get(i);
|
|
155
|
+
if (arrowCoord) {
|
|
156
|
+
const coords = Array.from(arrowCoord);
|
|
157
|
+
lineString.push(coords);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
type: 'LineString',
|
|
162
|
+
coordinates: lineString
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Geometry, BinaryGeometry } from '@loaders.gl/schema';
|
|
2
|
+
export declare function convertToGeoJSON(geometry: ArrayBuffer | string): Geometry;
|
|
3
|
+
export declare function convertToBinaryGeometry(geometry: ArrayBuffer | string | Geometry): BinaryGeometry;
|
|
4
|
+
export declare function convertToWKT(geometry: Geometry): string;
|
|
5
|
+
export declare function convertToWKB(geometry: Geometry): ArrayBuffer;
|
|
6
|
+
//# sourceMappingURL=convert-to-geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-to-geojson.d.ts","sourceRoot":"","sources":["../../../src/lib/geometry-converters/convert-to-geojson.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,QAAQ,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AASjE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,CAYzE;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,CAYjG;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEvD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAE5D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { convertGeometryToWKB } from "./wkb/convert-geometry-to-wkb.js";
|
|
5
|
+
import { convertGeometryToWKT } from "./wkb/convert-geometry-to-wkt.js";
|
|
6
|
+
import { convertWKBToBinaryGeometry } from "./wkb/convert-wkb-to-binary-geometry.js";
|
|
7
|
+
import { convertWKTToGeometry } from "./wkb/convert-wkt-to-geometry.js";
|
|
8
|
+
import { convertBinaryGeometryToGeometry } from "./convert-binary-geometry-to-geojson.js";
|
|
9
|
+
export function convertToGeoJSON(geometry) {
|
|
10
|
+
if (geometry instanceof ArrayBuffer) {
|
|
11
|
+
const binaryGeometry = convertWKBToBinaryGeometry(geometry);
|
|
12
|
+
return convertBinaryGeometryToGeometry(binaryGeometry);
|
|
13
|
+
}
|
|
14
|
+
// Assume string encoded WKT
|
|
15
|
+
if (typeof geometry === 'string') {
|
|
16
|
+
return convertWKTToGeometry(geometry);
|
|
17
|
+
}
|
|
18
|
+
throw new Error('Geo conversion not implemented');
|
|
19
|
+
}
|
|
20
|
+
export function convertToBinaryGeometry(geometry) {
|
|
21
|
+
if (geometry instanceof ArrayBuffer) {
|
|
22
|
+
return convertWKBToBinaryGeometry(geometry);
|
|
23
|
+
}
|
|
24
|
+
// Assume string encoded WKT
|
|
25
|
+
if (typeof geometry === 'string') {
|
|
26
|
+
// const geometry = convertWKTToGeometry(geometry);
|
|
27
|
+
// return convertGeometryToBinaryGeometry(geometry);
|
|
28
|
+
}
|
|
29
|
+
throw new Error('Geo conversion not implemented');
|
|
30
|
+
}
|
|
31
|
+
export function convertToWKT(geometry) {
|
|
32
|
+
return convertGeometryToWKT(geometry);
|
|
33
|
+
}
|
|
34
|
+
export function convertToWKB(geometry) {
|
|
35
|
+
return convertGeometryToWKB(geometry);
|
|
36
|
+
}
|
|
37
|
+
// export function convertToTWKB(geometry: Geometry): ArrayBuffer {
|
|
38
|
+
// return convertGeometryToTWKB(geometry);
|
|
39
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-geometry-to-twkb.d.ts","sourceRoot":"","sources":["../../../../src/lib/geometry-converters/wkb/convert-geometry-to-twkb.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAQV,QAAQ,EACT,MAAM,oBAAoB,CAAC;AAmB5B,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAC,GACzC,WAAW,CAab"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
|
|
5
|
+
import { BinaryWriter } from "../../utils/binary-writer.js";
|
|
6
|
+
import { WKBGeometryType } from "./helpers/wkb-types.js";
|
|
7
|
+
export function convertGeometryToTWKB(geometry, options) {
|
|
8
|
+
const writer = new BinaryWriter(0, true);
|
|
9
|
+
const context = {
|
|
10
|
+
...getTwkbPrecision(5, 0, 0),
|
|
11
|
+
hasZ: options?.hasZ,
|
|
12
|
+
hasM: options?.hasM
|
|
13
|
+
};
|
|
14
|
+
encodeGeometry(writer, geometry, context);
|
|
15
|
+
// TODO - we need to slice it?
|
|
16
|
+
return writer.arrayBuffer;
|
|
17
|
+
}
|
|
18
|
+
function encodeGeometry(writer, geometry, context) {
|
|
19
|
+
switch (geometry.type) {
|
|
20
|
+
case 'Point':
|
|
21
|
+
return encodePoint(writer, context, geometry);
|
|
22
|
+
case 'LineString':
|
|
23
|
+
return encodeLineString(writer, context, geometry);
|
|
24
|
+
case 'Polygon':
|
|
25
|
+
return encodePolygon(writer, context, geometry);
|
|
26
|
+
case 'MultiPoint':
|
|
27
|
+
return encodeMultiPoint(writer, context, geometry);
|
|
28
|
+
case 'MultiLineString':
|
|
29
|
+
return encodeMultiLineString(writer, context, geometry);
|
|
30
|
+
case 'MultiPolygon':
|
|
31
|
+
return encodeMultiPolygon(writer, context, geometry);
|
|
32
|
+
case 'GeometryCollection':
|
|
33
|
+
return encodeGeometryCollection(writer, context, geometry);
|
|
34
|
+
default:
|
|
35
|
+
throw new Error('unsupported geometry type');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function encodePoint(writer, context, point) {
|
|
39
|
+
const isEmpty = point.coordinates.length === 0 || point[0] === 'undefined' || point[1] === 'undefined';
|
|
40
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
|
|
41
|
+
if (!isEmpty) {
|
|
42
|
+
const previousPoint = [0, 0, 0, 0];
|
|
43
|
+
writeTwkbPoint(writer, context, point.coordinates, previousPoint);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function encodeLineString(writer, context, lineString) {
|
|
47
|
+
const points = lineString.coordinates;
|
|
48
|
+
const isEmpty = points.length === 0;
|
|
49
|
+
writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
|
|
50
|
+
if (!isEmpty) {
|
|
51
|
+
writer.writeVarInt(points.length);
|
|
52
|
+
const previousPoint = [0, 0, 0, 0];
|
|
53
|
+
for (const point of points) {
|
|
54
|
+
writeTwkbPoint(writer, context, point, previousPoint);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return writer.arrayBuffer;
|
|
58
|
+
}
|
|
59
|
+
function encodePolygon(writer, context, polygon) {
|
|
60
|
+
const polygonRings = polygon.coordinates;
|
|
61
|
+
const isEmpty = polygonRings.length === 0;
|
|
62
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
|
|
63
|
+
if (!isEmpty) {
|
|
64
|
+
writer.writeVarInt(polygonRings.length);
|
|
65
|
+
const previousPoint = [0, 0, 0, 0];
|
|
66
|
+
for (const ring of polygonRings) {
|
|
67
|
+
writer.writeVarInt(ring.length);
|
|
68
|
+
for (const point of ring) {
|
|
69
|
+
writeTwkbPoint(writer, context, previousPoint, point);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return writer.arrayBuffer;
|
|
74
|
+
}
|
|
75
|
+
function encodeMultiPoint(writer, context, multiPoint) {
|
|
76
|
+
const points = multiPoint.coordinates;
|
|
77
|
+
const isEmpty = points.length === 0;
|
|
78
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
|
|
79
|
+
if (!isEmpty) {
|
|
80
|
+
writer.writeVarInt(points.length);
|
|
81
|
+
const previousPoint = [0, 0, 0, 0];
|
|
82
|
+
for (let i = 0; i < points.length; i++) {
|
|
83
|
+
writeTwkbPoint(writer, context, previousPoint, points[i]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function encodeMultiLineString(writer, context, multiLineStrings) {
|
|
88
|
+
const lineStrings = multiLineStrings.coordinates;
|
|
89
|
+
const isEmpty = lineStrings.length === 0;
|
|
90
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
|
|
91
|
+
if (!isEmpty) {
|
|
92
|
+
writer.writeVarInt(lineStrings.length);
|
|
93
|
+
const previousPoint = [0, 0, 0, 0];
|
|
94
|
+
for (const lineString of lineStrings) {
|
|
95
|
+
writer.writeVarInt(lineString.length);
|
|
96
|
+
for (const point of lineString) {
|
|
97
|
+
writeTwkbPoint(writer, context, previousPoint, point);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return writer.arrayBuffer;
|
|
102
|
+
}
|
|
103
|
+
function encodeMultiPolygon(writer, context, multiPolygon) {
|
|
104
|
+
const { coordinates } = multiPolygon;
|
|
105
|
+
const isEmpty = coordinates.length === 0;
|
|
106
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
|
|
107
|
+
if (!isEmpty) {
|
|
108
|
+
const polygons = coordinates;
|
|
109
|
+
writer.writeVarInt(polygons.length);
|
|
110
|
+
const previousPoint = [0, 0, 0, 0];
|
|
111
|
+
for (const polygonRings of polygons) {
|
|
112
|
+
writer.writeVarInt(polygonRings.length);
|
|
113
|
+
for (const ring of polygonRings) {
|
|
114
|
+
writer.writeVarInt(ring.length);
|
|
115
|
+
for (const point of ring) {
|
|
116
|
+
writeTwkbPoint(writer, context, previousPoint, point);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function encodeGeometryCollection(writer, context, geometryCollection) {
|
|
123
|
+
const { geometries } = geometryCollection;
|
|
124
|
+
const isEmpty = geometries.length === 0;
|
|
125
|
+
writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
|
|
126
|
+
if (geometries.length > 0) {
|
|
127
|
+
writer.writeVarInt(geometries.length);
|
|
128
|
+
for (const geometry of geometries) {
|
|
129
|
+
encodeGeometry(writer, geometry, context);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* @param writer
|
|
136
|
+
* @param context
|
|
137
|
+
* @param geometryType
|
|
138
|
+
* @param isEmpty
|
|
139
|
+
*/
|
|
140
|
+
function writeTwkbHeader(writer, context, geometryType, isEmpty) {
|
|
141
|
+
const type = (zigZagEncode(context.xy) << 4) + geometryType;
|
|
142
|
+
let metadataHeader = context.hasZ || context.hasM ? 1 << 3 : 0;
|
|
143
|
+
metadataHeader += isEmpty ? 1 << 4 : 0;
|
|
144
|
+
writer.writeUInt8(type);
|
|
145
|
+
writer.writeUInt8(metadataHeader);
|
|
146
|
+
if (context.hasZ || context.hasM) {
|
|
147
|
+
let extendedPrecision = 0;
|
|
148
|
+
if (context.hasZ) {
|
|
149
|
+
extendedPrecision |= 0x1;
|
|
150
|
+
}
|
|
151
|
+
if (context.hasM) {
|
|
152
|
+
extendedPrecision |= 0x2;
|
|
153
|
+
}
|
|
154
|
+
writer.writeUInt8(extendedPrecision);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Write one point to array buffer. ZigZagEncoding the delta fdrom the previous point. Mutates previousPoint.
|
|
159
|
+
* @param writer
|
|
160
|
+
* @param context
|
|
161
|
+
* @param previousPoint - Mutated by this function
|
|
162
|
+
* @param point
|
|
163
|
+
*/
|
|
164
|
+
function writeTwkbPoint(writer, context, point, previousPoint) {
|
|
165
|
+
const x = point[0] * context.xyFactor;
|
|
166
|
+
const y = point[1] * context.xyFactor;
|
|
167
|
+
const z = point[2] * context.zFactor;
|
|
168
|
+
const m = point[3] * context.mFactor;
|
|
169
|
+
writer.writeVarInt(zigZagEncode(x - previousPoint[0]));
|
|
170
|
+
writer.writeVarInt(zigZagEncode(y - previousPoint[1]));
|
|
171
|
+
if (context.hasZ) {
|
|
172
|
+
writer.writeVarInt(zigZagEncode(z - previousPoint[2]));
|
|
173
|
+
}
|
|
174
|
+
if (context.hasM) {
|
|
175
|
+
writer.writeVarInt(zigZagEncode(m - previousPoint[3]));
|
|
176
|
+
}
|
|
177
|
+
previousPoint[0] = x;
|
|
178
|
+
previousPoint[1] = y;
|
|
179
|
+
previousPoint[2] = z;
|
|
180
|
+
previousPoint[3] = m;
|
|
181
|
+
}
|
|
182
|
+
// HELPERS
|
|
183
|
+
function zigZagEncode(value) {
|
|
184
|
+
return (value << 1) ^ (value >> 31);
|
|
185
|
+
}
|
|
186
|
+
function getTwkbPrecision(xyPrecision, zPrecision, mPrecision) {
|
|
187
|
+
return {
|
|
188
|
+
xy: xyPrecision,
|
|
189
|
+
z: zPrecision,
|
|
190
|
+
m: mPrecision,
|
|
191
|
+
xyFactor: Math.pow(10, xyPrecision),
|
|
192
|
+
zFactor: Math.pow(10, zPrecision),
|
|
193
|
+
mFactor: Math.pow(10, mPrecision)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Feature, Geometry } from '@loaders.gl/schema';
|
|
2
|
+
import { WKBOptions } from "./helpers/wkb-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Encodes a GeoJSON object into WKB
|
|
5
|
+
* @param geojson A GeoJSON Feature or Geometry
|
|
6
|
+
* @returns string
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertGeometryToWKB(geometry: Geometry | Feature, options?: WKBOptions): ArrayBuffer;
|
|
9
|
+
//# sourceMappingURL=convert-geometry-to-wkb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-geometry-to-wkb.d.ts","sourceRoot":"","sources":["../../../../src/lib/geometry-converters/wkb/convert-geometry-to-wkb.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EAQT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAkB,UAAU,EAAC,+BAA4B;AAGhE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,QAAQ,GAAG,OAAO,EAC5B,OAAO,GAAE,UAAe,GACvB,WAAW,CAwBb"}
|