shapefile.md

February 10, 2026 ยท View on GitHub

ShapeFile Reader

shapefile-file-ts shapefile-gzip-ts shapefile-brotli-ts

Description

Reads data from an esri Shapefile.

Implements the FeatureIterator interface which means you can use it in a for await loop for all the resulting Vector Features.

Usage

Be sure to checkout the Reader page for more knowledge on how to input data into the ShapefileReader.

Just to show how the ShapefileReader works, here is a basic example:

import { ShapeFileReader, DataBaseFile, Transformer } from 'gis-tools-ts';
import { FileReader } from 'gis-tools-ts/file';
// or use the MMapReader if using Bun:
// import { MMapReader } from 'gis-tools-ts/mmap';

const transform = new Transformer();
const dbf = new DataBaseFile(new FileReader('./data.dbf'), 'utf-8');
const reader = new ShapeFileReader(new FileReader('./data.shp'), dbf, transform);

// read all the features
for await (const feature of reader) {
  console.log(feature);
}

Browser or Locally

import {
  shapefileFromGzip,
  shapefileFromURL,
  LambertConformalConic,
  EPSG_9974,
} from 'gis-tools-ts';

// From a URL:
const reader = await shapefileFromURL('https://example.com/data.zip', [LambertConformalConic], {
  EPSG_9974,
});
// OR from raw ArrayBuffer from a gzip file
const reader = await shapefileFromGzip(arrayBufferInput, [LambertConformalConic], { EPSG_9974 });

for await (const feature of reader) {
  console.log(feature);
}

Filesystem specific usage

Given an input path to all the relavant files, build a Shapefile

import { LambertConformalConic, EPSG_9974 } from 'gis-tools-ts';
import { shapefileFromPath } from 'gis-tools-ts/file'; // or 'gis-tools-ts/mmap' if you are using Bun

const reader = await shapefileFromPath('path/to/files', [LambertConformalConic], { EPSG_9974 });

for await (const feature of reader) {
  console.log(feature);
}

Or build from a Definition object

import { LambertConformalConic, EPSG_9974 } from 'gis-tools-ts';
import { shapefileFromDefinition } from 'gis-tools-ts/file'; // Or 'gis-tools-ts/mmap' if you are using Bun
import type { Definition } from 'gis-tools-ts';

const def: Definition = {
  shp: 'path/to/file.shp',
  dbf: 'path/to/file.dbf',
  prj: 'path/to/file.prj',
  cpg: 'path/to/file.cpg',
};

const reader = await shapefileFromDefinition(def, [LambertConformalConic], { EPSG_9974 });

for await (const feature of reader) {
  console.log(feature);
}