Socket
Socket
Sign inDemoInstall

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.5.11 to 0.6.0

bin/dbf2json

85

dist/shapefile.js

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

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

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

var prototype$1 = Dbf.prototype;
prototype$1.read = dbf_read;
prototype$1.cancel = dbf_cancel;
var prototype = Dbf.prototype;
prototype.read = dbf_read;
prototype.cancel = dbf_cancel;

@@ -394,33 +394,62 @@ function cancel() {

var prototype = Shapefile.prototype;
prototype.read = shapefile_read;
prototype.cancel = shapefile_cancel;
var prototype$1 = Shapefile.prototype;
prototype$1.read = shapefile_read;
prototype$1.cancel = shapefile_cancel;
function open(shp, dbf, options) {
if (typeof dbf === "string") {
if (!/\.dbf$/.test(dbf)) dbf += ".dbf";
dbf = path(dbf, options);
} else if (dbf instanceof ArrayBuffer || dbf instanceof Uint8Array) {
dbf = array(dbf);
} else if (dbf != null) {
dbf = stream(dbf);
function open(shp$$1, dbf$$1, options) {
if (typeof dbf$$1 === "string") {
if (!/\.dbf$/.test(dbf$$1)) dbf$$1 += ".dbf";
dbf$$1 = path(dbf$$1, options);
} else if (dbf$$1 instanceof ArrayBuffer || dbf$$1 instanceof Uint8Array) {
dbf$$1 = array(dbf$$1);
} else if (dbf$$1 != null) {
dbf$$1 = stream(dbf$$1);
}
if (typeof shp === "string") {
if (!/\.shp$/.test(shp)) shp += ".shp";
if (dbf === undefined) dbf = path(shp.substring(0, shp.length - 4) + ".dbf", options).catch(function() {});
shp = path(shp, options);
} else if (shp instanceof ArrayBuffer || shp instanceof Uint8Array) {
shp = array(shp);
if (typeof shp$$1 === "string") {
if (!/\.shp$/.test(shp$$1)) shp$$1 += ".shp";
if (dbf$$1 === undefined) dbf$$1 = path(shp$$1.substring(0, shp$$1.length - 4) + ".dbf", options).catch(function() {});
shp$$1 = path(shp$$1, options);
} else if (shp$$1 instanceof ArrayBuffer || shp$$1 instanceof Uint8Array) {
shp$$1 = array(shp$$1);
} else {
shp = stream(shp);
shp$$1 = stream(shp$$1);
}
return Promise.all([shp, dbf]).then(function(sources) {
var shp = sources[0], dbf = sources[1], encoding = "windows-1252";
return Promise.all([shp$$1, dbf$$1]).then(function(sources) {
var shp$$1 = sources[0], dbf$$1 = sources[1], encoding = "windows-1252";
if (options && options.encoding != null) encoding = options.encoding;
return shapefile(shp, dbf, dbf && new TextDecoder(encoding));
return shapefile(shp$$1, dbf$$1, dbf$$1 && new TextDecoder(encoding));
});
}
function read(shp, dbf, options) {
return open(shp, dbf, options).then(function(source) {
function openShp(source) {
if (typeof source === "string") {
if (!/\.shp$/.test(source)) source += ".shp";
source = path(source, options);
} else if (source instanceof ArrayBuffer || source instanceof Uint8Array) {
source = array(source);
} else {
source = stream(source);
}
return source.then(shp);
}
function openDbf(source, options) {
var encoding = "windows-1252";
if (options && options.encoding != null) encoding = options.encoding;
encoding = new TextDecoder(encoding);
if (typeof source === "string") {
if (!/\.dbf$/.test(source)) source += ".dbf";
source = path(source, options);
} else if (source instanceof ArrayBuffer || source instanceof Uint8Array) {
source = array(source);
} else {
source = stream(source);
}
return source.then(function(source) {
return dbf(source, encoding);
});
}
function read(shp$$1, dbf$$1, options) {
return open(shp$$1, dbf$$1, options).then(function(source) {
var features = [], collection = {type: "FeatureCollection", features: features, bbox: source.bbox};

@@ -436,2 +465,4 @@ return source.read().then(function read(result) {

exports.open = open;
exports.openShp = openShp;
exports.openDbf = openDbf;
exports.read = read;

@@ -438,0 +469,0 @@

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

// https://github.com/mbostock/shapefile Version 0.5.11. 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?m:x)(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=A,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 c(){return this._source.cancel()}function s(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],c=f[0],s=f[1],l=e[a],h=l[0],y=l[1];if(d(f,l,n))return 0;s>r!=y>r&&t<(h-c)*(r-s)/(y-s)+c&&(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 H))throw new Error("unsupported shape type: "+t);this._source=e,this._type=H[t],this.bbox=[n.getFloat64(36,!0),n.getFloat64(44,!0),n.getFloat64(52,!0),n.getFloat64(60,!0)]}function g(){}function p(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),J(n,t,t&&new TextDecoder(r))})}function _(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 b=function(){return this._array=null,Promise.resolve()},w=function(){var e=this._array;return this._array=null,Promise.resolve(e?{done:!1,value:e}:{done:!0,value:void 0})};t.prototype.read=w,t.prototype.cancel=b;var m=function(e){return fetch(e).then(function(e){return e.body&&e.body.getReader?e.body.getReader():e.arrayBuffer().then(n)})},x=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()})},A=new Uint8Array(0),F=function(){return this._source.cancel()},U=function(){var e=this,n=e._array.subarray(e._index);return e._source.read().then(function(t){return e._array=A,e._index=0,t.done?n.length>0?{done:!1,value:n}:{done:!0,value:void 0}:{done:!1,value:i(n,t.value)}})},P=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=A,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=U,a.prototype.slice=P,a.prototype.cancel=F;var I=function(){return this._source.cancel()},L=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))},E=function(e){return!(e=e.trim())||isNaN(e=+e)?null:e},R=function(e){return e.trim()||null},B={B:E,C:R,D:M,F:E,L:L,M:E,N:E},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]=B[o.type](e._decode(t.subarray(n,n+=o.length))),r},{})}:{done:!0,value:void 0}})},D=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},$=function(e,n){return e=u(e),e.slice(32).then(function(t){var r=D(t);return e.slice(r.getUint16(8,!0)-32).then(function(t){return new f(e,n,r,D(t))})})},N=f.prototype;N.read=C,N.cancel=I;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}},S=function(){return null},T=function(e){return{type:"Point",coordinates:[e.getFloat64(4,!0),e.getFloat64(12,!0)]}},j=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]);s(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}},q=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])})}},G=function(){var e=this;return e._source.slice(8).then(function(n){if(null==n)return{done:!0,value:void 0};var t=D(n);return e._source.slice(2*t.getInt32(4,!1)).then(function(n){var t=D(n);return{done:!1,value:t.getInt32(0,!0)?e._type(t):S()}})})},H={0:S,1:T,3:q,5:j,8:O,11:T,13:q,15:j,18:O},V=function(e){return e=u(e),e.slice(100).then(function(n){return new y(e,D(n))})},X=y.prototype;X.read=G,X.cancel=c;var k=function(){return Promise.all([this._dbf&&this._dbf.cancel(),this._shp.cancel()]).then(g)},z=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}}})},J=function(e,n,t){return Promise.all([V(e),n&&$(n,t)]).then(function(e){return new p(e[0],e[1])})},K=p.prototype;K.read=z,K.cancel=k,e.open=v,e.read=_,Object.defineProperty(e,"__esModule",{value:!0})});
// 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})});

@@ -85,5 +85,5 @@ 'use strict';

var prototype$1 = Dbf.prototype;
prototype$1.read = dbf_read;
prototype$1.cancel = dbf_cancel;
var prototype = Dbf.prototype;
prototype.read = dbf_read;
prototype.cancel = dbf_cancel;

@@ -268,33 +268,62 @@ function cancel() {

var prototype = Shapefile.prototype;
prototype.read = shapefile_read;
prototype.cancel = shapefile_cancel;
var prototype$1 = Shapefile.prototype;
prototype$1.read = shapefile_read;
prototype$1.cancel = shapefile_cancel;
function open(shp, dbf, options) {
if (typeof dbf === "string") {
if (!/\.dbf$/.test(dbf)) dbf += ".dbf";
dbf = path(dbf, options);
} else if (dbf instanceof ArrayBuffer || dbf instanceof Uint8Array) {
dbf = array(dbf);
} else if (dbf != null) {
dbf = stream(dbf);
function open(shp$$1, dbf$$1, options) {
if (typeof dbf$$1 === "string") {
if (!/\.dbf$/.test(dbf$$1)) dbf$$1 += ".dbf";
dbf$$1 = path(dbf$$1, options);
} else if (dbf$$1 instanceof ArrayBuffer || dbf$$1 instanceof Uint8Array) {
dbf$$1 = array(dbf$$1);
} else if (dbf$$1 != null) {
dbf$$1 = stream(dbf$$1);
}
if (typeof shp === "string") {
if (!/\.shp$/.test(shp)) shp += ".shp";
if (dbf === undefined) dbf = path(shp.substring(0, shp.length - 4) + ".dbf", options).catch(function() {});
shp = path(shp, options);
} else if (shp instanceof ArrayBuffer || shp instanceof Uint8Array) {
shp = array(shp);
if (typeof shp$$1 === "string") {
if (!/\.shp$/.test(shp$$1)) shp$$1 += ".shp";
if (dbf$$1 === undefined) dbf$$1 = path(shp$$1.substring(0, shp$$1.length - 4) + ".dbf", options).catch(function() {});
shp$$1 = path(shp$$1, options);
} else if (shp$$1 instanceof ArrayBuffer || shp$$1 instanceof Uint8Array) {
shp$$1 = array(shp$$1);
} else {
shp = stream(shp);
shp$$1 = stream(shp$$1);
}
return Promise.all([shp, dbf]).then(function(sources) {
var shp = sources[0], dbf = sources[1], encoding = "windows-1252";
return Promise.all([shp$$1, dbf$$1]).then(function(sources) {
var shp$$1 = sources[0], dbf$$1 = sources[1], encoding = "windows-1252";
if (options && options.encoding != null) encoding = options.encoding;
return shapefile(shp, dbf, dbf && new TextDecoder(encoding));
return shapefile(shp$$1, dbf$$1, dbf$$1 && new TextDecoder(encoding));
});
}
function read(shp, dbf, options) {
return open(shp, dbf, options).then(function(source) {
function openShp(source) {
if (typeof source === "string") {
if (!/\.shp$/.test(source)) source += ".shp";
source = path(source, options);
} else if (source instanceof ArrayBuffer || source instanceof Uint8Array) {
source = array(source);
} else {
source = stream(source);
}
return source.then(shp);
}
function openDbf(source, options) {
var encoding = "windows-1252";
if (options && options.encoding != null) encoding = options.encoding;
encoding = new TextDecoder(encoding);
if (typeof source === "string") {
if (!/\.dbf$/.test(source)) source += ".dbf";
source = path(source, options);
} else if (source instanceof ArrayBuffer || source instanceof Uint8Array) {
source = array(source);
} else {
source = stream(source);
}
return source.then(function(source) {
return dbf(source, encoding);
});
}
function read(shp$$1, dbf$$1, options) {
return open(shp$$1, dbf$$1, options).then(function(source) {
var features = [], collection = {type: "FeatureCollection", features: features, bbox: source.bbox};

@@ -310,2 +339,4 @@ return source.read().then(function read(result) {

exports.open = open;
exports.openShp = openShp;
exports.openDbf = openDbf;
exports.read = read;
import path from "path-source";
import array from "array-source";
import stream from "stream-source";
import dbf from "./dbf/index";
import shapefile from "./shapefile/index";
import shp from "./shp/index";

@@ -31,2 +33,31 @@ export function open(shp, dbf, options) {

export function openShp(source) {
if (typeof source === "string") {
if (!/\.shp$/.test(source)) source += ".shp";
source = path(source, options);
} else if (source instanceof ArrayBuffer || source instanceof Uint8Array) {
source = array(source);
} else {
source = stream(source);
}
return source.then(shp);
}
export function openDbf(source, options) {
var encoding = "windows-1252";
if (options && options.encoding != null) encoding = options.encoding;
encoding = new TextDecoder(encoding);
if (typeof source === "string") {
if (!/\.dbf$/.test(source)) source += ".dbf";
source = path(source, options);
} else if (source instanceof ArrayBuffer || source instanceof Uint8Array) {
source = array(source);
} else {
source = stream(source);
}
return source.then(function(source) {
return dbf(source, encoding);
});
}
export function read(shp, dbf, options) {

@@ -33,0 +64,0 @@ return open(shp, dbf, options).then(function(source) {

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

@@ -23,2 +23,3 @@ "keywords": [

"bin": {
"dbf2json": "bin/dbf2json",
"shp2json": "bin/shp2json"

@@ -25,0 +26,0 @@ },

@@ -68,4 +68,29 @@ # Streaming Shapefile Parser

<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#L31 "Source")
<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")
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.
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”, 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:
* `highWaterMark` - in Node, the size of the stream’s internal buffer; defaults to 65536
<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")
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.
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”, 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:
* `encoding` - the dBASE character encoding; defaults to “windows-1252”
* `highWaterMark` - in Node, the size of the stream’s internal buffer; defaults to 65536
<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.

@@ -92,2 +117,4 @@

### shp2json
<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")

@@ -159,1 +186,41 @@

This 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).
### dbf2json
<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")
Converts the specified dBASE *file* to JSON. If *file* is not specified, defaults to reading from stdin. For example:
```
dbf2json example.dbf
```
To convert to newline-delimited objects:
```
dbf2json -n example.dbf
```
<a name="dbf2json_help" href="#dbf2json_help">#</a> dbf2json <b>-h</b>
<br><a href="#dbf2json_help">#</a> dbf2json <b>--help</b>
Output usage information.
<a name="dbf2json_version" href="#dbf2json_version">#</a> dbf2json <b>-V</b>
<br><a href="#dbf2json_version">#</a> dbf2json <b>--version</b>
Output the version number.
<a name="dbf2json_out" href="#dbf2json_out">#</a> dbf2json <b>-o</b> <i>file</i>
<br><a href="#dbf2json_out">#</a> dbf2json <b>--out</b> <i>file</i>
Specify the output file name. Defaults to “-” for stdout.
<a name="dbf2json_newline_delimited" href="#dbf2json_newline_delimited">#</a> dbf2json <b>-n</b>
<br><a href="#dbf2json_newline_delimited">#</a> dbf2json <b>--newline-delimited</b>
Output [newline-delimited JSON](http://ndjson.org/), with one object per line.
<a name="dbf2json_encoding" href="#dbf2json_encoding">#</a> dbf2json <b>--encoding</b> <i>encoding</i>
Specify the input character encoding. Defaults to “windows-1252”.
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