@loaders.gl/parquet 4.0.0 → 4.0.2

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 (53) hide show
  1. package/dist/index.cjs +10 -205
  2. package/dist/index.d.ts +0 -3
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +0 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/parsers/get-parquet-schema.js +1 -1
  7. package/dist/lib/parsers/get-parquet-schema.js.map +1 -1
  8. package/dist/lib/parsers/parse-parquet-to-rows.d.ts.map +1 -1
  9. package/dist/lib/parsers/parse-parquet-to-rows.js +3 -2
  10. package/dist/lib/parsers/parse-parquet-to-rows.js.map +1 -1
  11. package/dist/lib/wasm/encode-parquet-wasm.d.ts +7 -8
  12. package/dist/lib/wasm/encode-parquet-wasm.d.ts.map +1 -1
  13. package/dist/lib/wasm/encode-parquet-wasm.js +2 -2
  14. package/dist/lib/wasm/encode-parquet-wasm.js.map +1 -1
  15. package/dist/lib/wasm/parse-parquet-wasm.d.ts +2 -2
  16. package/dist/lib/wasm/parse-parquet-wasm.d.ts.map +1 -1
  17. package/dist/lib/wasm/parse-parquet-wasm.js +3 -3
  18. package/dist/lib/wasm/parse-parquet-wasm.js.map +1 -1
  19. package/dist/parquet-wasm-loader.d.ts +2 -2
  20. package/dist/parquet-wasm-loader.d.ts.map +1 -1
  21. package/dist/parquet-wasm-loader.js.map +1 -1
  22. package/dist/parquet-wasm-writer.d.ts +2 -2
  23. package/dist/parquet-wasm-writer.d.ts.map +1 -1
  24. package/dist/parquet-wasm-writer.js.map +1 -1
  25. package/dist/parquet-writer.d.ts.map +1 -1
  26. package/dist/parquet-writer.js +3 -2
  27. package/dist/parquet-writer.js.map +1 -1
  28. package/package.json +8 -8
  29. package/src/index.ts +2 -10
  30. package/src/lib/parsers/get-parquet-schema.ts +1 -1
  31. package/src/lib/parsers/parse-parquet-to-rows.ts +4 -2
  32. package/src/lib/wasm/encode-parquet-wasm.ts +11 -10
  33. package/src/lib/wasm/parse-parquet-wasm.ts +6 -7
  34. package/src/parquet-wasm-loader.ts +2 -2
  35. package/src/parquet-wasm-writer.ts +2 -2
  36. package/src/parquet-writer.ts +3 -2
  37. package/dist/lib/geo/decode-geo-column.d.ts +0 -4
  38. package/dist/lib/geo/decode-geo-column.d.ts.map +0 -1
  39. package/dist/lib/geo/decode-geo-column.js +0 -47
  40. package/dist/lib/geo/decode-geo-column.js.map +0 -1
  41. package/dist/lib/geo/decode-geo-metadata.d.ts +0 -44
  42. package/dist/lib/geo/decode-geo-metadata.d.ts.map +0 -1
  43. package/dist/lib/geo/decode-geo-metadata.js +0 -89
  44. package/dist/lib/geo/decode-geo-metadata.js.map +0 -1
  45. package/dist/lib/geo/geoparquet-metadata-schema.d.ts +0 -79
  46. package/dist/lib/geo/geoparquet-metadata-schema.d.ts.map +0 -1
  47. package/dist/lib/geo/geoparquet-metadata-schema.js +0 -76
  48. package/dist/lib/geo/geoparquet-metadata-schema.js.map +0 -1
  49. package/dist/lib/geo/geoparquet-metadata-schema.json +0 -60
  50. package/src/lib/geo/decode-geo-column.ts +0 -55
  51. package/src/lib/geo/decode-geo-metadata.ts +0 -177
  52. package/src/lib/geo/geoparquet-metadata-schema.json +0 -60
  53. package/src/lib/geo/geoparquet-metadata-schema.ts +0 -70
@@ -1,60 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "title": "GeoParquet",
4
- "description": "Parquet metadata included in the geo field.",
5
- "type": "object",
6
- "required": ["version", "primary_column", "columns"],
7
- "properties": {
8
- "version": {"type": "string", "const": "1.0.0-beta.1"},
9
- "primary_column": {"type": "string", "minLength": 1},
10
- "columns": {
11
- "type": "object",
12
- "minProperties": 1,
13
- "patternProperties": {
14
- ".+": {
15
- "type": "object",
16
- "required": ["encoding", "geometry_types"],
17
- "properties": {
18
- "encoding": {"type": "string", "const": "WKB"},
19
- "geometry_types": {
20
- "type": "array",
21
- "uniqueItems": true,
22
- "items": {
23
- "type": "string",
24
- "pattern": "^(GeometryCollection|(Multi)?(Point|LineString|Polygon))( Z)?$"
25
- }
26
- },
27
- "crs": {
28
- "oneOf": [
29
- {
30
- "$ref": "https://proj.org/schemas/v0.5/projjson.schema.json"
31
- },
32
- {"type": "null"}
33
- ]
34
- },
35
- "edges": {"type": "string", "enum": ["planar", "spherical"]},
36
- "orientation": {"type": "string", "const": "counterclockwise"},
37
- "bbox": {
38
- "type": "array",
39
- "items": {"type": "number"},
40
- "oneOf": [
41
- {
42
- "description": "2D bbox consisting of (xmin, ymin, xmax, ymax)",
43
- "minItems": 4,
44
- "maxItems": 4
45
- },
46
- {
47
- "description": "3D bbox consisting of (xmin, ymin, zmin, xmax, ymax, zmax)",
48
- "minItems": 6,
49
- "maxItems": 6
50
- }
51
- ]
52
- },
53
- "epoch": {"type": "number"}
54
- }
55
- }
56
- },
57
- "additionalProperties": false
58
- }
59
- }
60
- }
@@ -1,55 +0,0 @@
1
- // loaders.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- import type {ArrayRowTable, GeoJSONTable, ObjectRowTable, Schema} from '@loaders.gl/schema';
5
- import type {Feature, Geometry} from '@loaders.gl/schema';
6
- import {getTableLength, getTableRowAsObject} from '@loaders.gl/schema';
7
- // import {binaryToGeometry} from '@loaders.gl/gis';
8
- import {WKBLoader, WKTLoader} from '@loaders.gl/wkt';
9
-
10
- import {GeoColumnMetadata, getGeoMetadata} from './decode-geo-metadata';
11
-
12
- /** TODO - move to loaders.gl/gis? */
13
- export function convertWKBTableToGeoJSON(
14
- table: ArrayRowTable | ObjectRowTable,
15
- schema: Schema
16
- ): GeoJSONTable {
17
- const geoMetadata = getGeoMetadata(schema);
18
- const primaryColumn = geoMetadata?.primary_column;
19
- if (!primaryColumn) {
20
- throw new Error('no geometry column');
21
- }
22
- const columnMetadata = geoMetadata.columns[primaryColumn];
23
-
24
- const features: Feature[] = [];
25
-
26
- const length = getTableLength(table);
27
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
28
- const row = getTableRowAsObject(table, rowIndex);
29
- const geometry = parseGeometry(row[primaryColumn], columnMetadata);
30
- delete row[primaryColumn];
31
- const feature: Feature = {type: 'Feature', geometry: geometry!, properties: row};
32
- features.push(feature);
33
- }
34
-
35
- return {shape: 'geojson-table', schema, type: 'FeatureCollection', features};
36
- }
37
-
38
- function parseGeometry(geometry: unknown, columnMetadata: GeoColumnMetadata): Geometry | null {
39
- switch (columnMetadata.encoding) {
40
- case 'wkt':
41
- return WKTLoader.parseTextSync?.(geometry as string) || null;
42
- case 'wkb':
43
- default:
44
- const arrayBuffer = ArrayBuffer.isView(geometry)
45
- ? geometry.buffer.slice(geometry.byteOffset, geometry.byteOffset + geometry.byteLength)
46
- : (geometry as ArrayBuffer);
47
- const geojson = WKBLoader.parseSync?.(arrayBuffer, {
48
- wkb: {shape: 'geometry'}
49
- }) as unknown as Geometry;
50
- return geojson; // binaryGeometry ? binaryToGeometry(binaryGeometry) : null;
51
- // const binaryGeometry = WKBLoader.parseSync?.(geometry);
52
- // ts-ignore
53
- // return binaryGeometry ? binaryToGeometry(binaryGeometry) : null;
54
- }
55
- }
@@ -1,177 +0,0 @@
1
- // loaders.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
- import {Schema, Field} from '@loaders.gl/schema';
4
-
5
- /* eslint-disable camelcase */
6
-
7
- type GeometryType =
8
- | 'Point'
9
- | 'LineString'
10
- | 'Polygon'
11
- | 'MultiPoint'
12
- | 'MultiLineString'
13
- | 'MultiPolygon'
14
- | 'GeometryCollection'
15
- | 'Point Z'
16
- | 'LineString Z'
17
- | 'Polygon Z'
18
- | 'MultiPoint Z'
19
- | 'MultiLineString Z'
20
- | 'MultiPolygon Z'
21
- | 'GeometryCollection Z';
22
-
23
- /**
24
- * A geoarrow / geoparquet geo metadata object
25
- * (stored in stringified form in the top level metadata 'geo' key)
26
- * @see https://github.com/opengeospatial/geoparquet/blob/main/format-specs/geoparquet.md
27
- * @see https://github.com/geoarrow/geoarrow/blob/main/metadata.md
28
- * */
29
- export type GeoMetadata = {
30
- version?: string;
31
- primary_column?: string;
32
- columns: Record<string, GeoColumnMetadata>;
33
- [key: string]: unknown;
34
- };
35
-
36
- /** A geoarrow / geoparquet geo metadata for one geometry column */
37
- export type GeoColumnMetadata = {
38
- encoding: 'wkb' | 'wkt';
39
- geometry_types: GeometryType[];
40
- crs?: object | null;
41
- orientation?: 'counterclockwise';
42
- bbox?: [number, number, number, number] | [number, number, number, number, number, number];
43
- edges?: 'planar' | 'spherical';
44
- epoch?: number;
45
- [key: string]: unknown;
46
- };
47
-
48
- /** Parse a key with stringified arrow metadata */
49
- export function parseJSONStringMetadata(
50
- schema: Schema,
51
- metadataKey: string
52
- ): Record<string, unknown> | null {
53
- const stringifiedMetadata = schema.metadata[metadataKey];
54
- if (!stringifiedMetadata) {
55
- return null;
56
- }
57
-
58
- try {
59
- const metadata = JSON.parse(stringifiedMetadata);
60
- if (!metadata || typeof metadata !== 'object') {
61
- return null;
62
- }
63
- return metadata;
64
- } catch {
65
- return null;
66
- }
67
- }
68
-
69
- export function unpackJSONStringMetadata(schema: Schema, metadataKey: string): void {
70
- const json = parseJSONStringMetadata(schema, metadataKey);
71
- for (const [key, value] of Object.entries(json || {})) {
72
- schema.metadata[`${metadataKey}.${key}`] =
73
- typeof value === 'string' ? value : JSON.stringify(value);
74
- }
75
- }
76
-
77
- // GEO METADATA
78
-
79
- /**
80
- * Reads the GeoMetadata object from the metadata
81
- * @note geoarrow / parquet schema is stringified into a single key-value pair in the parquet metadata */
82
- export function getGeoMetadata(schema: Schema): GeoMetadata | null {
83
- const geoMetadata = parseJSONStringMetadata(schema, 'geo') as GeoMetadata;
84
- return geoMetadata;
85
- }
86
-
87
- /**
88
- * Stores a geoarrow / geoparquet geo metadata object in the schema
89
- * @note geoarrow / geoparquet geo metadata is a single stringified JSON field
90
- */
91
- export function setGeoMetadata(schema: Schema, geoMetadata: GeoMetadata): void {
92
- const stringifiedGeoMetadata = JSON.stringify(geoMetadata);
93
- schema.metadata.geo = stringifiedGeoMetadata;
94
- }
95
-
96
- /**
97
- * Unpacks geo metadata into separate metadata fields (parses the long JSON string)
98
- * @note geoarrow / parquet schema is stringified into a single key-value pair in the parquet metadata
99
- */
100
- export function unpackGeoMetadata(schema: Schema): void {
101
- const geoMetadata = getGeoMetadata(schema);
102
- if (!geoMetadata) {
103
- return;
104
- }
105
-
106
- // Store Parquet Schema Level Metadata
107
-
108
- const {version, primary_column, columns} = geoMetadata;
109
- if (version) {
110
- schema.metadata['geo.version'] = version;
111
- }
112
-
113
- if (primary_column) {
114
- schema.metadata['geo.primary_column'] = primary_column;
115
- }
116
-
117
- // store column names as comma separated list
118
- schema.metadata['geo.columns'] = Object.keys(columns || {}).join('');
119
-
120
- for (const [columnName, columnMetadata] of Object.entries(columns || {})) {
121
- const field = schema.fields.find((field) => field.name === columnName);
122
- if (field) {
123
- if (field.name === primary_column) {
124
- setFieldMetadata(field, 'geo.primary_field', 'true');
125
- }
126
- unpackGeoFieldMetadata(field, columnMetadata);
127
- }
128
- }
129
- }
130
-
131
- // eslint-disable-next-line complexity
132
- function unpackGeoFieldMetadata(field: Field, columnMetadata): void {
133
- for (const [key, value] of Object.entries(columnMetadata || {})) {
134
- switch (key) {
135
- case 'geometry_type':
136
- setFieldMetadata(field, `geo.${key}`, (value as string[]).join(','));
137
- break;
138
- case 'bbox':
139
- setFieldMetadata(field, `geo.crs.${key}`, JSON.stringify(value));
140
- break;
141
- case 'crs':
142
- // @ts-ignore
143
- for (const [crsKey, crsValue] of Object.entries(value || {})) {
144
- switch (crsKey) {
145
- case 'id':
146
- const crsId =
147
- typeof crsValue === 'object'
148
- ? // @ts-ignore
149
- `${crsValue?.authority}:${crsValue?.code}`
150
- : JSON.stringify(crsValue);
151
- setFieldMetadata(field, `geo.crs.${crsKey}`, crsId);
152
- break;
153
- default:
154
- setFieldMetadata(
155
- field,
156
- `geo.crs.${crsKey}`,
157
- typeof crsValue === 'string' ? crsValue : JSON.stringify(crsValue)
158
- );
159
- break;
160
- }
161
- }
162
- break;
163
- case 'edges':
164
- default:
165
- setFieldMetadata(
166
- field,
167
- `geo.${key}`,
168
- typeof value === 'string' ? value : JSON.stringify(value)
169
- );
170
- }
171
- }
172
- }
173
-
174
- function setFieldMetadata(field: Field, key: string, value: string): void {
175
- field.metadata = field.metadata || {};
176
- field.metadata[key] = value;
177
- }
@@ -1,60 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "title": "GeoParquet",
4
- "description": "Parquet metadata included in the geo field.",
5
- "type": "object",
6
- "required": ["version", "primary_column", "columns"],
7
- "properties": {
8
- "version": {"type": "string", "const": "1.0.0-beta.1"},
9
- "primary_column": {"type": "string", "minLength": 1},
10
- "columns": {
11
- "type": "object",
12
- "minProperties": 1,
13
- "patternProperties": {
14
- ".+": {
15
- "type": "object",
16
- "required": ["encoding", "geometry_types"],
17
- "properties": {
18
- "encoding": {"type": "string", "const": "WKB"},
19
- "geometry_types": {
20
- "type": "array",
21
- "uniqueItems": true,
22
- "items": {
23
- "type": "string",
24
- "pattern": "^(GeometryCollection|(Multi)?(Point|LineString|Polygon))( Z)?$"
25
- }
26
- },
27
- "crs": {
28
- "oneOf": [
29
- {
30
- "$ref": "https://proj.org/schemas/v0.5/projjson.schema.json"
31
- },
32
- {"type": "null"}
33
- ]
34
- },
35
- "edges": {"type": "string", "enum": ["planar", "spherical"]},
36
- "orientation": {"type": "string", "const": "counterclockwise"},
37
- "bbox": {
38
- "type": "array",
39
- "items": {"type": "number"},
40
- "oneOf": [
41
- {
42
- "description": "2D bbox consisting of (xmin, ymin, xmax, ymax)",
43
- "minItems": 4,
44
- "maxItems": 4
45
- },
46
- {
47
- "description": "3D bbox consisting of (xmin, ymin, zmin, xmax, ymax, zmax)",
48
- "minItems": 6,
49
- "maxItems": 6
50
- }
51
- ]
52
- },
53
- "epoch": {"type": "number"}
54
- }
55
- }
56
- },
57
- "additionalProperties": false
58
- }
59
- }
60
- }
@@ -1,70 +0,0 @@
1
- // loaders.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- /* eslint-disable camelcase */
5
-
6
- /**
7
- * Geoparquet JSON schema for geo metadata
8
- * @see https://github.com/geoarrow/geoarrow/blob/main/metadata.md
9
- * @see https://github.com/opengeospatial/geoparquet/blob/main/format-specs/geoparquet.md
10
- */
11
- export const GEOPARQUET_METADATA_JSON_SCHEMA = {
12
- $schema: 'http://json-schema.org/draft-07/schema#',
13
- title: 'GeoParquet',
14
- description: 'Parquet metadata included in the geo field.',
15
- type: 'object',
16
- required: ['version', 'primary_column', 'columns'],
17
- properties: {
18
- version: {type: 'string', const: '1.0.0-beta.1'},
19
- primary_column: {type: 'string', minLength: 1},
20
- columns: {
21
- type: 'object',
22
- minProperties: 1,
23
- patternProperties: {
24
- '.+': {
25
- type: 'object',
26
- required: ['encoding', 'geometry_types'],
27
- properties: {
28
- encoding: {type: 'string', const: 'WKB'},
29
- geometry_types: {
30
- type: 'array',
31
- uniqueItems: true,
32
- items: {
33
- type: 'string',
34
- pattern: '^(GeometryCollection|(Multi)?(Point|LineString|Polygon))( Z)?$'
35
- }
36
- },
37
- crs: {
38
- oneOf: [
39
- {
40
- $ref: 'https://proj.org/schemas/v0.5/projjson.schema.json'
41
- },
42
- {type: 'null'}
43
- ]
44
- },
45
- edges: {type: 'string', enum: ['planar', 'spherical']},
46
- orientation: {type: 'string', const: 'counterclockwise'},
47
- bbox: {
48
- type: 'array',
49
- items: {type: 'number'},
50
- oneOf: [
51
- {
52
- description: '2D bbox consisting of (xmin, ymin, xmax, ymax)',
53
- minItems: 4,
54
- maxItems: 4
55
- },
56
- {
57
- description: '3D bbox consisting of (xmin, ymin, zmin, xmax, ymax, zmax)',
58
- minItems: 6,
59
- maxItems: 6
60
- }
61
- ]
62
- },
63
- epoch: {type: 'number'}
64
- }
65
- }
66
- },
67
- additionalProperties: false
68
- }
69
- }
70
- };