Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shapefile

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shapefile - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

6

dist/shapefile.js

@@ -1,2 +0,2 @@

// https://github.com/mbostock/shapefile Version 0.6.0. Copyright 2017 Mike Bostock.
// https://github.com/mbostock/shapefile Version 0.6.1. Copyright 2017 Mike Bostock.
(function (global, factory) {

@@ -431,3 +431,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

}
return source.then(shp);
return Promise.resolve(source).then(shp);
}

@@ -447,3 +447,3 @@

}
return source.then(function(source) {
return Promise.resolve(source).then(function(source) {
return dbf(source, encoding);

@@ -450,0 +450,0 @@ });

@@ -1,2 +0,2 @@

// https://github.com/mbostock/shapefile Version 0.6.0. Copyright 2017 Mike Bostock.
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.shapefile=e.shapefile||{})}(this,function(e){"use strict";function n(e){return new t(e instanceof Uint8Array?e:new Uint8Array(e))}function t(e){this._array=e}function r(e){return("function"==typeof fetch?A:U)(e)}function o(e){return"function"==typeof e.read?e:e.getReader()}function i(e,n){if(!e.length)return n;if(!n.length)return e;var t=new Uint8Array(e.length+n.length);return t.set(e),t.set(n,e.length),t}function u(e){return"function"==typeof e.slice?e:new a("function"==typeof e.read?e:e.getReader())}function a(e){this._source=e,this._array=F,this._index=0}function f(e,n,t,r){this._source=e,this._decode=n.decode.bind(n),this._recordLength=t.getUint16(10,!0),this._fields=[];for(var o=0;13!==r.getUint8(o);o+=32){for(var i=0;i<11&&0!==r.getUint8(o+i);++i);this._fields.push({name:this._decode(new Uint8Array(r.buffer,r.byteOffset+o,i)),type:String.fromCharCode(r.getUint8(o+11)),length:r.getUint8(o+16)})}}function s(){return this._source.cancel()}function c(e){if((n=e.length)<4)return!1;for(var n,t=0,r=e[n-1][1]*e[0][0]-e[n-1][0]*e[0][1];++t<n;)r+=e[t-1][1]*e[t][0]-e[t-1][0]*e[t][1];return r>=0}function l(e,n){for(var t,r=-1,o=n.length;++r<o;)if(t=h(e,n[r]))return t>0;return!1}function h(e,n){for(var t=n[0],r=n[1],o=-1,i=0,u=e.length,a=u-1;i<u;a=i++){var f=e[i],s=f[0],c=f[1],l=e[a],h=l[0],y=l[1];if(d(f,l,n))return 0;c>r!=y>r&&t<(h-s)*(r-c)/(y-c)+s&&(o=-o)}return o}function d(e,n,t){var r=t[0]-e[0],o=t[1]-e[1];if(0===r&&0===o)return!0;var i=n[0]-e[0],u=n[1]-e[1];if(0===i&&0===u)return!1;var a=(r*i+o*u)/(i*i+u*u);return!(a<0||a>1)&&(0===a||1===a||a*i===r&&a*u===o)}function y(e,n){var t=n.getInt32(32,!0);if(!(t in X))throw new Error("unsupported shape type: "+t);this._source=e,this._type=X[t],this.bbox=[n.getFloat64(36,!0),n.getFloat64(44,!0),n.getFloat64(52,!0),n.getFloat64(60,!0)]}function p(){}function g(e,n){this._shp=e,this._dbf=n,this.bbox=e.bbox}function v(e,t,i){return"string"==typeof t?(/\.dbf$/.test(t)||(t+=".dbf"),t=r(t,i)):t instanceof ArrayBuffer||t instanceof Uint8Array?t=n(t):null!=t&&(t=o(t)),"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),void 0===t&&(t=r(e.substring(0,e.length-4)+".dbf",i).catch(function(){})),e=r(e,i)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.all([e,t]).then(function(e){var n=e[0],t=e[1],r="windows-1252";return i&&null!=i.encoding&&(r=i.encoding),Q(n,t,t&&new TextDecoder(r))})}function _(e){return"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),e=r(e,options)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),e.then(k)}function b(e,t){var i="windows-1252";return t&&null!=t.encoding&&(i=t.encoding),i=new TextDecoder(i),"string"==typeof e?(/\.dbf$/.test(e)||(e+=".dbf"),e=r(e,t)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),e.then(function(e){return T(e,i)})}function w(e,n,t){return v(e,n,t).then(function(e){var n=[],t={type:"FeatureCollection",features:n,bbox:e.bbox};return e.read().then(function r(o){return o.done?t:(n.push(o.value),e.read().then(r))})})}var x=function(){return this._array=null,Promise.resolve()},m=function(){var e=this._array;return this._array=null,Promise.resolve(e?{done:!1,value:e}:{done:!0,value:void 0})};t.prototype.read=m,t.prototype.cancel=x;var A=function(e){return fetch(e).then(function(e){return e.body&&e.body.getReader?e.body.getReader():e.arrayBuffer().then(n)})},U=function(e){return new Promise(function(t,r){var o=new XMLHttpRequest;o.responseType="arraybuffer",o.onload=function(){t(n(o.response))},o.onerror=r,o.ontimeout=r,o.open("GET",e,!0),o.send()})},F=new Uint8Array(0),P=function(){return this._source.cancel()},I=function(){var e=this,n=e._array.subarray(e._index);return e._source.read().then(function(t){return e._array=F,e._index=0,t.done?n.length>0?{done:!1,value:n}:{done:!0,value:void 0}:{done:!1,value:i(n,t.value)}})},L=function(e){if((e|=0)<0)throw new Error("invalid length");var n=this,t=this._array.length-this._index;if(this._index+e<=this._array.length)return Promise.resolve(this._array.subarray(this._index,this._index+=e));var r=new Uint8Array(e);return r.set(this._array.subarray(this._index)),function o(){return n._source.read().then(function(i){return i.done?(n._array=F,n._index=0,t>0?r.subarray(0,t):null):t+i.value.length>=e?(n._array=i.value,n._index=e-t,r.set(i.value.subarray(0,e-t),t),r):(r.set(i.value,t),t+=i.value.length,o())})}()};a.prototype.read=I,a.prototype.slice=L,a.prototype.cancel=P;var B=function(){return this._source.cancel()},D=function(e){return!/^[nf]$/i.test(e)&&(!!/^[yt]$/i.test(e)||null)},M=function(e){return new Date(+e.substring(0,4),e.substring(4,6)-1,+e.substring(6,8))},$=function(e){return!(e=e.trim())||isNaN(e=+e)?null:e},E=function(e){return e.trim()||null},R={B:$,C:E,D:M,F:$,L:D,M:$,N:$},C=function(){var e=this,n=1;return e._source.slice(e._recordLength).then(function(t){return t?{done:!1,value:e._fields.reduce(function(r,o){return r[o.name]=R[o.type](e._decode(t.subarray(n,n+=o.length))),r},{})}:{done:!0,value:void 0}})},S=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},T=function(e,n){return e=u(e),e.slice(32).then(function(t){var r=S(t);return e.slice(r.getUint16(8,!0)-32).then(function(t){return new f(e,n,r,S(t))})})},N=f.prototype;N.read=C,N.cancel=B;var O=function(e){var n,t=40,r=e.getInt32(36,!0),o=new Array(r);for(n=0;n<r;++n,t+=16)o[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return{type:"MultiPoint",coordinates:o}},j=function(){return null},q=function(e){return{type:"Point",coordinates:[e.getFloat64(4,!0),e.getFloat64(12,!0)]}},G=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o),a=[],f=[];for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return i.forEach(function(e,n){var t=u.slice(e,i[n+1]);c(t)?a.push([t]):f.push(t)}),f.forEach(function(e){a.some(function(n){if(l(n[0],e))return n.push(e),!0})||a.push([e])}),1===a.length?{type:"Polygon",coordinates:a[0]}:{type:"MultiPolygon",coordinates:a}},H=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o);for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return 1===r?{type:"LineString",coordinates:u}:{type:"MultiLineString",coordinates:i.map(function(e,n){return u.slice(e,i[n+1])})}},V=function(){var e=this;return e._source.slice(8).then(function(n){if(null==n)return{done:!0,value:void 0};var t=S(n);return e._source.slice(2*t.getInt32(4,!1)).then(function(n){var t=S(n);return{done:!1,value:t.getInt32(0,!0)?e._type(t):j()}})})},X={0:j,1:q,3:H,5:G,8:O,11:q,13:H,15:G,18:O},k=function(e){return e=u(e),e.slice(100).then(function(n){return new y(e,S(n))})},z=y.prototype;z.read=V,z.cancel=s;var J=function(){return Promise.all([this._dbf&&this._dbf.cancel(),this._shp.cancel()]).then(p)},K=function(){var e=this;return Promise.all([e._dbf?e._dbf.read():{value:{}},e._shp.read()]).then(function(e){var n=e[0],t=e[1];return t.done?t:{done:!1,value:{type:"Feature",properties:n.value,geometry:t.value}}})},Q=function(e,n,t){return Promise.all([k(e),n&&T(n,t)]).then(function(e){return new g(e[0],e[1])})},W=g.prototype;W.read=K,W.cancel=J,e.open=v,e.openShp=_,e.openDbf=b,e.read=w,Object.defineProperty(e,"__esModule",{value:!0})});
// https://github.com/mbostock/shapefile Version 0.6.1. Copyright 2017 Mike Bostock.
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.shapefile=e.shapefile||{})}(this,function(e){"use strict";function n(e){return new t(e instanceof Uint8Array?e:new Uint8Array(e))}function t(e){this._array=e}function r(e){return("function"==typeof fetch?A:U)(e)}function o(e){return"function"==typeof e.read?e:e.getReader()}function i(e,n){if(!e.length)return n;if(!n.length)return e;var t=new Uint8Array(e.length+n.length);return t.set(e),t.set(n,e.length),t}function u(e){return"function"==typeof e.slice?e:new a("function"==typeof e.read?e:e.getReader())}function a(e){this._source=e,this._array=F,this._index=0}function f(e,n,t,r){this._source=e,this._decode=n.decode.bind(n),this._recordLength=t.getUint16(10,!0),this._fields=[];for(var o=0;13!==r.getUint8(o);o+=32){for(var i=0;i<11&&0!==r.getUint8(o+i);++i);this._fields.push({name:this._decode(new Uint8Array(r.buffer,r.byteOffset+o,i)),type:String.fromCharCode(r.getUint8(o+11)),length:r.getUint8(o+16)})}}function s(){return this._source.cancel()}function c(e){if((n=e.length)<4)return!1;for(var n,t=0,r=e[n-1][1]*e[0][0]-e[n-1][0]*e[0][1];++t<n;)r+=e[t-1][1]*e[t][0]-e[t-1][0]*e[t][1];return r>=0}function l(e,n){for(var t,r=-1,o=n.length;++r<o;)if(t=h(e,n[r]))return t>0;return!1}function h(e,n){for(var t=n[0],r=n[1],o=-1,i=0,u=e.length,a=u-1;i<u;a=i++){var f=e[i],s=f[0],c=f[1],l=e[a],h=l[0],y=l[1];if(d(f,l,n))return 0;c>r!=y>r&&t<(h-s)*(r-c)/(y-c)+s&&(o=-o)}return o}function d(e,n,t){var r=t[0]-e[0],o=t[1]-e[1];if(0===r&&0===o)return!0;var i=n[0]-e[0],u=n[1]-e[1];if(0===i&&0===u)return!1;var a=(r*i+o*u)/(i*i+u*u);return!(a<0||a>1)&&(0===a||1===a||a*i===r&&a*u===o)}function y(e,n){var t=n.getInt32(32,!0);if(!(t in X))throw new Error("unsupported shape type: "+t);this._source=e,this._type=X[t],this.bbox=[n.getFloat64(36,!0),n.getFloat64(44,!0),n.getFloat64(52,!0),n.getFloat64(60,!0)]}function p(){}function g(e,n){this._shp=e,this._dbf=n,this.bbox=e.bbox}function v(e,t,i){return"string"==typeof t?(/\.dbf$/.test(t)||(t+=".dbf"),t=r(t,i)):t instanceof ArrayBuffer||t instanceof Uint8Array?t=n(t):null!=t&&(t=o(t)),"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),void 0===t&&(t=r(e.substring(0,e.length-4)+".dbf",i).catch(function(){})),e=r(e,i)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.all([e,t]).then(function(e){var n=e[0],t=e[1],r="windows-1252";return i&&null!=i.encoding&&(r=i.encoding),Q(n,t,t&&new TextDecoder(r))})}function _(e){return"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),e=r(e,options)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.resolve(e).then(k)}function b(e,t){var i="windows-1252";return t&&null!=t.encoding&&(i=t.encoding),i=new TextDecoder(i),"string"==typeof e?(/\.dbf$/.test(e)||(e+=".dbf"),e=r(e,t)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.resolve(e).then(function(e){return T(e,i)})}function w(e,n,t){return v(e,n,t).then(function(e){var n=[],t={type:"FeatureCollection",features:n,bbox:e.bbox};return e.read().then(function r(o){return o.done?t:(n.push(o.value),e.read().then(r))})})}var m=function(){return this._array=null,Promise.resolve()},x=function(){var e=this._array;return this._array=null,Promise.resolve(e?{done:!1,value:e}:{done:!0,value:void 0})};t.prototype.read=x,t.prototype.cancel=m;var A=function(e){return fetch(e).then(function(e){return e.body&&e.body.getReader?e.body.getReader():e.arrayBuffer().then(n)})},U=function(e){return new Promise(function(t,r){var o=new XMLHttpRequest;o.responseType="arraybuffer",o.onload=function(){t(n(o.response))},o.onerror=r,o.ontimeout=r,o.open("GET",e,!0),o.send()})},F=new Uint8Array(0),P=function(){return this._source.cancel()},I=function(){var e=this,n=e._array.subarray(e._index);return e._source.read().then(function(t){return e._array=F,e._index=0,t.done?n.length>0?{done:!1,value:n}:{done:!0,value:void 0}:{done:!1,value:i(n,t.value)}})},L=function(e){if((e|=0)<0)throw new Error("invalid length");var n=this,t=this._array.length-this._index;if(this._index+e<=this._array.length)return Promise.resolve(this._array.subarray(this._index,this._index+=e));var r=new Uint8Array(e);return r.set(this._array.subarray(this._index)),function o(){return n._source.read().then(function(i){return i.done?(n._array=F,n._index=0,t>0?r.subarray(0,t):null):t+i.value.length>=e?(n._array=i.value,n._index=e-t,r.set(i.value.subarray(0,e-t),t),r):(r.set(i.value,t),t+=i.value.length,o())})}()};a.prototype.read=I,a.prototype.slice=L,a.prototype.cancel=P;var B=function(){return this._source.cancel()},D=function(e){return!/^[nf]$/i.test(e)&&(!!/^[yt]$/i.test(e)||null)},M=function(e){return new Date(+e.substring(0,4),e.substring(4,6)-1,+e.substring(6,8))},$=function(e){return!(e=e.trim())||isNaN(e=+e)?null:e},E=function(e){return e.trim()||null},R={B:$,C:E,D:M,F:$,L:D,M:$,N:$},C=function(){var e=this,n=1;return e._source.slice(e._recordLength).then(function(t){return t?{done:!1,value:e._fields.reduce(function(r,o){return r[o.name]=R[o.type](e._decode(t.subarray(n,n+=o.length))),r},{})}:{done:!0,value:void 0}})},S=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},T=function(e,n){return e=u(e),e.slice(32).then(function(t){var r=S(t);return e.slice(r.getUint16(8,!0)-32).then(function(t){return new f(e,n,r,S(t))})})},N=f.prototype;N.read=C,N.cancel=B;var O=function(e){var n,t=40,r=e.getInt32(36,!0),o=new Array(r);for(n=0;n<r;++n,t+=16)o[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return{type:"MultiPoint",coordinates:o}},j=function(){return null},q=function(e){return{type:"Point",coordinates:[e.getFloat64(4,!0),e.getFloat64(12,!0)]}},G=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o),a=[],f=[];for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return i.forEach(function(e,n){var t=u.slice(e,i[n+1]);c(t)?a.push([t]):f.push(t)}),f.forEach(function(e){a.some(function(n){if(l(n[0],e))return n.push(e),!0})||a.push([e])}),1===a.length?{type:"Polygon",coordinates:a[0]}:{type:"MultiPolygon",coordinates:a}},H=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o);for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return 1===r?{type:"LineString",coordinates:u}:{type:"MultiLineString",coordinates:i.map(function(e,n){return u.slice(e,i[n+1])})}},V=function(){var e=this;return e._source.slice(8).then(function(n){if(null==n)return{done:!0,value:void 0};var t=S(n);return e._source.slice(2*t.getInt32(4,!1)).then(function(n){var t=S(n);return{done:!1,value:t.getInt32(0,!0)?e._type(t):j()}})})},X={0:j,1:q,3:H,5:G,8:O,11:q,13:H,15:G,18:O},k=function(e){return e=u(e),e.slice(100).then(function(n){return new y(e,S(n))})},z=y.prototype;z.read=V,z.cancel=s;var J=function(){return Promise.all([this._dbf&&this._dbf.cancel(),this._shp.cancel()]).then(p)},K=function(){var e=this;return Promise.all([e._dbf?e._dbf.read():{value:{}},e._shp.read()]).then(function(e){var n=e[0],t=e[1];return t.done?t:{done:!1,value:{type:"Feature",properties:n.value,geometry:t.value}}})},Q=function(e,n,t){return Promise.all([k(e),n&&T(n,t)]).then(function(e){return new g(e[0],e[1])})},W=g.prototype;W.read=K,W.cancel=J,e.open=v,e.openShp=_,e.openDbf=b,e.read=w,Object.defineProperty(e,"__esModule",{value:!0})});

