Skip to content

Commit 914ebd2

Browse files
Update README.md
Improve all the other sections of the README
1 parent c02e9ce commit 914ebd2

File tree

1 file changed

+33
-67
lines changed

1 file changed

+33
-67
lines changed

README.md

Lines changed: 33 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# shp-write
1+
# @mapbox/shp-write
22

3-
Writes shapefile in pure javascript.
4-
5-
Uses [dbf](https://github.com/tmcw/dbf)
6-
for the data component, and [jsZIP](http://stuk.github.io/jszip/) to generate
7-
ZIP file downloads in-browser.
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.
85

96
> [!IMPORTANT]
107
> **The package location for this repo has changed!**
@@ -14,34 +11,32 @@ ZIP file downloads in-browser.
1411

1512
## Usage
1613

17-
For npm
14+
NPM
1815

1916
npm install --save @mapbox/shp-write
2017

2118
Yarn
2219

2320
yarn add @mapbox/shp-write
2421

25-
Or in a browser
22+
Browser
2623

2724
https://unpkg.com/@mapbox/shp-write@latest/shpwrite.js
2825

2926
## Caveats
3027

3128
- Requires a capable fancy modern browser with [Typed Arrays](http://caniuse.com/#feat=typedarrays)
3229
support
33-
- Geometries: Point, LineString, Polygon, MultiLineString, MultiPolygon
34-
- 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)
3532
- Uses jsZip for ZIP files, but [compression is buggy](https://github.com/Stuk/jszip/issues/53) so it uses STORE instead of DEFLATE.
3633

37-
## Minimal Example
34+
## Example
3835

3936
```js
4037
var shpwrite = require("@mapbox/shp-write");
4138

42-
// a GeoJSON bridge for features
43-
const zipData = shpwrite.zip(
44-
{
39+
const geoJSON = {
4540
type: "FeatureCollection",
4641
features: [
4742
{
@@ -65,16 +60,9 @@ const zipData = shpwrite.zip(
6560
},
6661
},
6762
],
68-
}
69-
);
70-
71-
```
72-
73-
## Options Example
74-
75-
```js
76-
var shpwrite = require("@mapbox/shp-write");
63+
};
7764

65+
// Optional custom options passed to the underlying `zip` call
7866
const options = {
7967
folder: "my_internal_shapes_folder",
8068
filename: "my_zip_filename",
@@ -87,35 +75,7 @@ const options = {
8775
},
8876
};
8977

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

12181
## Custom .prj file
@@ -128,37 +88,43 @@ var options = {
12888
```
12989

13090
## API
91+
13192
### `write(data, geometrytype, geometries, callback)`
13293

133-
Given data, an array of objects for each row of data, geometry, the OGC standard
134-
geometry type (like `POINT`), geometries, a list of geometries as bare coordinate
135-
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.
13695

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+
137101
```js
138-
{
139-
shp: DataView(),
140-
shx: DataView(),
141-
dbf: DataView()
142-
}
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+
});
143112
```
144113

145114
### `zip(geojson, [options])`
146115

147116
Generate a ArrayBuffer of a zipped shapefile, dbf, and prj, from a GeoJSON
148117
object.
149118

150-
### DEPRECTEAD! May be removed in a future version
151119
### `download(geojson, [options])`
152120

153-
Given a [GeoJSON](http://geojson.org/) FeatureCollection as an object,
154-
converts convertible features into Shapefiles and triggers a download.
155-
156-
The additional `options` parameter is passed to the underlying `zip` call.
157-
158-
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
159123
user should instead rely on an external library for this functionality like
160124
`file-saver` or `downloadjs`
161125

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+
162128
## Other Implementations
163129

164130
- https://code.google.com/p/pyshp/

0 commit comments

Comments
 (0)