What it writes
Send table data back to the map as features.
GeoJSONWriter converts table-shaped geospatial data into a FeatureCollection or feature stream, with an incremental path for larger outputs.
Input
GeoJSON tables and geometry columns
Output
GeoJSON features and collections
Streaming
Incremental feature batches
Boundary
Readable web and GIS interchange
Detailed guide
GeoJSONWriter reference
The sections below document format metadata, usage, streaming, output shapes, and writer options.
Streaming writer for GeoJSON encoded files.
| GeoJSONWriter | |
|---|---|
| File Extension | .geojson |
| Media Type | application/geo+json |
| File Type | Text |
| File Format | GeoJSON |
| Data Format | Classic Table |
| Supported APIs | encode, encodeInBatches |
Usage
Encode a loaders.gl table containing geometry into a GeoJSON FeatureCollection. For example, an object-row table can contain WKT geometry strings in a named column:
import {GeoJSONWriter} from '@loaders.gl/tables/geojson';
import {encode} from '@loaders.gl/core';
const table = {
shape: 'object-row-table',
schema: {
fields: [{name: 'geometry', type: 'utf8'}, {name: 'name', type: 'utf8'}],
metadata: {}
},
data: [{geometry: 'POINT (1 2)', name: 'Example'}]
};
const bytes = await encode(table, GeoJSONWriter);
const text = new TextDecoder().decode(bytes);
Streaming output
Pass an iterable of table batches to encodeInBatches. Each output chunk is
an ArrayBuffer containing UTF-8 text; join chunks in order to form the complete
GeoJSON document. Output chunks are not parsed feature batches.
import {GeoJSONWriter} from '@loaders.gl/tables/geojson';
import {encodeInBatches} from '@loaders.gl/core';
const chunks = await encodeInBatches(tableBatches, GeoJSONWriter);
for await (const bytes of chunks) {
// Forward each encoded chunk to the application's output stream.
await output.write(bytes);
}
Options
| Option | Default | Description |
|---|---|---|
geojson.featureArray | false | Writes a feature array instead of a FeatureCollection wrapper. |
geojson.geometryColumn | null | Index of the geometry column; inferred when omitted. |
chunkSize | 10000 | Target encoded chunk size in bytes. |
GeoJSONWriter supports asynchronous encode and encodeInBatches. It does
not provide encodeSync. JSONPath options belong to JSON parsing and are not
writer options.