write shapefiles from pure javascript
npm install shp-write-blobnpm run make-test and open index.html in browser.
indexTest.js.
js
var shpwrite = require('shp-write');
// (optional) set names for zip file, zipped folder and feature types
var options = {
folder: 'myshapes',
types: {
point: 'mypoints',
polygon: 'mypolygons',
polyline: 'mylines'
}
}
// a GeoJSON bridge for features
shpwrite.download({
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [0, 0]
},
properties: {
name: 'Foo'
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [0, 10]
},
properties: {
name: 'Bar'
}
}
]
}, options);
// triggers a download of a zip file with shapefiles contained within.
`
API
$3
Given a GeoJSON FeatureCollection as an object,
converts convertible features into Shapefiles and triggers a download.
$3
Given data, an array of objects for each row of data, geometry, the OGC standard
geometry type (like POINT), geometries, a list of geometries as bare coordinate
arrays, generate a shapfile and call the callback with err and an object with
`js
{
shp: DataView(),
shx: DataView(),
dbf: DataView()
}
`
$3
Returns a promise which contains the blob of a zipped shapefile, dbf, and prj, from a GeoJSON
object.
Other Implementations
* https://code.google.com/p/pyshp/
Reference
* http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
Contributors
* Nick Baugh
$3
zip(geojson)` method now returns a promise which contains the blob for store in cordova