Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hongfaqiu/shp-write-multi
geojson to shp
https://github.com/hongfaqiu/shp-write-multi
Last synced: 7 days ago
JSON representation
geojson to shp
- Host: GitHub
- URL: https://github.com/hongfaqiu/shp-write-multi
- Owner: hongfaqiu
- License: bsd-3-clause
- Created: 2021-04-09T09:01:30.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-30T02:09:11.000Z (almost 2 years ago)
- Last Synced: 2025-01-03T23:42:51.004Z (9 days ago)
- Language: JavaScript
- Homepage:
- Size: 291 KB
- Stars: 5
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://secure.travis-ci.org/mapbox/shp-write.svg?branch=master)](http://travis-ci.org/mapbox/shp-write)
# shp-write-multi
``origin repository`` [shp-write](https://github.com/mapbox/shp-write)
Writes shapefile in pure javascript. Uses [dbf](https://github.com/tmcw/dbf)
for the data component, and [jsZIP](http://stuk.github.io/jszip/) to generate
ZIP file downloads in-browser.## Usage
For node.js or [browserify](https://github.com/substack/node-browserify)
npm install --save shp-write-multi
Or in a browserhttps://unpkg.com/shp-write-multi@latest/shpwrite.js
## Caveats
* Requires a capable fancy modern browser with [Typed Arrays](http://caniuse.com/#feat=typedarrays)
support
* Geometries: Point, LineString, Polygon, MultiLineString, MultiPolygon
* Tabular-style properties export with Shapefile's field name length limit
* Uses jsZip for ZIP files, but [compression is buggy](https://github.com/Stuk/jszip/issues/53) so it uses STORE instead of DEFLATE.## Example
```js
const shpwrite = require('shp-write-multi');// (optional) set names for features and zipped folder
const options = {
folder: 'myshapes',
// output .shp name with geojson's features, default is ['myshpes_POINT_1', 'myshpes_POINT_2']
names: ['test','test1']
}
// a GeoJSON bridge for features
await 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.
```output file
```js
download.zip
└── myshapes
├── test.dbf
├── test.prj
├── test.shp
├── test.shx
├── test1.dbf
├── test1.prj
├── test1.shp
└── test1.shx
```## API
### `download(geojson)` ⇒ Asynchronous call
Given a [GeoJSON](http://geojson.org/) FeatureCollection as an object,
converts convertible features into Shapefiles and triggers a download.### `write(data, geometrytype, geometries, callback)` ⇒ Synchronous call
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()
}
```### `zip(geojson)` ⇒ Asynchronous call
Generate a ArrayBuffer of a zipped shapefile, dbf, and prj, from a GeoJSON
object.