/shapefile

A streaming parser for the ESRI Shapefile spatial data format.

Primary LanguageJavaScriptOtherNOASSERTION

Streaming Shapefile Parser

Based on the ESRI Shapefile Technical Description and dBASE Table File Format.

Caveat emptor: this library is a work in progress and does not currently support all shapefile geometry types (see shp.js for details). It also only supports dBASE III and has no error checking. Please contribute if you want to help!

Reading a Shapefile

The main API for reading a shapefile is shapefile.readStream. This returns an event emitter which emits three types of events:

  • feature - while reading features from the shapefile
  • end - when all features have been read
  • error - if an error occurs

Features are emitted as GeoJSON features, not as shapefile primitives. That’s because GeoJSON objects are the standard representation of geometry in JavaScript, and they are convenient. If you want to access the shapefile primitives directly, use the private shp and dbf classes instead.

See index-test for an example converting a shapefile to a GeoJSON feature collection.