forked from mapbox/shp-write
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also includes the following: * adds eslint/editorconfig * applied eslint formatting for all sources * some minor fixes discovered through linting
- Loading branch information
Showing
16 changed files
with
470 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
[*.md] | ||
indent_size = 2 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended" | ||
], | ||
"plugins": [], | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"globals": { | ||
"Promise": false, | ||
"ArrayBuffer": false, | ||
"DataView": false, | ||
"describe": false, | ||
"it": false | ||
}, | ||
"rules": { | ||
"indent": ["error", 2, { "SwitchCase": 1 }], | ||
"linebreak-style": ["error", "unix"], | ||
"quotes": ["error", "single", { "allowTemplateLiterals": true }], | ||
"semi": ["error", "always"], | ||
"one-var": ["error", "never"], | ||
"no-confusing-arrow": "error", | ||
"no-unused-vars": ["error", { | ||
"ignoreRestSiblings": true | ||
}], | ||
"key-spacing": ["error", { | ||
"beforeColon": false, | ||
"afterColon": true | ||
}], | ||
"space-infix-ops": ["error", {"int32Hint": false}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[![Build Status](https://secure.travis-ci.org/mapbox/shp-write.svg?branch=master)](http://travis-ci.org/mapbox/shp-write) | ||
|
||
# shp-write | ||
|
||
[![Build Status](https://secure.travis-ci.org/mapbox/shp-write.svg?branch=master)](http://travis-ci.org/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. | ||
|
@@ -16,26 +16,30 @@ Or in a browser | |
|
||
https://unpkg.com/shp-write@latest/shpwrite.js | ||
|
||
## Testing | ||
|
||
To test the download functionality run `npm run make-test` and open index.html in browser. | ||
This should start an immediate download of test features defined in `indexTest.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 | ||
var shpwrite = require('shp-write'); | ||
|
||
// (optional) set names for feature types and zipped folder | ||
// (optional) set names for zip file, zipped folder and feature types | ||
var options = { | ||
folder: 'myshapes', | ||
types: { | ||
point: 'mypoints', | ||
polygon: 'mypolygons', | ||
line: 'mylines' | ||
polyline: 'mylines' | ||
} | ||
} | ||
// a GeoJSON bridge for features | ||
|
@@ -95,12 +99,20 @@ object. | |
|
||
## Other Implementations | ||
|
||
* https://code.google.com/p/pyshp/ | ||
* [https://code.google.com/p/pyshp/](https://code.google.com/p/pyshp/) | ||
|
||
## Reference | ||
|
||
* http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf | ||
* [http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf](http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf) | ||
|
||
## Contributors | ||
|
||
* Nick Baugh <[email protected]> | ||
|
||
## Pull requests contained in this branch | ||
|
||
This branch includes the following PRs of the official repository: | ||
|
||
* [IE download fix](https://github.com/mapbox/shp-write/pull/50) (merged manually as the source repo is gone) | ||
* [Fix point export](https://github.com/mapbox/shp-write/pull/69) | ||
* [Fixed extraction of polygon coordinates](https://github.com/mapbox/shp-write/pull/65) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<script src='bundle.js'></script> | ||
<script src='shpwrite.js'></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require('./src/download')({ | ||
'type': 'FeatureCollection', | ||
'features': [{ | ||
'type': 'Feature', | ||
'properties': {}, | ||
'geometry': { | ||
'type': 'Polygon', | ||
'coordinates': [ | ||
[ | ||
[ | ||
24.936046600341797, | ||
60.175245406790246 | ||
], | ||
[ | ||
24.920597076416016, | ||
60.15577400466598 | ||
], | ||
[ | ||
24.953556060791016, | ||
60.1570553725571 | ||
], | ||
[ | ||
24.936046600341797, | ||
60.175245406790246 | ||
] | ||
], | ||
[ | ||
[ | ||
24.93523120880127, | ||
60.169247224327165 | ||
], | ||
[ | ||
24.945573806762695, | ||
60.15874243076889 | ||
], | ||
[ | ||
24.928064346313477, | ||
60.15825127085746 | ||
], | ||
[ | ||
24.93523120880127, | ||
60.169247224327165 | ||
] | ||
] | ||
] | ||
} | ||
}, | ||
{ | ||
'type': 'Feature', | ||
'properties': {}, | ||
'geometry': { | ||
'type': 'LineString', | ||
'coordinates': [ | ||
[ | ||
24.920940399169922, | ||
60.17977000114811 | ||
], | ||
[ | ||
24.953556060791016, | ||
60.17486121440947 | ||
] | ||
] | ||
} | ||
}, | ||
{ | ||
'type': 'Feature', | ||
'properties': {}, | ||
'geometry': { | ||
'type': 'Point', | ||
'coordinates': [ | ||
24.925403594970703, | ||
60.171830205844614 | ||
] | ||
} | ||
} | ||
] | ||
}, { | ||
file: 'shapefiles', | ||
folder: 'shapefiles', | ||
types: { | ||
point: 'points', | ||
polygon: 'polygons', | ||
polyline: 'lines' | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
var zip = require('./zip'); | ||
var saveAs = require('file-saver').saveAs; | ||
|
||
module.exports = function(gj, options) { | ||
var content = zip(gj, options); | ||
location.href = 'data:application/zip;base64,' + content; | ||
zip(gj, options).then(function(blob) { saveAs(blob, options.file + '.zip'); }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
module.exports.enlarge = function enlargeExtent(extent, pt) { | ||
if (pt[0] < extent.xmin) extent.xmin = pt[0]; | ||
if (pt[0] > extent.xmax) extent.xmax = pt[0]; | ||
if (pt[1] < extent.ymin) extent.ymin = pt[1]; | ||
if (pt[1] > extent.ymax) extent.ymax = pt[1]; | ||
return extent; | ||
if (pt[0] < extent.xmin) extent.xmin = pt[0]; | ||
if (pt[0] > extent.xmax) extent.xmax = pt[0]; | ||
if (pt[1] < extent.ymin) extent.ymin = pt[1]; | ||
if (pt[1] > extent.ymax) extent.ymax = pt[1]; | ||
return extent; | ||
}; | ||
|
||
module.exports.enlargeExtent = function enlargeExtent(extent, ext) { | ||
if (ext.xmax > extent.xmax) extent.xmax = ext.xmax; | ||
if (ext.xmin < extent.xmin) extent.xmin = ext.xmin; | ||
if (ext.ymax > extent.ymax) extent.ymax = ext.ymax; | ||
if (ext.ymin < extent.ymin) extent.ymin = ext.ymin; | ||
return extent; | ||
if (ext.xmax > extent.xmax) extent.xmax = ext.xmax; | ||
if (ext.xmin < extent.xmin) extent.xmin = ext.xmin; | ||
if (ext.ymax > extent.ymax) extent.ymax = ext.ymax; | ||
if (ext.ymin < extent.ymin) extent.ymin = ext.ymin; | ||
return extent; | ||
}; | ||
|
||
module.exports.blank = function() { | ||
return { | ||
xmin: Number.MAX_VALUE, | ||
ymin: Number.MAX_VALUE, | ||
xmax: -Number.MAX_VALUE, | ||
ymax: -Number.MAX_VALUE | ||
}; | ||
return { | ||
xmin: Number.MAX_VALUE, | ||
ymin: Number.MAX_VALUE, | ||
xmax: -Number.MAX_VALUE, | ||
ymax: -Number.MAX_VALUE | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.