Skip to content

Commit

Permalink
Add custom projection
Browse files Browse the repository at this point in the history
  • Loading branch information
sheindel committed Aug 23, 2023
1 parent ebded5b commit d3773a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ const zipData = shpwrite.zip(
);
```

## Custom .prj file
To pass a custom [WKT string](http://www.opengeospatial.org/standards/wkt-crs) in the .prj file to define a different projection the prj option can be used:

```js
var options = {
prj: 'PROJCS["Amersfoort / RD New",GEOGCS["Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Stereographic_North_Pole"],PARAMETER["standard_parallel_1",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["Meter",1]]'
}
```

## API
### `write(data, geometrytype, geometries, callback)`

Expand Down
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare module "@mapbox/shp-write" {
export interface DownloadOptions {
folder?: string;
filename?: string;
prj?: string;
types?: {
point?: string;
polygon?: string;
Expand Down
4 changes: 2 additions & 2 deletions indexTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ require('./src/download')({
}
]
}, {
file: 'shapefiles',
folder: 'shapefiles',
file: 'my_zip_filename', // if empty, filename will be download.zip
folder: 'my_internal_shapes_folder', // leave empty to put in root
outputType: 'blob',
compression: 'DEFLATE',
types: {
Expand Down
11 changes: 7 additions & 4 deletions src/zip.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var write = require("./write"),
geojson = require("./geojson"),
prj = require("./prj"),
JSZip = require("jszip");
var write = require("./write");
var geojson = require("./geojson");
var defaultPrj = require('./prj');
var JSZip = require("jszip");


module.exports = function (
gj,
Expand All @@ -14,6 +15,8 @@ module.exports = function (
zipTarget = zip.folder(options.folder);
}

var prj = (options && options.prj) ? options.prj : defaultPrj;

[
geojson.point(gj),
geojson.line(gj),
Expand Down

0 comments on commit d3773a5

Please sign in to comment.