@@ -305,3 +305,3 @@ 'use strict';

}
return source.then(shp);
return Promise.resolve(source).then(shp);
}

@@ -321,3 +321,3 @@

}
return source.then(function(source) {
return Promise.resolve(source).then(function(source) {
return dbf(source, encoding);

@@ -324,0 +324,0 @@ });

@@ -42,3 +42,3 @@ import path from "path-source";

}
return source.then(shp);
return Promise.resolve(source).then(shp);
}

@@ -58,3 +58,3 @@

}
return source.then(function(source) {
return Promise.resolve(source).then(function(source) {
return dbf(source, encoding);

@@ -61,0 +61,0 @@ });

{
"name": "shapefile",
"version": "0.6.0",
"version": "0.6.1",
"description": "An implementation of the shapefile (.shp) spatial data format.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -22,3 +22,3 @@ # Streaming Shapefile Parser

<!DOCTYPE html>
<script src="https://unpkg.com/shapefile@0.5"></script>
<script src="https://unpkg.com/shapefile@0.6"></script>
<script>

@@ -54,5 +54,11 @@

<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")
Returns 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.
The [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.
<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")
Returns a promise that yields an open shapefile *source*.
Returns a promise that yields a GeoJSON Feature [*source*](#sources).

@@ -72,8 +78,6 @@ If 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.

Returns a promise that yields an open shapefile *source*. 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 geometry objects.
Returns 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.
If 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.
If 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.
If typeof *shp* 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.
The follwing options are supported:

@@ -85,8 +89,6 @@

Returns a promise that yields an open dBASE *source*. 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.
Returns 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.
If typeof *dbf* is “string”, opens the dBASE 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 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.
If 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.
If typeof *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.
The follwing options are supported:

@@ -97,11 +99,9 @@

<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")
### Sources
Returns 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.
Calling [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.
The [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). [Proj4js](https://github.com/proj4js/proj4js) can parse most [well-known text (WKT)](https://en.wikipedia.org/wiki/Well-known_text#Coordinate_reference_system) specifications, but I’m not aware of any pure-JavaScript libraries that can convert these to OGC CRS URNs. (Please let me know if one exists!)
<a name="source_bbox" href="#source_bbox">#</a> <i>source</i>.<b>bbox</b>
The shapefile’s bounding box [*xmin*, *ymin*, *xmax*, *ymax*], where *x* and *y* represent longitude and latitude in spherical coordinates.
The 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).

@@ -112,5 +112,7 @@ <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")

* `value` - a [GeoJSON feature](http://geojson.org/geojson-spec.html#feature-objects), or undefined if the stream ended
* `value` - a JSON object, or undefined if the stream ended
* `done` - a boolean which is true if the stream ended
The 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).
<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")

@@ -175,3 +177,3 @@

Output 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), [geometry objects](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).
Output 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).

@@ -178,0 +180,0 @@ <a name="shp2json_ignore_properties" href="#shp2json_ignore_properties">#</a> shp2json <b>--ignore-properties</b>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc