@loaders.gl/schema 5.0.0-alpha.10 → 5.0.0-alpha.12
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/dist.dev.js +17 -4
- package/dist/dist.min.js +3 -3
- package/dist/geoarrow-metadata.schema.json +117 -0
- package/dist/geoparquet.schema.json +222 -0
- package/dist/geospatial-metadata-zod-schema.cjs +149 -0
- package/dist/geospatial-metadata-zod-schema.cjs.map +6 -0
- package/dist/geospatial-metadata-zod-schema.d.ts +44 -0
- package/dist/geospatial-metadata-zod-schema.d.ts.map +1 -0
- package/dist/geospatial-metadata-zod-schema.js +151 -0
- package/dist/geospatial-metadata-zod-schema.js.map +1 -0
- package/package.json +16 -7
- package/src/geospatial-metadata-zod-schema.ts +163 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {z} from 'zod';
|
|
6
|
+
import type {
|
|
7
|
+
GeoArrowMetadata,
|
|
8
|
+
GeoColumnMetadata,
|
|
9
|
+
GeoMetadata,
|
|
10
|
+
GeoParquetGeometryType
|
|
11
|
+
} from './geometry/geoarrow';
|
|
12
|
+
|
|
13
|
+
/** GeoParquet geometry type names, including optional Z dimensions. */
|
|
14
|
+
export const GeoParquetGeometryTypeSchema = z.enum([
|
|
15
|
+
'Point',
|
|
16
|
+
'LineString',
|
|
17
|
+
'Polygon',
|
|
18
|
+
'MultiPoint',
|
|
19
|
+
'MultiLineString',
|
|
20
|
+
'MultiPolygon',
|
|
21
|
+
'GeometryCollection',
|
|
22
|
+
'Point Z',
|
|
23
|
+
'LineString Z',
|
|
24
|
+
'Polygon Z',
|
|
25
|
+
'MultiPoint Z',
|
|
26
|
+
'MultiLineString Z',
|
|
27
|
+
'MultiPolygon Z',
|
|
28
|
+
'GeometryCollection Z',
|
|
29
|
+
'Point M',
|
|
30
|
+
'LineString M',
|
|
31
|
+
'Polygon M',
|
|
32
|
+
'MultiPoint M',
|
|
33
|
+
'MultiLineString M',
|
|
34
|
+
'MultiPolygon M',
|
|
35
|
+
'GeometryCollection M',
|
|
36
|
+
'Point ZM',
|
|
37
|
+
'LineString ZM',
|
|
38
|
+
'Polygon ZM',
|
|
39
|
+
'MultiPoint ZM',
|
|
40
|
+
'MultiLineString ZM',
|
|
41
|
+
'MultiPolygon ZM',
|
|
42
|
+
'GeometryCollection ZM'
|
|
43
|
+
]) satisfies z.ZodType<GeoParquetGeometryType>;
|
|
44
|
+
|
|
45
|
+
const GeoParquetGeometryTypesSchema = z
|
|
46
|
+
.array(GeoParquetGeometryTypeSchema)
|
|
47
|
+
.refine(geometryTypes => new Set(geometryTypes).size === geometryTypes.length, {
|
|
48
|
+
message: 'GeoParquet geometry_types entries must be unique'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const PROJJSONCRSSchema = z.record(z.string(), z.unknown());
|
|
52
|
+
|
|
53
|
+
/** Zod schema for metadata attached to one GeoParquet geometry column. */
|
|
54
|
+
export const GeoParquetColumnMetadataSchema = z
|
|
55
|
+
.object({
|
|
56
|
+
encoding: z.enum([
|
|
57
|
+
'WKB',
|
|
58
|
+
'wkb',
|
|
59
|
+
'GEOMETRY',
|
|
60
|
+
'geometry',
|
|
61
|
+
'GEOGRAPHY',
|
|
62
|
+
'geography',
|
|
63
|
+
'point',
|
|
64
|
+
'linestring',
|
|
65
|
+
'polygon',
|
|
66
|
+
'multipoint',
|
|
67
|
+
'multilinestring',
|
|
68
|
+
'multipolygon'
|
|
69
|
+
]),
|
|
70
|
+
geometry_types: GeoParquetGeometryTypesSchema,
|
|
71
|
+
crs: z.union([PROJJSONCRSSchema, z.null()]).optional(),
|
|
72
|
+
orientation: z.literal('counterclockwise').optional(),
|
|
73
|
+
bbox: z
|
|
74
|
+
.union([
|
|
75
|
+
z.tuple([z.number(), z.number(), z.number(), z.number()]),
|
|
76
|
+
z.tuple([z.number(), z.number(), z.number(), z.number(), z.number(), z.number()]),
|
|
77
|
+
z.tuple([
|
|
78
|
+
z.number(),
|
|
79
|
+
z.number(),
|
|
80
|
+
z.number(),
|
|
81
|
+
z.number(),
|
|
82
|
+
z.number(),
|
|
83
|
+
z.number(),
|
|
84
|
+
z.number(),
|
|
85
|
+
z.number()
|
|
86
|
+
])
|
|
87
|
+
])
|
|
88
|
+
.optional(),
|
|
89
|
+
edges: z.enum(['planar', 'spherical', 'vincenty', 'thomas', 'andoyer', 'karney']).optional(),
|
|
90
|
+
epoch: z.number().finite().optional()
|
|
91
|
+
})
|
|
92
|
+
.passthrough() as unknown as z.ZodType<GeoColumnMetadata>;
|
|
93
|
+
|
|
94
|
+
/** Zod schema for the GeoParquet metadata stored in a Parquet file's `geo` key. */
|
|
95
|
+
export const GeoParquetMetadataSchema = z
|
|
96
|
+
.object({
|
|
97
|
+
version: z.string().min(1),
|
|
98
|
+
primary_column: z.string().min(1),
|
|
99
|
+
columns: z.record(z.string(), GeoParquetColumnMetadataSchema)
|
|
100
|
+
})
|
|
101
|
+
.passthrough()
|
|
102
|
+
.refine(metadata => Boolean(metadata.columns[metadata.primary_column]), {
|
|
103
|
+
message: 'GeoParquet primary_column must name an entry in columns',
|
|
104
|
+
path: ['primary_column']
|
|
105
|
+
})
|
|
106
|
+
.superRefine((metadata, context) => {
|
|
107
|
+
if (!metadata.version.startsWith('2.')) return;
|
|
108
|
+
for (const [columnName, column] of Object.entries(metadata.columns)) {
|
|
109
|
+
const encoding = column.encoding.toUpperCase();
|
|
110
|
+
if (encoding !== 'WKB' && encoding !== 'GEOMETRY' && encoding !== 'GEOGRAPHY') {
|
|
111
|
+
context.addIssue({
|
|
112
|
+
code: 'custom',
|
|
113
|
+
message: 'GeoParquet 2.x geometry columns must use WKB, GEOMETRY, or GEOGRAPHY encoding',
|
|
114
|
+
path: ['columns', columnName, 'encoding']
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}) satisfies z.ZodType<GeoMetadata>;
|
|
119
|
+
|
|
120
|
+
/** Zod schema for metadata stored on one GeoArrow extension field. */
|
|
121
|
+
export const GeoArrowMetadataSchema = z
|
|
122
|
+
.object({
|
|
123
|
+
encoding: z
|
|
124
|
+
.enum([
|
|
125
|
+
'geoarrow.geometry',
|
|
126
|
+
'geoarrow.geometrycollection',
|
|
127
|
+
'geoarrow.multipolygon',
|
|
128
|
+
'geoarrow.polygon',
|
|
129
|
+
'geoarrow.multilinestring',
|
|
130
|
+
'geoarrow.linestring',
|
|
131
|
+
'geoarrow.multipoint',
|
|
132
|
+
'geoarrow.point',
|
|
133
|
+
'geoarrow.box',
|
|
134
|
+
'geoarrow.wkb',
|
|
135
|
+
'geoarrow.wkt'
|
|
136
|
+
])
|
|
137
|
+
.optional(),
|
|
138
|
+
crs: z.union([PROJJSONCRSSchema, z.string()]).optional(),
|
|
139
|
+
crs_type: z.enum(['projjson', 'wkt2:2019', 'authority_code', 'srid']).optional(),
|
|
140
|
+
edges: z.enum(['spherical', 'vincenty', 'thomas', 'andoyer', 'karney']).optional(),
|
|
141
|
+
geometry_types: GeoParquetGeometryTypesSchema.optional()
|
|
142
|
+
})
|
|
143
|
+
.passthrough()
|
|
144
|
+
.superRefine((metadata, context) => {
|
|
145
|
+
const {crs, crs_type: crsType} = metadata;
|
|
146
|
+
const valid =
|
|
147
|
+
(crs === undefined && crsType === undefined) ||
|
|
148
|
+
(typeof crs === 'object' &&
|
|
149
|
+
crs !== null &&
|
|
150
|
+
(crsType === undefined || crsType === 'projjson')) ||
|
|
151
|
+
(typeof crs === 'string' &&
|
|
152
|
+
(crsType === undefined ||
|
|
153
|
+
crsType === 'wkt2:2019' ||
|
|
154
|
+
crsType === 'authority_code' ||
|
|
155
|
+
crsType === 'srid'));
|
|
156
|
+
if (!valid) {
|
|
157
|
+
context.addIssue({
|
|
158
|
+
code: 'custom',
|
|
159
|
+
message: 'GeoArrow crs and crs_type must describe the same CRS representation',
|
|
160
|
+
path: ['crs_type']
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}) as z.ZodType<GeoArrowMetadata>;
|