Skip to content

Commit d2cbd29

Browse files
authored
Merge pull request #123 from Agriculture-Intelligence/master
docs: Stylize announcement, update contributors in README.md
2 parents 48a0fe7 + 914ebd2 commit d2cbd29

File tree

1 file changed

+38
-70
lines changed

1 file changed

+38
-70
lines changed

README.md

Lines changed: 38 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
1-
# shp-write
1+
# @mapbox/shp-write
22

3-
# ANNOUNCEMENT!
4-
5-
The npm package location (and subsequently unpkg url) for this repo has changed!
3+
Writes shapefile in pure javascript. Uses [dbf](https://github.com/tmcw/dbf)
4+
for the data component, and [jsZIP](http://stuk.github.io/jszip/) to generate downloads in-browser.
65

7-
tl;dr: `shp-write` -> `@mapbox/shp-write`
6+
> [!IMPORTANT]
7+
> **The package location for this repo has changed!**
8+
>
9+
> tl;dr: `shp-write` -> [`@mapbox/shp-write`](https://www.npmjs.com/package/@mapbox/shp-write)
810
911

10-
Writes shapefile in pure javascript. Uses [dbf](https://github.com/tmcw/dbf)
11-
for the data component, and [jsZIP](http://stuk.github.io/jszip/) to generate
12-
ZIP file downloads in-browser.
13-
1412
## Usage
1513

16-
For npm
14+
NPM
1715

1816
npm install --save @mapbox/shp-write
1917

2018
Yarn
2119

2220
yarn add @mapbox/shp-write
2321

24-
Or in a browser
22+
Browser
2523

2624
https://unpkg.com/@mapbox/shp-write@latest/shpwrite.js
2725

2826
## Caveats
2927

3028
- Requires a capable fancy modern browser with [Typed Arrays](http://caniuse.com/#feat=typedarrays)
3129
support
32-
- Geometries: Point, LineString, Polygon, MultiLineString, MultiPolygon
33-
- Tabular-style properties export with Shapefile's field name length limit
30+
- Supports geometries: `Point`, `LineString`, `Polygon`, `MultiLineString`, `MultiPolygon`
31+
- Tabular-style properties export with [10 character field name length limit](https://en.wikipedia.org/wiki/Shapefile#:~:text=Maximum%20length%20of%20field%20names%20is%2010%20characters)
3432
- Uses jsZip for ZIP files, but [compression is buggy](https://github.com/Stuk/jszip/issues/53) so it uses STORE instead of DEFLATE.
3533

36-
## Minimal Example
34+
## Example
3735

3836
```js
3937
var shpwrite = require("@mapbox/shp-write");
4038

41-
// a GeoJSON bridge for features
42-
const zipData = shpwrite.zip(
43-
{
39+
const geoJSON = {
4440
type: "FeatureCollection",
4541
features: [
4642
{
@@ -64,16 +60,9 @@ const zipData = shpwrite.zip(
6460
},
6561
},
6662
],
67-
}
68-
);
69-
70-
```
71-
72-
## Options Example
73-
74-
```js
75-
var shpwrite = require("@mapbox/shp-write");
63+
};
7664

65+
// Optional custom options passed to the underlying `zip` call
7766
const options = {
7867
folder: "my_internal_shapes_folder",
7968
filename: "my_zip_filename",
@@ -86,35 +75,7 @@ const options = {
8675
},
8776
};
8877

89-
// a GeoJSON bridge for features
90-
const zipData = shpwrite.zip(
91-
{
92-
type: "FeatureCollection",
93-
features: [
94-
{
95-
type: "Feature",
96-
geometry: {
97-
type: "Point",
98-
coordinates: [0, 0],
99-
},
100-
properties: {
101-
name: "Foo",
102-
},
103-
},
104-
{
105-
type: "Feature",
106-
geometry: {
107-
type: "Point",
108-
coordinates: [0, 10],
109-
},
110-
properties: {
111-
name: "Bar",
112-
},
113-
},
114-
],
115-
},
116-
options
117-
);
78+
const zipData = shpwrite.zip(geoJSON,options);
11879
```
11980

12081
## Custom .prj file
@@ -127,37 +88,43 @@ var options = {
12788
```
12889

12990
## API
91+
13092
### `write(data, geometrytype, geometries, callback)`
13193

132-
Given data, an array of objects for each row of data, geometry, the OGC standard
133-
geometry type (like `POINT`), geometries, a list of geometries as bare coordinate
134-
arrays, generate a shapfile and call the callback with `err` and an object with
94+
Generates a shapefile and calls the callback with err and an object containing shp, shx, and dbf DataViews.
13595

96+
* data: Array of objects for each row of data.
97+
* geometrytype: The OGC standard geometry type (e.g., POINT).
98+
* geometries: List of geometries as bare coordinate arrays.
99+
* callback: Function to handle the generated DataViews.
100+
136101
```js
137-
{
138-
shp: DataView(),
139-
shx: DataView(),
140-
dbf: DataView()
141-
}
102+
shpwrite.write(data, geometrytype, geometries, (err, result) => {
103+
// result is equal to
104+
// {
105+
// shp: DataView(),
106+
// shx: DataView(),
107+
// dbf: DataView()
108+
// }
109+
if (err) throw err;
110+
console.log(result);
111+
});
142112
```
143113

144114
### `zip(geojson, [options])`
145115

146116
Generate a ArrayBuffer of a zipped shapefile, dbf, and prj, from a GeoJSON
147117
object.
148118

149-
### DEPRECTEAD! May be removed in a future version
150119
### `download(geojson, [options])`
151120

152-
Given a [GeoJSON](http://geojson.org/) FeatureCollection as an object,
153-
converts convertible features into Shapefiles and triggers a download.
154-
155-
The additional `options` parameter is passed to the underlying `zip` call.
156-
157-
This is now marked as deprecated because it applies to browsers only and the
121+
> [!WARNING]
122+
> This is now marked as deprecated because it applies to browsers only and the
158123
user should instead rely on an external library for this functionality like
159124
`file-saver` or `downloadjs`
160125

126+
Given a [GeoJSON](http://geojson.org/) FeatureCollection as an object, converts convertible features into Shapefiles and triggers a download. `options` is passed to the underlying `zip` call.
127+
161128
## Other Implementations
162129

163130
- https://code.google.com/p/pyshp/
@@ -169,3 +136,4 @@ user should instead rely on an external library for this functionality like
169136
## Contributors
170137

171138
- Nick Baugh <[email protected]>
139+
- Charles Richardson <[email protected]>

0 commit comments

Comments
 (0)