Skip to main content

Shapefile module · loader API

ShapefileLoader

Load a Shapefile dataset as one geospatial table, coordinating its geometry, attributes, index, projection, and optional text-encoding sidecars.

What it assembles

Treat the sidecars as one dataset.

ShapefileLoader joins geometry and attributes, then carries projection and encoding information through the result so applications do not have to coordinate the files themselves.

Geometry

SHP records and multipart shapes

Attributes

DBF fields and text encoding

Metadata

SHX index and PRJ coordinate system

Output

Legacy, GeoJSON, or Arrow table shapes

Detailed guide

ShapefileLoader reference

The sections below document usage, output shapes, options, and the structure of the assembled result.

The ShapefileLoader parses Shapefile datasets into loaders.gl geometry tables.

Usage​

import {ShapefileLoader} from '@loaders.gl/geospatial/shapefile';
import {load} from '@loaders.gl/core';

const table = await load(url, ShapefileLoader);
const legacy = await load(url, ShapefileLoader, {shapefile: {shape: 'v3'}});

Shapes​

ShapefileLoader returns an Apache Arrow table with GeoArrow-compatible geometry by default. Set shapefile.shape: 'v3' or shapefile.shape: 'geojson-table' for legacy representations.

ShapeOutput
v3legacy Shapefile output object
geojson-tableloaders.gl GeoJSON table
arrowApache Arrow Table with WKB or typed GeoArrow geometry

Options​

OptionTypeDefaultDescription
shapefile.shapeString'arrow'Output shape: 'arrow', 'v3', or 'geojson-table'.
shapefile.geoarrowEncodingString'geoarrow.wkb'Arrow geometry encoding when shapefile.shape is 'arrow': 'geoarrow.wkb' or 'geoarrow'. 'geoarrow' infers a geometry-specific GeoArrow encoding from the SHP header.
shp._maxDimensionsInteger4Shapefiles can hold up to 4 dimensions (XYZM). By default all dimensions are parsed; when set to 2 only the X and Y dimensions are parsed. Note that for some Shapefiles, the third dimension is M, not Z. header.type in the output designates the stored dimensions.
gis.reprojectbooleanfalseOpt-in coordinate transformation; missing source CRS or unsupported transformations throw CRSReprojectionError.
gis.targetCrsCRSDefinition'WGS84' when reprojection is enabledOutput CRS for transformed coordinates.

Output​

The default ShapefileLoader output is an Apache Arrow Table whose property columns come from DBF and whose geometry column uses WKB or typed GeoArrow encoding. The table schema carries geospatial metadata and preserves the projection used for reprojection. When shapefile.shape: 'v3' is selected, the legacy output below is returned instead. Consult the Shapefile specification for the meaning of the numeric types.

{
encoding: 'ISO-8859-1',
prj: null,
shx: {
offsets: Int32Array(8) [
50, 0, 0, 0,
0, 0, 0, 0
],
lengths: Int32Array(8) [
14, 0, 0, 0,
0, 0, 0, 0
]
},
header: {
magic: 9994,
length: 136,
version: 1000,
type: 11,
bbox: {
minX: 1,
minY: 2,
minZ: 3,
minM: 0,
maxX: 1,
maxY: 2,
maxZ: 3,
maxM: 0
}
},
data: [ { type: 'Feature', geometry: [Object], properties: [Object] } ]
}

Worker batches​

ShapefileLoader supports browser worker parsing and loadInBatches / parseInBatches. The worker joins streamed SHP geometry with DBF attributes and fetches available .shx, .cpg, and .prj sidecars using the source URL. Request options in core.fetch are forwarded to those requests. An application-supplied fetch function keeps parsing on the caller.

Worker results use owned Arrow column buffers. Requests for geojson-table or v3 use WKB geometry columns in transit; feature and property objects are constructed only on the caller. Reprojection still runs during geometry decoding. Typed GeoArrow output retains its existing atomic-only restriction; batched Arrow output uses WKB geometry. No Arrow IPC is used.

Set core.worker: true to enable workers and core.worker: false to use the main thread. An abort signal or iterator closure releases the worker; already transferred input buffers remain detached. These prebuilt bundles target browser workers.