@loaders.gl/geoarrow 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.
Files changed (70) hide show
  1. package/LICENSE +41 -0
  2. package/README.md +7 -0
  3. package/dist/geo-column/geo-column-info.d.ts +20 -0
  4. package/dist/geo-column/geo-column-info.d.ts.map +1 -0
  5. package/dist/geo-column/geo-column-info.js +74 -0
  6. package/dist/geo-column/geo-column.d.ts +61 -0
  7. package/dist/geo-column/geo-column.d.ts.map +1 -0
  8. package/dist/geo-column/geo-column.js +4 -0
  9. package/dist/geoarrow-functions.d.ts +131 -0
  10. package/dist/geoarrow-functions.d.ts.map +1 -0
  11. package/dist/geoarrow-functions.js +218 -0
  12. package/dist/geoarrow-types.d.ts +49 -0
  13. package/dist/geoarrow-types.d.ts.map +1 -0
  14. package/dist/geoarrow-types.js +4 -0
  15. package/dist/get-arrow-bounds.d.ts +11 -0
  16. package/dist/get-arrow-bounds.d.ts.map +1 -0
  17. package/dist/get-arrow-bounds.js +34 -0
  18. package/dist/get-geoarrow-geometry-info.d.ts +30 -0
  19. package/dist/get-geoarrow-geometry-info.d.ts.map +1 -0
  20. package/dist/get-geoarrow-geometry-info.js +124 -0
  21. package/dist/index.cjs +430 -0
  22. package/dist/index.cjs.map +7 -0
  23. package/dist/index.d.ts +11 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +12 -0
  26. package/dist/mesharrow/arrow-fixed-size-list-utils.d.ts +11 -0
  27. package/dist/mesharrow/arrow-fixed-size-list-utils.d.ts.map +1 -0
  28. package/dist/mesharrow/arrow-fixed-size-list-utils.js +39 -0
  29. package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.d.ts +11 -0
  30. package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.d.ts.map +1 -0
  31. package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.js +31 -0
  32. package/dist/mesharrow/get-bounding-box.d.ts +5 -0
  33. package/dist/mesharrow/get-bounding-box.d.ts.map +1 -0
  34. package/dist/mesharrow/get-bounding-box.js +33 -0
  35. package/dist/mesharrow/get-deck-binary-data.d.ts +13 -0
  36. package/dist/mesharrow/get-deck-binary-data.d.ts.map +1 -0
  37. package/dist/mesharrow/get-deck-binary-data.js +24 -0
  38. package/dist/mesharrow/mesh-accessors.d.ts +8 -0
  39. package/dist/mesharrow/mesh-accessors.d.ts.map +1 -0
  40. package/dist/mesharrow/mesh-accessors.js +18 -0
  41. package/dist/metadata/geoarrow-metadata.d.ts +27 -0
  42. package/dist/metadata/geoarrow-metadata.d.ts.map +1 -0
  43. package/dist/metadata/geoarrow-metadata.js +71 -0
  44. package/dist/metadata/geoparquet-metadata-schema.d.ts +79 -0
  45. package/dist/metadata/geoparquet-metadata-schema.d.ts.map +1 -0
  46. package/dist/metadata/geoparquet-metadata-schema.js +69 -0
  47. package/dist/metadata/geoparquet-metadata.d.ts +45 -0
  48. package/dist/metadata/geoparquet-metadata.d.ts.map +1 -0
  49. package/dist/metadata/geoparquet-metadata.js +131 -0
  50. package/dist/metadata/metadata-utils.d.ts +21 -0
  51. package/dist/metadata/metadata-utils.d.ts.map +1 -0
  52. package/dist/metadata/metadata-utils.js +14 -0
  53. package/package.json +63 -0
  54. package/src/geo-column/geo-column-info.ts +114 -0
  55. package/src/geo-column/geo-column.ts +85 -0
  56. package/src/geoarrow-functions.ts +258 -0
  57. package/src/geoarrow-types.ts +72 -0
  58. package/src/get-arrow-bounds.ts +41 -0
  59. package/src/get-geo-column-from-geoarrow.ts.disabled +251 -0
  60. package/src/get-geoarrow-geometry-info.ts +172 -0
  61. package/src/index.ts +57 -0
  62. package/src/mesharrow/arrow-fixed-size-list-utils.ts +62 -0
  63. package/src/mesharrow/arrow-list-of-fixed-size-list-utils.ts +47 -0
  64. package/src/mesharrow/get-bounding-box.ts +39 -0
  65. package/src/mesharrow/get-deck-binary-data.ts +43 -0
  66. package/src/mesharrow/mesh-accessors.ts +27 -0
  67. package/src/metadata/geoarrow-metadata.ts +102 -0
  68. package/src/metadata/geoparquet-metadata-schema.ts +71 -0
  69. package/src/metadata/geoparquet-metadata.ts +195 -0
  70. package/src/metadata/metadata-utils.ts +32 -0
