GeoJSONWriter
Streaming writer for GeoJSON encoded files.
| Loader | Characteristic |
|---|---|
| File Extension | .geojson |
| Media Type | application/geo+json |
| File Type | Text |
| File Format | GeoJSON |
| Data Format | Classic Table |
| Supported APIs | encode, encodeSync, encodeÓInBatches |
Usage​
For simple usage, you can encode a table into a JSON "file" atomically:
import {GeoJSONWriter} from '@loaders.gl/json';
import {encode} from '@loaders.gl/core';
const data = await encode(url, GeoJSONWriter, {json: options});
Streaming and JSON paths​
For larger files, GeoJSONWriter supports streaming JSON parsing, in which case it will yield "batches" of rows from one array.
import {GeoJSONWriter} from '@loaders.gl/json';
import {encodeInBatches} from '@loaders.gl/core';
const batches = await encodeInBatches('geojson.json', GeoJSONWriter, {json: {jsonpaths: ['$.features']}});
for await (const batch of batches) {
// batch.data will contain a number of rows
for (const feature of batch.data) {
switch (feature.geometry.type) {
case 'Polygon':
...
}
}
}
To parse a stream of GeoJSON, the user can specify the options.json.jsonpaths to stream the features array.
If no JSONPath is specified the loader will stream the first array it encounters in the JSON payload.
Data Format​
Encoded batches are array buffers or strings
Options​
Supports table category options such as batchType and batchSize.
| Option | From | Type | Default | Description |
|---|---|---|---|---|
json.table | [ | boolean | false | Parses non-streaming JSON as table, i.e. return the first embedded array in the JSON. Always true during batched/streaming parsing. |
json.jsonpaths | [ | string[] | [] | A list of JSON paths (see below) indicating the array that can be streamed. |
JSONPaths​
The loader implements a focused subset of the IETF JSONPath specification (RFC 9535). See the JSONPath support table for the full list of supported and unsupported features.
JSONPaths are used only to identify which array should be streamed, so selectors such as $.features[*] and $.features[:] are normalized to $.features. Descendant operators, element indexes, filters, and unions are not supported. Regardless of the paths provided, only arrays will be streamed.
Attribution​
This loader is based on a fork of dscape's clarinet under BSD 2-clause license.