diff --git a/CHANGELOG.md b/CHANGELOG.md index cbf02255..aec57a0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +v0.6.47 +* Added support for using JSON data as an argument to the -i command. +* Added an `io` object with an `io.addInputFile()` method to the `-run` command's expression context, to support loading dynamically generated datasets. + v0.6.46 * Added save to clipboard option to web UI export menu. * In -each expressions, `this.geojson` setter now accepts nulls and FeatureCollectsions in addition to single Features. diff --git a/REFERENCE.md b/REFERENCE.md index de3c806d..79daa81f 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,6 +1,6 @@ # COMMAND REFERENCE -This documentation applies to version 0.6.45 of mapshaper's command line program. Run `mapshaper -v` to check your version. For an introduction to the command line tool, read [this page](https://github.com/mbloch/mapshaper/wiki/Introduction-to-the-Command-Line-Tool) first. +This documentation applies to version 0.6.47 of mapshaper's command line program. Run `mapshaper -v` to check your version. For an introduction to the command line tool, read [this page](https://github.com/mbloch/mapshaper/wiki/Introduction-to-the-Command-Line-Tool) first. ## Command line syntax @@ -138,7 +138,7 @@ By default, multiple input files are processed separately, as if running mapshap **Options** -`` or `files=` File(s) to input (space-separated list). Use `-` to import TopoJSON or GeoJSON from `/dev/stdin`. +`` or `files=` File(s) to input (space-separated list). Use `-` to import TopoJSON or GeoJSON from `/dev/stdin`. Literal JSON data can also be used instead of a file name. `combine-files` Import multiple files to separate layers with shared topology. Useful for generating a single TopoJSON file containing multiple geometry objects. @@ -1045,11 +1045,11 @@ $ mapshaper data.json \ Create mapshaper commands on-the-fly and run them. -`` or `expression=` A JS expression for generating one or more mapshaper commands. The expression has access to a "target" object with information about the currently targeted layer, as well as modules loaded with the `-require` command. +`` or `expression=` A JS expression for generating one or more mapshaper commands. The expression has access to a "target" object with information about the currently targeted layer, as well as modules loaded with the `-require` command. In v0.6.47, an "io" object was added, with an `io.addInputFile(, )` method, to support importing dynamically generated datasets (see Example 2 below). Common options: `target=` -**Example:** Apply a custom projection based on the layer extent +**Example 1:** Apply a custom projection based on the layer extent ```bash $ mapshaper -i country.shp -require projection.js -run 'getProjCommand(target)' -o @@ -1067,6 +1067,21 @@ module.exports = { ``` +**Example 2:** Import a dynamically generated dataset + +```bash +$ mapshaper -require script.js -run 'importData(io)' -o +``` + +```javascript +// contents of script.js file +module.exports = { + importData: function(io) { + var data = [{"foo": "bar"}]; + io.addInputFile('data.json', data); + return `-i data.json`; + } +}; ### -shape diff --git a/package-lock.json b/package-lock.json index d1f1794a..5cce9c9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mapshaper", - "version": "0.6.46", + "version": "0.6.47", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mapshaper", - "version": "0.6.46", + "version": "0.6.47", "license": "MPL-2.0", "dependencies": { "@placemarkio/tokml": "^0.3.3", diff --git a/package.json b/package.json index ea7d4837..57399498 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mapshaper", - "version": "0.6.46", + "version": "0.6.47", "description": "A tool for editing vector datasets for mapping and GIS.", "keywords": [ "shapefile",