diff --git a/README.md b/README.md index 5203a3d..55e86c8 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.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). + # 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..159ef9c 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.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 b562e72..f9e5ee9 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.size = dbf && dbf.size; } var prototype = Shapefile.prototype;