@loaders.gl/gis 4.3.4 → 4.4.0-alpha.10
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 +39 -15
- package/dist/index.js.map +1 -0
- 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 +49 -0
- package/dist/lib/binary-geometry-api/binary-geometry-info.js.map +1 -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 +51 -0
- package/dist/lib/binary-geometry-api/concat-binary-geometry.js.map +1 -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} +1 -1
- package/dist/lib/binary-geometry-api/transform-coordinates.js.map +1 -0
- 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} +4 -90
- package/dist/lib/feature-collection-converters/convert-binary-features-to-geojson.js.map +1 -0
- 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} +6 -5
- package/dist/lib/feature-collection-converters/convert-flat-geojson-to-binary-features.js.map +1 -0
- 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 +378 -0
- package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.js.map +1 -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 +25 -0
- package/dist/lib/feature-collection-converters/convert-geojson-to-binary-features.js.map +1 -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} +5 -1
- package/dist/lib/feature-collection-converters/convert-geojson-to-flat-geojson.js.map +1 -0
- 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 +5 -0
- package/dist/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.js.map +1 -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} +5 -1
- package/dist/lib/geometry-api/geometry-info.js.map +1 -0
- 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 +92 -0
- package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.js.map +1 -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 +165 -0
- package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.js.map +1 -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 +40 -0
- package/dist/lib/geometry-converters/convert-to-geojson.js.map +1 -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 +196 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.js.map +1 -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 +274 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.js.map +1 -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 +45 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.js.map +1 -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 +255 -0
- package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.js.map +1 -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 +165 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js.map +1 -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 +10 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.js.map +1 -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 +259 -0
- package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.js.map +1 -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 +175 -0
- package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.js.map +1 -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 +47 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-types.js.map +1 -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 +65 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.js.map +1 -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 +34 -0
- package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.js.map +1 -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 +155 -0
- package/dist/lib/table-converters/convert-geoarrow-table.js.map +1 -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} +11 -16
- package/dist/lib/table-converters/convert-wkb-table-to-geojson.js.map +1 -0
- 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 +36 -0
- package/dist/lib/table-converters/make-arrow-batch-iterator.js.map +1 -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 +154 -0
- package/dist/lib/utils/base64-encoder.js.map +1 -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 +70 -0
- package/dist/lib/utils/binary-reader.js.map +1 -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 +128 -0
- package/dist/lib/utils/binary-writer.js.map +1 -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 +19 -0
- package/dist/lib/utils/concat-typed-arrays.js.map +1 -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 +55 -0
- package/dist/lib/utils/hex-encoder.js.map +1 -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 +51 -0
- package/dist/lib/utils/hex-transcoder.js.map +1 -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 +36 -0
- package/dist/lib/wkt-crs/encode-wkt-crs.js.map +1 -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 +121 -0
- package/dist/lib/wkt-crs/parse-wkt-crs.js.map +1 -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
|
@@ -3,30 +3,18 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
-
BinaryGeometry,
|
|
7
6
|
BinaryGeometryType,
|
|
8
|
-
BinaryPointGeometry,
|
|
9
|
-
BinaryLineGeometry,
|
|
10
|
-
BinaryPolygonGeometry,
|
|
11
7
|
BinaryFeatureCollection,
|
|
12
8
|
BinaryFeature,
|
|
13
9
|
// BinaryPointFeature,
|
|
14
10
|
// BinaryLineFeature,
|
|
15
11
|
// BinaryPolygonFeature,
|
|
16
|
-
BinaryAttribute,
|
|
17
12
|
Feature,
|
|
18
|
-
|
|
19
|
-
Position,
|
|
20
|
-
GeoJsonProperties,
|
|
21
|
-
Point,
|
|
22
|
-
MultiPoint,
|
|
23
|
-
LineString,
|
|
24
|
-
MultiLineString,
|
|
25
|
-
Polygon,
|
|
26
|
-
MultiPolygon
|
|
13
|
+
GeoJsonProperties
|
|
27
14
|
} from '@loaders.gl/schema';
|
|
15
|
+
import {convertBinaryGeometryToGeometry} from '../geometry-converters/convert-binary-geometry-to-geojson';
|
|
28
16
|
|
|
29
|
-
// Note:
|
|
17
|
+
// Note: We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.
|
|
30
18
|
// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
|
|
31
19
|
|
|
32
20
|
type BinaryToGeoJsonOptions = {
|
|
@@ -42,7 +30,7 @@ type BinaryToGeoJsonOptions = {
|
|
|
42
30
|
* @param options.featureId Global feature id. If specified, only a single feature is extracted
|
|
43
31
|
* @return GeoJSON objects
|
|
44
32
|
*/
|
|
45
|
-
export function
|
|
33
|
+
export function convertBinaryFeatureCollectionToGeojson(
|
|
46
34
|
data: BinaryFeatureCollection,
|
|
47
35
|
options?: BinaryToGeoJsonOptions
|
|
48
36
|
): Feature[] | Feature {
|
|
@@ -91,25 +79,6 @@ function parseFeatures(data: BinaryFeatureCollection, type?: BinaryGeometryType)
|
|
|
91
79
|
return parseFeatureCollection(dataArray);
|
|
92
80
|
}
|
|
93
81
|
|
|
94
|
-
/** Parse input binary data and return a valid GeoJSON geometry object */
|
|
95
|
-
export function binaryToGeometry(
|
|
96
|
-
data: BinaryGeometry,
|
|
97
|
-
startIndex?: number,
|
|
98
|
-
endIndex?: number
|
|
99
|
-
): Geometry {
|
|
100
|
-
switch (data.type) {
|
|
101
|
-
case 'Point':
|
|
102
|
-
return pointToGeoJson(data, startIndex, endIndex);
|
|
103
|
-
case 'LineString':
|
|
104
|
-
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
105
|
-
case 'Polygon':
|
|
106
|
-
return polygonToGeoJson(data, startIndex, endIndex);
|
|
107
|
-
default:
|
|
108
|
-
const unexpectedInput: never = data;
|
|
109
|
-
throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
82
|
// Normalize features
|
|
114
83
|
// Return an array of data objects, each of which have a type key
|
|
115
84
|
function normalizeInput(data: BinaryFeatureCollection, type?: BinaryGeometryType): BinaryFeature[] {
|
|
@@ -162,7 +131,7 @@ function parseFeatureCollection(dataArray: BinaryFeature[]): Feature[] {
|
|
|
162
131
|
|
|
163
132
|
/** Parse input binary data and return a single GeoJSON Feature */
|
|
164
133
|
function parseFeature(data: BinaryFeature, startIndex?: number, endIndex?: number): Feature {
|
|
165
|
-
const geometry =
|
|
134
|
+
const geometry = convertBinaryGeometryToGeometry(data, startIndex, endIndex);
|
|
166
135
|
const properties = parseProperties(data, startIndex, endIndex);
|
|
167
136
|
const fields = parseFields(data, startIndex, endIndex);
|
|
168
137
|
return {type: 'Feature', geometry, properties, ...fields};
|
|
@@ -181,109 +150,3 @@ function parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJs
|
|
|
181
150
|
}
|
|
182
151
|
return properties;
|
|
183
152
|
}
|
|
184
|
-
|
|
185
|
-
/** Parse binary data of type Polygon */
|
|
186
|
-
function polygonToGeoJson(
|
|
187
|
-
data: BinaryPolygonGeometry,
|
|
188
|
-
startIndex: number = -Infinity,
|
|
189
|
-
endIndex: number = Infinity
|
|
190
|
-
): Polygon | MultiPolygon {
|
|
191
|
-
const {positions} = data;
|
|
192
|
-
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
193
|
-
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(
|
|
194
|
-
(x) => x >= startIndex && x <= endIndex
|
|
195
|
-
);
|
|
196
|
-
const multi = polygonIndices.length > 2;
|
|
197
|
-
|
|
198
|
-
// Polygon
|
|
199
|
-
if (!multi) {
|
|
200
|
-
const coordinates: Position[][] = [];
|
|
201
|
-
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
202
|
-
const startRingIndex = primitivePolygonIndices[i];
|
|
203
|
-
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
204
|
-
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
205
|
-
coordinates.push(ringCoordinates);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return {type: 'Polygon', coordinates};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// MultiPolygon
|
|
212
|
-
const coordinates: Position[][][] = [];
|
|
213
|
-
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
214
|
-
const startPolygonIndex = polygonIndices[i];
|
|
215
|
-
const endPolygonIndex = polygonIndices[i + 1];
|
|
216
|
-
const polygonCoordinates = polygonToGeoJson(
|
|
217
|
-
data,
|
|
218
|
-
startPolygonIndex,
|
|
219
|
-
endPolygonIndex
|
|
220
|
-
).coordinates;
|
|
221
|
-
coordinates.push(polygonCoordinates as Position[][]);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return {type: 'MultiPolygon', coordinates};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/** Parse binary data of type LineString */
|
|
228
|
-
function lineStringToGeoJson(
|
|
229
|
-
data: BinaryLineGeometry,
|
|
230
|
-
startIndex: number = -Infinity,
|
|
231
|
-
endIndex: number = Infinity
|
|
232
|
-
): LineString | MultiLineString {
|
|
233
|
-
const {positions} = data;
|
|
234
|
-
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
235
|
-
const multi = pathIndices.length > 2;
|
|
236
|
-
|
|
237
|
-
if (!multi) {
|
|
238
|
-
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
239
|
-
return {type: 'LineString', coordinates};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const coordinates: Position[][] = [];
|
|
243
|
-
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
244
|
-
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
245
|
-
coordinates.push(ringCoordinates);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return {type: 'MultiLineString', coordinates};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** Parse binary data of type Point */
|
|
252
|
-
function pointToGeoJson(data: BinaryPointGeometry, startIndex, endIndex): Point | MultiPoint {
|
|
253
|
-
const {positions} = data;
|
|
254
|
-
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
255
|
-
const multi = coordinates.length > 1;
|
|
256
|
-
|
|
257
|
-
if (multi) {
|
|
258
|
-
return {type: 'MultiPoint', coordinates};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return {type: 'Point', coordinates: coordinates[0]};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Parse a linear ring of positions to a GeoJSON linear ring
|
|
266
|
-
*
|
|
267
|
-
* @param positions Positions TypedArray
|
|
268
|
-
* @param startIndex Start index to include in ring
|
|
269
|
-
* @param endIndex End index to include in ring
|
|
270
|
-
* @returns GeoJSON ring
|
|
271
|
-
*/
|
|
272
|
-
function ringToGeoJson(
|
|
273
|
-
positions: BinaryAttribute,
|
|
274
|
-
startIndex?: number,
|
|
275
|
-
endIndex?: number
|
|
276
|
-
): Position[] {
|
|
277
|
-
startIndex = startIndex || 0;
|
|
278
|
-
endIndex = endIndex || positions.value.length / positions.size;
|
|
279
|
-
|
|
280
|
-
const ringCoordinates: Position[] = [];
|
|
281
|
-
for (let j = startIndex; j < endIndex; j++) {
|
|
282
|
-
const coord = Array<number>();
|
|
283
|
-
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
284
|
-
coord.push(Number(positions.value[k]));
|
|
285
|
-
}
|
|
286
|
-
ringCoordinates.push(coord);
|
|
287
|
-
}
|
|
288
|
-
return ringCoordinates;
|
|
289
|
-
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
/* eslint-disable indent */
|
|
2
6
|
import {earcut} from '@math.gl/polygon';
|
|
3
7
|
import type {
|
|
@@ -8,10 +12,15 @@ import type {
|
|
|
8
12
|
FlatPoint,
|
|
9
13
|
FlatLineString,
|
|
10
14
|
FlatPolygon,
|
|
11
|
-
GeojsonGeometryInfo,
|
|
12
15
|
TypedArray
|
|
13
16
|
} from '@loaders.gl/schema';
|
|
14
|
-
import {
|
|
17
|
+
import {GeojsonGeometryInfo} from '../geometry-api/geometry-info';
|
|
18
|
+
import {
|
|
19
|
+
PropArrayConstructor,
|
|
20
|
+
Lines,
|
|
21
|
+
Points,
|
|
22
|
+
Polygons
|
|
23
|
+
} from './helpers/flat-geojson-to-binary-types';
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
26
|
* Convert binary features to flat binary arrays. Similar to
|
|
@@ -26,11 +35,11 @@ import {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-b
|
|
|
26
35
|
* @param options
|
|
27
36
|
* @returns filled arrays
|
|
28
37
|
*/
|
|
29
|
-
export function
|
|
38
|
+
export function convertFlatGeojsonToBinaryFeatureCollection(
|
|
30
39
|
features: FlatFeature[],
|
|
31
40
|
geometryInfo: GeojsonGeometryInfo,
|
|
32
41
|
options?: FlatGeojsonToBinaryOptions
|
|
33
|
-
) {
|
|
42
|
+
): BinaryFeatureCollection {
|
|
34
43
|
const propArrayTypes = extractNumericPropTypes(features);
|
|
35
44
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
36
45
|
return fillArrays(
|
|
@@ -56,17 +65,13 @@ export type FlatGeojsonToBinaryOptions = {
|
|
|
56
65
|
triangulate?: boolean;
|
|
57
66
|
};
|
|
58
67
|
|
|
59
|
-
export const TEST_EXPORTS = {
|
|
60
|
-
extractNumericPropTypes
|
|
61
|
-
};
|
|
62
|
-
|
|
63
68
|
/**
|
|
64
69
|
* Extracts properties that are always numeric
|
|
65
70
|
*
|
|
66
71
|
* @param features
|
|
67
72
|
* @returns object with numeric types
|
|
68
73
|
*/
|
|
69
|
-
function extractNumericPropTypes(features: FlatFeature[]): {
|
|
74
|
+
export function extractNumericPropTypes(features: FlatFeature[]): {
|
|
70
75
|
[key: string]: PropArrayConstructor;
|
|
71
76
|
} {
|
|
72
77
|
const propArrayTypes = {};
|