{"name":"shapefile","version":"0.0.11","description":"An implementation of the shapefile (.shp) spatial data format.","keywords":["geojson","shapefile"],"author":{"name":"Mike Bostock","url":"http://bost.ocks.org/mike"},"repository":{"type":"git","url":"http://github.com/mbostock/shapefile.git"},"main":"./index.js","dependencies":{"iconv-lite":"0.2.x"},"devDependencies":{"vows":"0.7.x"},"bin":{"dbfcat":"./bin/dbfcat","shpcat":"./bin/shpcat","shp2json":"./bin/shp2json"},"_id":"shapefile@0.0.11","dist":{"shasum":"376a8ae46091bf0593ab868c68430ef68fce98c8","tarball":"http://registry-npm.ywwl.com/shapefile/download/shapefile-0.0.11.tgz","integrity":"sha512-M43rDXZINJ+mFrw9sA1YuUqORNd1BWXXZAI8Jd5LhY6mBH4qLci00gnDhLEeTTuu/AZ3GXE18rIY+y5d24QwEA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZANG6MWEMnjtwyjITQRRAOF8bGtQkMjxld7Slrny2JAIgVvkVRqUYwqfnQtY1W4UafMu6VYyVndG5zKRcQYPSg2o="}],"size":10657,"noattachment":false,"key":"/shapefile/-/shapefile-0.0.11.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"mbostock","email":"mbostock@gmail.com"},"maintainers":[{"name":"mbostock","email":"mbostock@gmail.com"}],"directories":{},"readme":"# Streaming Shapefile Parser\n\nIn Node:\n\n```js\nvar shapefile = require(\"shapefile\");\n\nshapefile.open(\"example.shp\")\n  .then(source => source.read()\n    .then(function log(result) {\n      if (result.done) return;\n      console.log(result.value);\n      return source.read().then(log);\n    }))\n  .catch(error => console.error(error.stack));\n```\n\nIn a browser:\n\n```html\n<!DOCTYPE html>\n<script src=\"https://unpkg.com/shapefile@0.6\"></script>\n<script>\n\nshapefile.open(\"https://cdn.rawgit.com/mbostock/shapefile/master/test/points.shp\")\n  .then(source => source.read()\n    .then(function log(result) {\n      if (result.done) return;\n      console.log(result.value);\n      return source.read().then(log);\n    }))\n  .catch(error => console.error(error.stack));\n\n</script>\n```\n\nIn a terminal:\n\n```\nshp2json example.shp\n```\n\nFor a live example, see [bl.ocks.org/2dd741099154a4da55a7db31fd96a892](http://bl.ocks.org/mbostock/2dd741099154a4da55a7db31fd96a892). See also [ndjson-cli](https://github.com/mbostock/ndjson-cli) for examples of manipulating GeoJSON using newline-delimited JSON streams. See [Command-Line Cartography](https://medium.com/@mbostock/command-line-cartography-part-1-897aa8f8ca2c) for a longer introduction.\n\nThis parser implementation is based on the [ESRI Shapefile Technical Description](http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf), [dBASE Table for ESRI Shapefile (DBF)](http://www.digitalpreservation.gov/formats/fdd/fdd000326.shtml) and [Data File Header Structure for the\ndBASE Version 7 Table File](http://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm). Caveat emptor: this is a work in progress and does not currently support all shapefile geometry types. It only supports dBASE III and has little error checking. Please contribute if you want to help!\n\nIn-browser parsing of dBASE table files requires [TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder#Browser_compatibility), part of the [Encoding living standard](https://encoding.spec.whatwg.org/), which is not supported in IE or Safari as of September, 2016. See [text-encoding](https://github.com/inexorabletash/text-encoding) for a browser polyfill.\n\nTypeScript definitions are available in [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/shapefile): `typings install dt~shapefile`.\n\n## API Reference\n\n<a name=\"read\" href=\"#read\">#</a> shapefile.<b>read</b>(<i>shp</i>[, <i>dbf</i>[, <i>options</i>]]) [<>](https://github.com/mbostock/shapefile/blob/master/index.js#L62 \"Source\")\n\nReturns a promise that yields a [GeoJSON feature collection](http://geojson.org/geojson-spec.html#feature-collection-objects) for specified shapefile *shp* and dBASE table file *dbf*. The meaning of the arguments is the same as [shapefile.open](#open). This is a convenience API for reading an entire shapefile in one go; use this method if you don’t mind putting the whole shapefile in memory. The yielded *collection* has a bbox property representing the bounding box of all records in this shapefile. The bounding box is specified as [*xmin*, *ymin*, *xmax*, *ymax*], where *x* and *y* represent longitude and latitude in spherical coordinates.\n\nThe [coordinate reference system](http://geojson.org/geojson-spec.html#coordinate-reference-system-objects) of the feature collection is not specified. This library does not support parsing coordinate reference system specifications (.prj); see [Proj4js](https://github.com/proj4js/proj4js) for parsing [well-known text (WKT)](https://en.wikipedia.org/wiki/Well-known_text#Coordinate_reference_system) specifications.\n\n<a name=\"open\" href=\"#open\">#</a> shapefile.<b>open</b>(<i>shp</i>[, <i>dbf</i>[, <i>options</i>]]) [<>](https://github.com/mbostock/shapefile/blob/master/index.js#L6 \"Source\")\n\nReturns a promise that yields a GeoJSON Feature [*source*](#sources).\n\nIf typeof *shp* is “string”, opens the shapefile at the specified *shp* path. If *shp* does not have a “.shp” extension, it is implicitly added. If *shp* instanceof ArrayBuffer or *shp* instanceof Uint8Array, reads the specified in-memory shapefile. Otherwise, *shp* must be a [Node readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) in Node or a [WhatWG standard readable stream](https://streams.spec.whatwg.org/#rs) in browsers.\n\nIf typeof *dbf* is “string”, opens the dBASE file at the specified *dbf* path. If *dbf* does not have a “.dbf” extension, it is implicitly added. If *dbf* instanceof ArrayBuffer or *dbf* instanceof Uint8Array, reads the specified in-memory dBASE file. If *dbf* is undefined and *shp* is a string, then *dbf* defaults to *shp* with the “.shp” extension replaced with “.dbf”; in this case, no error is thrown if there is no dBASE file at the resulting implied *dbf*. If *dbf* is undefined and *shp* is not a string, or if *dbf* is null, then no dBASE file is read, and the resulting GeoJSON features will have empty properties. Otherwise, *dbf* must be a [Node readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) in Node or a [WhatWG standard readable stream](https://streams.spec.whatwg.org/#rs) in browsers.\n\nIf typeof *shp* or *dbf* is “string”, in Node, the files are read from the [file system](https://nodejs.org/api/fs.html); in browsers, the files are read using [streaming](https://www.chromestatus.com/feature/5804334163951616) [fetch](https://fetch.spec.whatwg.org/), if available, and falling back to [XMLHttpRequest](https://xhr.spec.whatwg.org/). See [path-source](https://github.com/mbostock/path-source) for more.\n\nThe follwing options are supported:\n\n* `encoding` - the dBASE character encoding; defaults to “windows-1252”\n* `highWaterMark` - in Node, the size of the stream’s internal buffer; defaults to 65536\n\n<a name=\"openShp\" href=\"#openShp\">#</a> shapefile.<b>openShp</b>(<i>shp</i>[, <i>options</i>]) [<>](https://github.com/mbostock/shapefile/blob/master/index.js#L33 \"Source\")\n\nReturns a promise that yields a GeoJSON geometry [*source*](#sources). Unlike [shapefile.open](#open), this only reads the shapefile, and never the associated dBASE file. Subsequent calls to [*source*.read](#source_read) will yield GeoJSON geometries.\n\nIf typeof *shp* is “string”, opens the shapefile at the specified *shp* path. If *shp* does not have a “.shp” extension, it is implicitly added. In Node, the files are read from the [file system](https://nodejs.org/api/fs.html); in browsers, the files are read using [streaming](https://www.chromestatus.com/feature/5804334163951616) [fetch](https://fetch.spec.whatwg.org/), if available, and falling back to [XMLHttpRequest](https://xhr.spec.whatwg.org/). (See [path-source](https://github.com/mbostock/path-source) for more.) If *shp* instanceof ArrayBuffer or *shp* instanceof Uint8Array, reads the specified in-memory shapefile. Otherwise, *shp* must be a [Node readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) in Node or a [WhatWG standard readable stream](https://streams.spec.whatwg.org/#rs) in browsers.\n\nThe follwing options are supported:\n\n* `highWaterMark` - in Node, the size of the stream’s internal buffer; defaults to 65536\n\n<a name=\"openDbf\" href=\"#openDbf\">#</a> shapefile.<b>openDbf</b>(<i>dbf</i>[, <i>options</i>]) [<>](https://github.com/mbostock/shapefile/blob/master/index.js#L45 \"Source\")\n\nReturns a promise that yields a GeoJSON properties object [*source*](#sources). Unlike [shapefile.open](#open), this only reads the dBASE file, and never the associated shapefile. Subsequent calls to [*source*.read](#source_read) will yield GeoJSON properties objects.\n\nIf typeof *dbf* is “string”, opens the dBASE at the specified *dbf* path. If *dbf* does not have a “.dbf” extension, it is implicitly added. In Node, the files are read from the [file system](https://nodejs.org/api/fs.html); in browsers, the files are read using [streaming](https://www.chromestatus.com/feature/5804334163951616) [fetch](https://fetch.spec.whatwg.org/), if available, and falling back to [XMLHttpRequest](https://xhr.spec.whatwg.org/). (See [path-source](https://github.com/mbostock/path-source) for more.) If *dbf* instanceof ArrayBuffer or *dbf* instanceof Uint8Array, reads the specified in-memory shapefile. Otherwise, *dbf* must be a [Node readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) in Node or a [WhatWG standard readable stream](https://streams.spec.whatwg.org/#rs) in browsers.\n\nThe follwing options are supported:\n\n* `encoding` - the dBASE character encoding; defaults to “windows-1252”\n* `highWaterMark` - in Node, the size of the stream’s internal buffer; defaults to 65536\n\n### Sources\n\nCalling [shapefile.open](#open) yields a *source*; you can then call [*source*.read](#source_read) to read individual GeoJSON features. Similarly, [shapefile.openShp](#openShp) yields a *source* of GeoJSON geometries, and [shapefile.openDbf](#openDbf) yields of a *source* of GeoJSON properties objects.\n\n<a name=\"source_bbox\" href=\"#source_bbox\">#</a> <i>source</i>.<b>bbox</b>\n\nThe shapefile’s bounding box [*xmin*, *ymin*, *xmax*, *ymax*], where *x* and *y* represent longitude and latitude in spherical coordinates. This field is only defined on sources returned by [shapefile.open](#open) and [shapefile.openShp](#openShp), not [shapefile.openDbf](#openDbf).\n\n<a name=\"source_read\" href=\"#source_read\">#</a> <i>source</i>.<b>read</b>() [<>](https://github.com/mbostock/shapefile/blob/master/shapefile/read.js \"Source\")\n\nReturns a Promise for the next record from the underlying stream. The yielded result is an object with the following properties:\n\n* `value` - a JSON object, or undefined if the stream ended\n* `done` - a boolean which is true if the stream ended\n\nThe type of JSON object depends on the type of *source*: it may be either a [GeoJSON feature](http://geojson.org/geojson-spec.html#feature-objects), a [GeoJSON geometry](http://geojson.org/geojson-spec.html#geometry-objects), or a GeoJSON properties object (any JSON object).\n\n<a name=\"source_cancel\" href=\"#source_cancel\">#</a> <i>source</i>.<b>cancel</b>() [<>](https://github.com/mbostock/shapefile/blob/master/shapefile/cancel.js \"Source\")\n\nReturns a Promise which is resolved when the underlying stream has been destroyed.\n\n## Command Line Reference\n\n### shp2json\n\n<a name=\"shp2json\" href=\"#shp2json\">#</a> <b>shp2json</b> [<i>options…</i>] [<i>file</i>] [<>](https://github.com/mbostock/shapefile/blob/master/bin/shp2json \"Source\")\n\nConverts the specified shapefile *file* to GeoJSON. If *file* is not specified, defaults to reading from stdin (with no dBASE file). For example, to convert to a feature collection:\n\n```\nshp2json example.shp\n```\n\nTo convert to a geometry collection:\n\n```\nshp2json -g example.shp\n```\n\nTo convert to newline-delimited features:\n\n```\nshp2json -n example.shp\n```\n\nTo convert to newline-delimited geometries:\n\n```\nshp2json -ng example.shp\n```\n\nWhen [--geometry](#shp2json_geometry) or [--ignore-properties](#shp2json_ignore_properties) is not used, the shapefile is joined to the dBASE table file (.dbf) file corresonding to the specified shapefile *file*, if any.\n\n<a name=\"shp2json_help\" href=\"#shp2json_help\">#</a> shp2json <b>-h</b>\n<br><a href=\"#shp2json_help\">#</a> shp2json <b>--help</b>\n\nOutput usage information.\n\n<a name=\"shp2json_version\" href=\"#shp2json_version\">#</a> shp2json <b>-V</b>\n<br><a href=\"#shp2json_version\">#</a> shp2json <b>--version</b>\n\nOutput the version number.\n\n<a name=\"shp2json_out\" href=\"#shp2json_out\">#</a> shp2json <b>-o</b> <i>file</i>\n<br><a href=\"#shp2json_out\">#</a> shp2json <b>--out</b> <i>file</i>\n\nSpecify the output file name. Defaults to “-” for stdout.\n\n<a name=\"shp2json_newline_delimited\" href=\"#shp2json_newline_delimited\">#</a> shp2json <b>-n</b>\n<br><a href=\"#shp2json_newline_delimited\">#</a> shp2json <b>--newline-delimited</b>\n\nOutput [newline-delimited JSON](http://ndjson.org/), with one feature or [geometry](#shp2json_geometry) per line.\n\n<a name=\"shp2json_geometry\" href=\"#shp2json_geometry\">#</a> shp2json <b>-g</b>\n<br><a href=\"#shp2json_geometry\">#</a> shp2json <b>--geometry</b>\n\nOutput a [geometry collection](http://geojson.org/geojson-spec.html#geometrycollection) instead of a [feature collection](http://geojson.org/geojson-spec.html#feature-collection-objects) or, in conjuction with [--newline-delimited](#shp2json_newline_delimited), [geometries](http://geojson.org/geojson-spec.html#geometry-objects) instead of [feature objects](http://geojson.org/geojson-spec.html#feature-objects). Implies [--ignore-properties](#shp2json_ignore_properties).\n\n<a name=\"shp2json_ignore_properties\" href=\"#shp2json_ignore_properties\">#</a> shp2json <b>--ignore-properties</b>\n\nIgnore the corresponding dBASE table file (.dbf), if any. Output features will have an empty properties object.\n\n<a name=\"shp2json_encoding\" href=\"#shp2json_encoding\">#</a> shp2json <b>--encoding</b> <i>encoding</i>\n\nSpecify the dBASE table file character encoding. Defaults to “windows-1252”.\n\n<a name=\"shp2json_crs_name\" href=\"#shp2json_crs_name\">#</a> shp2json <b>--crs-name</b> <i>name</i>\n\nSpecify the [coordinate reference system name](http://geojson.org/geojson-spec.html#named-crs). This only applies when generating a feature collection; it is ignored when [-n](#shp2json_newline_delimited) or [-g](#shp2json_geometry) is used. Per the GeoJSON specification, the name should be an OGC CRS URN such as `urn:ogc:def:crs:OGC:1.3:CRS84`. However, legacy identifiers such as `EPSG:4326` may also be used.\n\nThis does not convert between coordinate reference systems! It merely outputs coordinate reference system metadata. This library does not support parsing coordinate reference system specifications (.prj).\n\n### dbf2json\n\n<a name=\"dbf2json\" href=\"#dbf2json\">#</a> <b>dbf2json</b> [<i>options…</i>] [<i>file</i>] [<>](https://github.com/mbostock/shapefile/blob/master/bin/dbf2json \"Source\")\n\nConverts the specified dBASE *file* to JSON. If *file* is not specified, defaults to reading from stdin. For example:\n\n```\ndbf2json example.dbf\n```\n\nTo convert to newline-delimited objects:\n\n```\ndbf2json -n example.dbf\n```\n\n<a name=\"dbf2json_help\" href=\"#dbf2json_help\">#</a> dbf2json <b>-h</b>\n<br><a href=\"#dbf2json_help\">#</a> dbf2json <b>--help</b>\n\nOutput usage information.\n\n<a name=\"dbf2json_version\" href=\"#dbf2json_version\">#</a> dbf2json <b>-V</b>\n<br><a href=\"#dbf2json_version\">#</a> dbf2json <b>--version</b>\n\nOutput the version number.\n\n<a name=\"dbf2json_out\" href=\"#dbf2json_out\">#</a> dbf2json <b>-o</b> <i>file</i>\n<br><a href=\"#dbf2json_out\">#</a> dbf2json <b>--out</b> <i>file</i>\n\nSpecify the output file name. Defaults to “-” for stdout.\n\n<a name=\"dbf2json_newline_delimited\" href=\"#dbf2json_newline_delimited\">#</a> dbf2json <b>-n</b>\n<br><a href=\"#dbf2json_newline_delimited\">#</a> dbf2json <b>--newline-delimited</b>\n\nOutput [newline-delimited JSON](http://ndjson.org/), with one object per line.\n\n<a name=\"dbf2json_encoding\" href=\"#dbf2json_encoding\">#</a> dbf2json <b>--encoding</b> <i>encoding</i>\n\nSpecify the input character encoding. Defaults to “windows-1252”.\n","publish_time":1363125837629,"_cnpm_publish_time":1363125837629,"dist-tags":{"latest":"0.6.6"}}