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.0.2 to 0.0.3

bin/dbfcat

12

dbf.js

@@ -57,3 +57,3 @@ var file = require("./file");

C: fieldString,
D: fieldString,
D: fieldDate,
F: fieldNumber,

@@ -66,3 +66,3 @@ L: fieldBoolean,

function fieldNumber(d) {
return +d;
return isNaN(d = +d) ? null : d;
}

@@ -74,4 +74,10 @@

function fieldDate(d) {
return new Date(+d.substring(0, 4), d.substring(4, 6) - 1, +d.substring(6, 8));
}
function fieldBoolean(d) {
return d === "T";
return /^[nf]$/i.test(d) ? false
: /^[yt]$/i.test(d) ? true
: null;
}

@@ -78,0 +84,0 @@

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

@@ -17,3 +17,11 @@ "keywords": [

},
"main": "./index.js"
"main": "./index.js",
"devDependencies": {
"vows": "0.7.x"
},
"bin": {
"dbfcat": "./bin/dbfcat",
"shpcat": "./bin/shpcat",
"shp2json": "./bin/shp2json"
}
}
# Streaming Shapefile Parser
Based on the [ESRI Shapefile Technical Description](http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf) and [dBASE Table File Format](http://www.digitalpreservation.gov/formats/fdd/fdd000325.shtml).
Caveat emptor: this library is a work in progress and does not currently support all shapefile geometry types (see [shp.js](https://github.com/mbostock/shapefile/blob/master/shp.js) for details). It also only supports dBASE III and has no error checking. Please contribute if you want to help!
## Reading a Shapefile
The main API for reading a shapefile is shapefile.readStream. This returns an [event emitter](http://nodejs.org/api/events.html) which emits three types of events:
* *feature* - while reading features from the shapefile
* *end* - when all features have been read
* *error* - if an error occurs
Features are emitted as [GeoJSON features](http://geojson.org/geojson-spec.html#feature-objects), not as shapefile primitives. That’s because GeoJSON objects are the standard representation of geometry in JavaScript, and they are convenient. If you want to access the shapefile primitives directly, use the private [shp](https://github.com/mbostock/shapefile/blob/master/shp.js) and [dbf](https://github.com/mbostock/shapefile/blob/master/dbf.js) classes instead.
See [index-test](https://github.com/mbostock/shapefile/blob/master/index-test) for an example converting a shapefile to a GeoJSON feature collection.

@@ -18,10 +18,7 @@ var file = require("./file");

shapeType: shapeType = fileHeader.readInt32LE(32),
xMin: fileHeader.readDoubleLE(36),
xMax: fileHeader.readDoubleLE(52),
yMin: fileHeader.readDoubleLE(44),
yMax: fileHeader.readDoubleLE(60),
zMin: fileHeader.readDoubleLE(68),
zMax: fileHeader.readDoubleLE(76),
mMin: fileHeader.readDoubleLE(84),
mMax: fileHeader.readDoubleLE(92)
box: [fileHeader.readDoubleLE(36), fileHeader.readDoubleLE(44), fileHeader.readDoubleLE(52), fileHeader.readDoubleLE(60)]
// TODO zMin: fileHeader.readDoubleLE(68)
// TODO zMax: fileHeader.readDoubleLE(76)
// TODO mMin: fileHeader.readDoubleLE(84)
// TODO mMax: fileHeader.readDoubleLE(92)
});

@@ -35,4 +32,4 @@ readShapeType = readShape[shapeType];

read(recordHeader.readInt32BE(4) * 2, function readRecord(record) {
// TODO verify var shapeType = record.readInt32LE(0);
stream.emit("record", readShapeType(record));
var shapeType = record.readInt32LE(0);
stream.emit("record", shapeType ? readShapeType(record) : null);
read(8, readRecordHeader);

@@ -39,0 +36,0 @@ });

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