@@ -0,0 +1,45 @@
1
+ import { Metadata } from "./metadata-utils.js";
2
+ /**
3
+ * A geoarrow / geoparquet geo metadata object
4
+ * (stored in stringified form in the top level metadata 'geo' key)
5
+ * @see https://github.com/opengeospatial/geoparquet/blob/main/format-specs/geoparquet.md
6
+ * @see https://github.com/geoarrow/geoarrow
7
+ * */
8
+ export type GeoMetadata = {
9
+ version?: string;
10
+ primary_column?: string;
11
+ columns: Record<string, GeoColumnMetadata>;
12
+ [key: string]: unknown;
13
+ };
14
+ /** A geoarrow / geoparquet geo metadata for one geometry column */
15
+ export type GeoColumnMetadata = {
16
+ encoding: 'wkb' | 'wkt';
17
+ geometry_types: GeoParquetGeometryType[];
18
+ crs?: object | null;
19
+ orientation?: 'counterclockwise';
20
+ bbox?: [number, number, number, number] | [number, number, number, number, number, number];
21
+ edges?: 'planar' | 'spherical';
22
+ epoch?: number;
23
+ [key: string]: unknown;
24
+ };
25
+ /** A GeoParquet metadata geometry type */
26
+ export type GeoParquetGeometryType = 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'Point Z' | 'LineString Z' | 'Polygon Z' | 'MultiPoint Z' | 'MultiLineString Z' | 'MultiPolygon Z' | 'GeometryCollection Z';
27
+ /**
28
+ * Reads the GeoMetadata object from the metadata
29
+ * @note geoarrow / parquet schema is stringified into a single key-value pair in the parquet metadata
30
+ */
31
+ export declare function getGeoMetadata(metadata: Metadata): GeoMetadata | null;
32
+ /**
33
+ * Stores a geoarrow / geoparquet geo metadata object in the schema
34
+ * @note geoarrow / geoparquet geo metadata is a single stringified JSON field
35
+ */
36
+ export declare function setGeoMetadata(metadata: Metadata, geoMetadata: GeoMetadata): void;
37
+ /**
38
+ * Unpacks geo metadata into separate metadata fields (parses the long JSON string)
39
+ * @note geoarrow / parquet schema is stringified into a single key-value pair in the parquet metadata
40
+ */
41
+ export declare function unpackGeoMetadata(metadata: Metadata): void;
42
+ export declare function unpackJSONStringMetadata(metadata: Metadata, metadataKey: string): void;
43
+ /** Parse a key with stringified arrow metadata */
44
+ export declare function parseJSONStringMetadata(stringifiedMetadata: string): Record<string, unknown> | null;
45
+ //# sourceMappingURL=geoparquet-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geoparquet-metadata.d.ts","sourceRoot":"","sources":["../../src/metadata/geoparquet-metadata.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,QAAQ,EAAqC,4BAAyB;AAE9E;;;;;KAKK;AACL,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC3C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,cAAc,EAAE,sBAAsB,EAAE,CAAC;IACzC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3F,KAAK,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,sBAAsB,GAC9B,OAAO,GACP,YAAY,GACZ,SAAS,GACT,YAAY,GACZ,iBAAiB,GACjB,cAAc,GACd,oBAAoB,GACpB,SAAS,GACT,cAAc,GACd,WAAW,GACX,cAAc,GACd,mBAAmB,GACnB,gBAAgB,GAChB,sBAAsB,CAAC;AAI3B;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI,CAYrE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAGjF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CA6B1D;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAUtF;AAqDD,kDAAkD;AAClD,wBAAgB,uBAAuB,CACrC,mBAAmB,EAAE,MAAM,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAchC"}
@@ -0,0 +1,131 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /* eslint-disable camelcase */
5
+ import { getMetadataValue, setMetadataValue } from "./metadata-utils.js";
6
+ // GEO METADATA
7
+ /**
8
+ * Reads the GeoMetadata object from the metadata
9
+ * @note geoarrow / parquet schema is stringified into a single key-value pair in the parquet metadata
10
+ */
11
+ export function getGeoMetadata(metadata) {
12
+ const stringifiedGeoMetadata = getMetadataValue(metadata, 'geo');
13
+ const geoMetadata = stringifiedGeoMetadata && parseJSONStringMetadata(stringifiedGeoMetadata);
14
+ if (!geoMetadata) {
15
+ return null;
16
+ }
17
+ for (const column of Object.values(geoMetadata.columns || {})) {
18
+ if (column.encoding) {
19
+ column.encoding = column.encoding.toLowerCase();
20
+ }
21
+ }
22
+ return geoMetadata;
23
+ }
24
+ /**
25
+ * Stores a geoarrow / geoparquet geo metadata object in the schema
26
+ * @note geoarrow / geoparquet geo metadata is a single stringified JSON field
27
+ */
28
+ export function setGeoMetadata(metadata, geoMetadata) {
29
+ const stringifiedGeoMetadata = JSON.stringify(geoMetadata);
30
+ setMetadataValue(metadata, 'geo', stringifiedGeoMetadata);
31
+ }
32
+ /**
33
+ * Unpacks geo metadata into separate metadata fields (parses the long JSON string)
34
+ * @note geoarrow / parquet schema is stringified into a single key-value pair in the parquet metadata
35
+ */
36
+ export function unpackGeoMetadata(metadata) {
37
+ const geoMetadata = getGeoMetadata(metadata);
38
+ if (!geoMetadata) {
39
+ return;
40
+ }
41
+ // Store Parquet Schema Level Metadata
42
+ const { version, primary_column, columns } = geoMetadata;
43
+ if (version) {
44
+ setMetadataValue(metadata, 'geo.version', version);
45
+ }
46
+ if (primary_column) {
47
+ setMetadataValue(metadata, 'geo.primary_column', primary_column);
48
+ }
49
+ // store column names as comma separated list
50
+ setMetadataValue(metadata, 'geo.columns', Object.keys(columns || {}).join(''));
51
+ // for (const [columnName, columnMetadata] of Object.entries(columns || {})) {
52
+ // const field = schema.fields.find((field) => field.name === columnName);
53
+ // if (field) {
54
+ // if (field.name === primary_column) {
55
+ // setFieldMetadata(field, 'geo.primary_field', 'true');
56
+ // }
57
+ // unpackGeoFieldMetadata(field, columnMetadata);
58
+ // }
59
+ // }
60
+ }
61
+ export function unpackJSONStringMetadata(metadata, metadataKey) {
62
+ const stringifiedGeoMetadata = getMetadataValue(metadata, 'geo');
63
+ const json = stringifiedGeoMetadata && parseJSONStringMetadata(stringifiedGeoMetadata);
64
+ for (const [key, value] of Object.entries(json || {})) {
65
+ setMetadataValue(metadata, `${metadataKey}.${key}`, typeof value === 'string' ? value : JSON.stringify(value));
66
+ }
67
+ }
68
+ // eslint-disable-next-line complexity
69
+ // function unpackGeoFieldMetadata(fieldMetadata: Metadata, columnMetadata): void {
70
+ // for (const [key, value] of Object.entries(columnMetadata || {})) {
71
+ // switch (key) {
72
+ // case 'geometry_types':
73
+ // setFieldMetadata(field, `geo.${key}`, (value as string[]).join(','));
74
+ // break;
75
+ // case 'bbox':
76
+ // setFieldMetadata(field, `geo.crs.${key}`, JSON.stringify(value));
77
+ // break;
78
+ // case 'crs':
79
+ // // @ts-ignore
80
+ // for (const [crsKey, crsValue] of Object.entries(value || {})) {
81
+ // switch (crsKey) {
82
+ // case 'id':
83
+ // // prettier-ignore
84
+ // const crsId =
85
+ // typeof crsValue === 'object'
86
+ // ? // @ts-ignore
87
+ // `${crsValue?.authority}:${crsValue?.code}`
88
+ // : JSON.stringify(crsValue);
89
+ // setFieldMetadata(field, `geo.crs.${crsKey}`, crsId);
90
+ // break;
91
+ // default:
92
+ // setFieldMetadata(
93
+ // field,
94
+ // `geo.crs.${crsKey}`,
95
+ // typeof crsValue === 'string' ? crsValue : JSON.stringify(crsValue)
96
+ // );
97
+ // break;
98
+ // }
99
+ // }
100
+ // break;
101
+ // case 'edges':
102
+ // default:
103
+ // setFieldMetadata(
104
+ // field,
105
+ // `geo.${key}`,
106
+ // typeof value === 'string' ? value : JSON.stringify(value)
107
+ // );
108
+ // }
109
+ // }
110
+ // }
111
+ // function setFieldMetadata(field: Field, key: string, value: string): void {
112
+ // field.metadata = field.metadata || {};
113
+ // field.metadata[key] = value;
114
+ // }
115
+ // HELPERS
116
+ /** Parse a key with stringified arrow metadata */
117
+ export function parseJSONStringMetadata(stringifiedMetadata) {
118
+ if (!stringifiedMetadata) {
119
+ return null;
120
+ }
121
+ try {
122
+ const metadata = JSON.parse(stringifiedMetadata);
123
+ if (!metadata || typeof metadata !== 'object') {
124
+ return null;
125
+ }
126
+ return metadata;
127
+ }
128
+ catch {
129
+ return null;
130
+ }
131
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A type that matches a string-to-string metadata map
3
+ * in the form of a map or an object.
4
+ */
5
+ export type Metadata = Map<string, string> | Record<string, string>;
6
+ /**
7
+ * A type that matches a variety of Apache arrow like schemas.
8
+ *
9
+ */
10
+ export type SchemaWithMetadata = {
11
+ /** Schema level metadata */
12
+ metadata?: Metadata;
13
+ /** Field top-level metadata */
14
+ fields?: {
15
+ name: string;
16
+ metadata?: Metadata;
17
+ }[];
18
+ };
19
+ export declare function getMetadataValue(metadata: Metadata, key: string): string | null;
20
+ export declare function setMetadataValue(metadata: Metadata, key: string, value: string): void;
21
+ //# sourceMappingURL=metadata-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata-utils.d.ts","sourceRoot":"","sources":["../../src/metadata/metadata-utils.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,+BAA+B;IAC/B,MAAM,CAAC,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAC,EAAE,CAAC;CAChD,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE/E;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAMrF"}
@@ -0,0 +1,14 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export function getMetadataValue(metadata, key) {
5
+ return metadata instanceof Map ? metadata.get(key) || null : metadata[key] || null;
6
+ }
7
+ export function setMetadataValue(metadata, key, value) {
8
+ if (metadata instanceof Map) {
9
+ metadata.set('key', key);
10
+ }
11
+ else {
12
+ metadata.key = key;
13
+ }
14
+ }
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@loaders.gl/geoarrow",
3
+ "version": "4.4.0-alpha.1",
4
+ "description": "GeoArrow columnar geometry encoding and decoding",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/visgl/loaders.gl"
13
+ },
14
+ "keywords": [
15
+ "loader",
16
+ "parser",
17
+ "writer",
18
+ "encoder",
19
+ "geoarrow",
20
+ "apache-arrow",
21
+ "arrow",
22
+ "binary columnar",
23
+ "cloud native",
24
+ "webgl",
25
+ "webgpu"
26
+ ],
27
+ "types": "dist/index.d.ts",
28
+ "main": "dist/index.cjs",
29
+ "module": "dist/index.js",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "require": "./dist/index.cjs"
35
+ },
36
+ "./exports/*": {
37
+ "types": "./dist/exports/*.d.ts",
38
+ "import": "./dist/exports/*.js"
39
+ }
40
+ },
41
+ "sideEffects": false,
42
+ "files": [
43
+ "src",
44
+ "dist",
45
+ "README.md"
46
+ ],
47
+ "browser": {
48
+ "fs": false
49
+ },
50
+ "scripts": {
51
+ "pre-build": "",
52
+ "build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
53
+ "build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
54
+ },
55
+ "dependencies": {
56
+ "@math.gl/polygon": "^4.1.0",
57
+ "apache-arrow": ">= 16.1.0"
58
+ },
59
+ "peerDependencies": {
60
+ "@loaders.gl/core": "4.4.0-alpha.0"
61
+ },
62
+ "gitHead": "f1732de45907bd500bf4eedb4803beca8bf4bfb0"
63
+ }
@@ -0,0 +1,114 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // import type {GeoColumn} from './geo-column';
6
+ // import {getGeoParquetMetadata, GeoParquetMetadata} from '../metadata/geoparquet-metadata';
7
+ // import {getGeoArrowMetadata, GeoArrowMetadata} from '../metadata_3/geoarrow-metadata';
8
+
9
+ /**
10
+ * Information about a binary geometry
11
+ */
12
+ export type geoColumnInfo = {
13
+ type: 'Point' | 'LineString' | 'Polygon';
14
+ /** The GeoJSON style geometry type corresponding to this particular binary geometry */
15
+ multiGeometryType:
16
+ | 'Point'
17
+ | 'LineString'
18
+ | 'Polygon'
19
+ | 'MultiPoint'
20
+ | 'MultiLineString'
21
+ | 'MultiPolygon';
22
+ /** Is this a "Multi" version of the binary geometry? */
23
+ isMultiGeometry: boolean;
24
+ /** How many dimensions are the coordinates? */
25
+ dimension: number;
26
+ /** How many points does this geometry have? */
27
+ pointCount: number;
28
+ /** How many coordinates does this geometry have? */
29
+ coordinateCount: number;
30
+ };
31
+
32
+ /**
33
+ * @returns information about a binary geometry
34
+ */
35
+ // export function getGeoColumnInfo(geometry: GeoColumn): GeoColumnInfo {
36
+
37
+ // }
38
+
39
+ // // loaders.gl
40
+ // // SPDX-License-Identifier: MIT
41
+ // // Copyright (c) vis.gl contributors
42
+
43
+ // import type {Schema, Field, GeoArrowMetadata, GeoArrowEncoding, Geometry} from '@loaders.gl/schema';
44
+ // import {convertArrowToSchema} from '@loaders.gl/schema-utils';
45
+ // import * as arrow from 'apache-arrow';
46
+ // import {getGeometryColumnsFromSchema, getGeometryMetadataForField} from '../geoarrow/geoarrow-metadata';
47
+ // import { getGeoMetadata as getParquetMe} from './geoparquet-metadata';
48
+
49
+ // /**
50
+ // * A geoarrow / geoparquet geo metadata object
51
+ // * (stored in stringified form in the top level metadata 'geo' key)
52
+ // * @see https://github.com/opengeospatial/geoparquet/blob/main/format-specs/geoparquet.md
53
+ // * @see https://github.com/geoarrow/geoarrow
54
+ // * */
55
+ // export type GeoTableMetadata = {
56
+ // version?: string;
57
+ // primaryGeometryColumn?: string;
58
+ // columns: Record<string, GeoColumnInfo>;
59
+ // [key: string]: unknown;
60
+ // };
61
+
62
+ // /** A geoarrow / geoparquet geo metadata for one geometry column */
63
+ // export type GeoColumnInfo = {
64
+ // encoding: 'wkb' | 'wkt' | 'none';
65
+ // geometryTypes: Geometry['type'][];
66
+ // dimension: number;
67
+ // crs?: object | null;
68
+ // orientation?: 'counterclockwise';
69
+ // bbox?: [number, number, number, number] | [number, number, number, number, number, number];
70
+ // edges?: 'planar' | 'spherical';
71
+ // epoch?: number;
72
+
73
+ // [key: string]: unknown;
74
+ // // geoParquetGeometryType:
75
+ // };
76
+
77
+ // export type GeoArrowInfo = {
78
+ // geometryColumns: Record<string, GeometryColumnInfo>
79
+ // };
80
+
81
+ // /**
82
+ // * get geometry columns from arrow table
83
+ // */
84
+ // export function getGeoArrowInfo(arrowTable: arrow.Table): GeoArrowInfo {
85
+ // const schema = convertArrowToSchema(arrowTable.schema);
86
+ // const geometryColumns = getGeometryColumnsFromSchema(schema);
87
+
88
+ // // get encoding from geometryColumns['geometry']
89
+ // const encoding = geometryColumns.geometry.encoding;
90
+
91
+ // // Remove geometry columns
92
+ // const propertyColumnNames = arrowTable.schema.fields
93
+ // .map((field) => field.name)
94
+ // // TODO - this deletes all geometry columns
95
+ // .filter((name) => name in geometryColumns);
96
+ // const propertiesTable = arrowTable.select(propertyColumnNames);
97
+
98
+ // const arrowGeometryColumn = arrowTable.getChild('geometry');
99
+
100
+ // for (let row = 0; row < arrowTable.numRows; row++) {
101
+ // // get the geometry value from arrow geometry column
102
+ // // Note that type can vary
103
+ // const arrowGeometry = arrowGeometryColumn?.get(row);
104
+ // // parse arrow geometry to geojson feature
105
+ // const feature = convertGeoArrowGeometryToGeoJSON(arrowGeometry, encoding);
106
+ // if (feature) {
107
+ // const properties = propertiesTable.get(row)?.toJSON() || {};
108
+ // features.push({type: 'Feature', geometry: feature, properties});
109
+ // }
110
+ // }
111
+
112
+ // return {
113
+ // };
114
+ // }
@@ -0,0 +1,85 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // GIS
6
+ import type {TypedArray} from '@math.gl/types';
7
+
8
+ // BINARY FORMAT GEOMETRY
9
+
10
+ export type GeoColumnType = 'Point' | 'LineString' | 'Polygon';
11
+
12
+ /** A geometry column can be built from list of geometry column data chunks */
13
+ export type GeoColumn<MetadataT = Record<string, unknown>> = {
14
+ shape: 'geo-column';
15
+ metadata?: MetadataT;
16
+ data: GeoColumnData[];
17
+ };
18
+
19
+ export type GeoColumnData = GeoColumnPointData | GeoColumnLineData | GeoColumnPolygonData;
20
+
21
+ /**
22
+ * Describes a single contiguous chunk of geometries in binary columnar format
23
+ * Extracts the nested position and offset arrays from a GeoArrow column
24
+ * @note Designed to be a cheap operation: does not create any new arrays, just holds extracted references the existing arrays
25
+ */
26
+ export type GeoColumnCommonData = {
27
+ shape: 'geo-column-data';
28
+
29
+ /** Number of rows geometries (can be less than pointCount if representing multipoints) */
30
+ numRows: number;
31
+ /** Offset to the end of the next geometry (length = rowCount) */
32
+ rowOffsets: Uint32Array;
33
+
34
+ /** Number of positions */
35
+ numPositions: number;
36
+ /** Data for coordinates, either interleaved or separate arrays */
37
+ positions: GeoColumnPositions;
38
+
39
+ /** Stores the data for the respective geometry types */
40
+ // points?: GeoColumnPointData;
41
+ // lines?: GeoColumnLineData;
42
+ // polygons?: GeoColumnPolygonData;
43
+ };
44
+
45
+ /** Columnar point geometry: an array of positions */
46
+ export type GeoColumnPointData = GeoColumnCommonData & {
47
+ type: 'Point';
48
+ };
49
+
50
+ /** Columnar line geometry, array of positions and indices to the start of each line */
51
+ export type GeoColumnLineData = GeoColumnCommonData & {
52
+ type: 'LineString';
53
+
54
+ /** Offset to the next path within the multi feature */
55
+ pathOffsets: Uint32Array;
56
+ };
57
+
58
+ /** Columnar polygon geometry, an array of positions to each primitite polygon and polygon */
59
+ export type GeoColumnPolygonData = GeoColumnCommonData & {
60
+ type: 'Polygon';
61
+ /** Offset to next polygon */
62
+ polygonOffsets: Uint32Array;
63
+ /** Offset to next primitive polygon */
64
+ ringOffsets: Uint32Array;
65
+ };
66
+
67
+ export type GeoColumnPositions = GeoColumnInterleavedPositions | GeoColumnSeparatePositions;
68
+
69
+ /** Positions are in a single coordinate array */
70
+ export type GeoColumnInterleavedPositions = {
71
+ layout: 'interleaved';
72
+ /** Dimension, i.e. number of coordinates per position: 2, 3 or 4 */
73
+ stride: 2 | 3 | 4;
74
+ /** Flat array of position coordinates (length = positionCount * positionStride */
75
+ coordinates: TypedArray;
76
+ };
77
+
78
+ /** Positions are in separate coordinate arrays */
79
+ export type GeoColumnSeparatePositions = {
80
+ layout: 'separate';
81
+ /** Dimension, i.e. number of coordinates per position: 2, 3 or 4 */
82
+ stride: 2 | 3 | 4;
83
+ /** Flat array of position coordinates (length = positionCount * positionStride */
84
+ coordinates: TypedArray[];
85
+ };