From e8701b5d26d4674a3941582beff95db0200a4cec Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Fri, 5 Jan 2018 15:06:54 +1100 Subject: [PATCH 1/2] Expose `featureCount` property. Fixes #40. --- README.md | 4 ++++ dbf/index.js | 1 + shapefile/index.js | 1 + 3 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 5203a3d..8c5b0c3 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,10 @@ Calling [shapefile.open](#open) yields a *source*; you can then call [*source*.r 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). +# source.featureCount + +The number of features present, determined by looking at the header of the .dbf file. This field is only defined on sources returned by [shapefile.open](#open) and [shapefile.openDbf](#openDbf), not [shapefile.openShp](#openShp). + # source.read() [<>](https://github.com/mbostock/shapefile/blob/master/shapefile/read.js "Source") Returns a Promise for the next record from the underlying stream. The yielded result is an object with the following properties: diff --git a/dbf/index.js b/dbf/index.js index 063d396..dae447f 100644 --- a/dbf/index.js +++ b/dbf/index.js @@ -17,6 +17,7 @@ function Dbf(source, decoder, head, body) { this._source = source; this._decode = decoder.decode.bind(decoder); this._recordLength = head.getUint16(10, true); + this.featureCount = head.getUint16(4, true); this._fields = []; for (var n = 0; body.getUint8(n) !== 0x0d; n += 32) { for (var j = 0; j < 11; ++j) if (body.getUint8(n + j) === 0) break; diff --git a/shapefile/index.js b/shapefile/index.js index b562e72..bb54b73 100644 --- a/shapefile/index.js +++ b/shapefile/index.js @@ -16,6 +16,7 @@ function Shapefile(shp, dbf) { this._shp = shp; this._dbf = dbf; this.bbox = shp.bbox; + this.featureCount = dbf && dbf.featureCount; } var prototype = Shapefile.prototype; From 93f683706c45b042da5e91f155c71a9bc4412e91 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Fri, 12 Jan 2018 17:37:41 +1100 Subject: [PATCH 2/2] featureCount -> size --- README.md | 2 +- dbf/index.js | 2 +- shapefile/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c5b0c3..55e86c8 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Calling [shapefile.open](#open) yields a *source*; you can then call [*source*.r 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). -# source.featureCount +# source.size The number of features present, determined by looking at the header of the .dbf file. This field is only defined on sources returned by [shapefile.open](#open) and [shapefile.openDbf](#openDbf), not [shapefile.openShp](#openShp). diff --git a/dbf/index.js b/dbf/index.js index dae447f..159ef9c 100644 --- a/dbf/index.js +++ b/dbf/index.js @@ -17,7 +17,7 @@ function Dbf(source, decoder, head, body) { this._source = source; this._decode = decoder.decode.bind(decoder); this._recordLength = head.getUint16(10, true); - this.featureCount = head.getUint16(4, true); + this.size = head.getUint16(4, true); this._fields = []; for (var n = 0; body.getUint8(n) !== 0x0d; n += 32) { for (var j = 0; j < 11; ++j) if (body.getUint8(n + j) === 0) break; diff --git a/shapefile/index.js b/shapefile/index.js index bb54b73..f9e5ee9 100644 --- a/shapefile/index.js +++ b/shapefile/index.js @@ -16,7 +16,7 @@ function Shapefile(shp, dbf) { this._shp = shp; this._dbf = dbf; this.bbox = shp.bbox; - this.featureCount = dbf && dbf.featureCount; + this.size = dbf && dbf.size; } var prototype = Shapefile.prototype;