[
  {
    "path": ".gitignore",
    "content": "node_modules\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js:\n  - \"0.8\"\n  - \"0.10\"\nbefore_install:\n  - npm install -g npm@~1.4.6\n"
  },
  {
    "path": "CODEOWNERS",
    "content": "*   @mapbox/maps"
  },
  {
    "path": "LICENSE.txt",
    "content": "\nISC License\n\nCopyright (c) 2017, Mapbox\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\nWITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\nANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\nOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.<Paste>\n"
  },
  {
    "path": "README.md",
    "content": "# geojson-merge\n\n[![build status](https://secure.travis-ci.org/mapbox/geojson-merge.png)](http://travis-ci.org/mapbox/geojson-merge)\n\nMerge multiple [GeoJSON](http://geojson.org/) files into one FeatureCollection.\n\n## install\n\n```bash\n$ npm install --save @mapbox/geojson-merge\n```\n\n## API\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n### merge\n\nMerge a series of GeoJSON objects into one FeatureCollection containing all\nfeatures in all files.  The objects can be any valid GeoJSON root object,\nincluding FeatureCollection, Feature, and Geometry types.\n\n**Parameters**\n\n-   `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>** a list of GeoJSON objects of any type\n\n**Examples**\n\n```javascript\nvar geojsonMerge = require('@mapbox/geojson-merge');\n\nvar mergedGeoJSON = geojsonMerge.merge([\n  { type: 'Point', coordinates: [0, 1] },\n  { type: 'Feature', geometry: { type: 'Point', coordinates: [0, 1] }, properties: {} }\n]);\n\nconsole.log(JSON.stringify(mergedGeoJSON));\n```\n\nReturns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** a geojson FeatureCollection.\n\n### mergeFeatureCollectionStream\n\nMerge GeoJSON files containing GeoJSON FeatureCollections\ninto a single stream of a FeatureCollection as a JSON string.\n\nThis is more limited than merge - it only supports FeatureCollections\nas input - but more performant, since it can operate on GeoJSON files\nlarger than what you can keep in memory at one time.\n\n**Parameters**\n\n-   `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** a list of filenames of GeoJSON files\n\n**Examples**\n\n```javascript\nvar geojsonMerge = require('@mapbox/geojson-merge');\n\nvar mergedStream = geojsonMerge.mergeFeatureCollectionStream([\n  'features.geojson',\n  'otherFeatures.geojson'])\n\nmergedStream.pipe(process.stdout);\n```\n\nReturns **[Stream](https://nodejs.org/api/stream.html)** output: a stringified JSON of a FeatureCollection.\n\n## cli\n\nOptions:\n\n> `-s` or `--stream` to use the high-performance streaming mode. This allows\n> you to combine very large GeoJSON files. Streaming mode requires every\n> GeoJSON file to contain a FeatureCollection at the top level.\n\n```bash\n$ npm install -g @mapbox/geojson-merge\n$ geojson-merge file.geojson otherfile.geojson > combined.geojson\n```\n\n## geojson-merge (for dummies)\n\n### Windows Instructions:\n\n1.  Start the `node.js` application  \n2.  Open `cmd.exe`  \n3.  Browse to a folder where you'd like `geojson-merge` installed  \n4.  In `cmd.exe` type the install string from above  \n5.  Wait patiently, it could take a moment to start  \n6.  Use `cd node_modules` to change directory  to the `node_modules` folder  \n7.  For simplicity sake, move your .geojson files into this `node_modules` directory  \n8.  Run this command to merge your files:  \n\n```bash\n$ node geojson-merge file1.geojson file2.geojson > merged.geojson\n```\n\n**Merging multiple files in a folder**\n\n```bash\n$ geojson-merge folder/*.geojson > combined.geojson\n```\n"
  },
  {
    "path": "fixtures/featureCollection.geojson",
    "content": "{\n  \"type\": \"FeatureCollection\",\n  \"features\": [\n    {\n      \"type\": \"Feature\",\n      \"properties\": {},\n      \"geometry\": {\n        \"type\": \"Polygon\",\n        \"coordinates\": [\n          [\n            [\n              13.7109375,\n              47.100044694025215\n            ],\n            [\n              13.7109375,\n              48.151428143221224\n            ],\n            [\n              15.710449218749998,\n              48.151428143221224\n            ],\n            [\n              15.710449218749998,\n              47.100044694025215\n            ],\n            [\n              13.7109375,\n              47.100044694025215\n            ]\n          ]\n        ]\n      }\n    }\n  ]\n}\n"
  },
  {
    "path": "geojson-merge",
    "content": "#!/usr/bin/env node\nvar geojsonMerge = require('./'),\n    stream = geojsonMerge.mergeFeatureCollectionStream,\n    merge = geojsonMerge.merge,\n    fs = require('fs'),\n    argv = require('minimist')(process.argv.slice(2));\n\nif (!argv._.length || argv.help) {\n  console.log('usage: geojson-merge [-s] FILE FILE2 FILE3');\n  console.log('\\n  --stream (or -s): use streaming mode for large files');\n  return;\n}\n\nif (argv.s || argv.stream) {\n  stream(argv._).pipe(process.stdout)\n} else {\n  process.stdout.write(JSON.stringify(merge(argv._.map(function(n) {\n      return JSON.parse(fs.readFileSync(n));\n  })), null, 2));\n}\n"
  },
  {
    "path": "index.js",
    "content": "var normalize = require('@mapbox/geojson-normalize');\nvar geojsonStream = require('geojson-stream');\nvar fs = require('fs');\n\n/**\n * Merge a series of GeoJSON objects into one FeatureCollection containing all\n * features in all files.  The objects can be any valid GeoJSON root object,\n * including FeatureCollection, Feature, and Geometry types.\n *\n * @param {Array<Object>} inputs a list of GeoJSON objects of any type\n * @return {Object} a geojson FeatureCollection.\n * @example\n * var geojsonMerge = require('@mapbox/geojson-merge');\n *\n * var mergedGeoJSON = geojsonMerge.merge([\n *   { type: 'Point', coordinates: [0, 1] },\n *   { type: 'Feature', geometry: { type: 'Point', coordinates: [0, 1] }, properties: {} }\n * ]);\n *\n * console.log(JSON.stringify(mergedGeoJSON));\n */\nfunction merge (inputs) {\n    var output = {\n        type: 'FeatureCollection',\n        features: []\n    };\n    for (var i = 0; i < inputs.length; i++) {\n        var normalized = normalize(inputs[i]);\n        for (var j = 0; j < normalized.features.length; j++) {\n            output.features.push(normalized.features[j]);\n        }\n    }\n    return output;\n}\n\n/**\n * Merge GeoJSON files containing GeoJSON FeatureCollections\n * into a single stream of a FeatureCollection as a JSON string.\n *\n * This is more limited than merge - it only supports FeatureCollections\n * as input - but more performant, since it can operate on GeoJSON files\n * larger than what you can keep in memory at one time.\n * @param {Array<string>} inputs a list of filenames of GeoJSON files\n * @returns {Stream} output: a stringified JSON of a FeatureCollection.\n * @example\n * var geojsonMerge = require('@mapbox/geojson-merge');\n *\n * var mergedStream = geojsonMerge.mergeFeatureCollectionStream([\n *   'features.geojson',\n *   'otherFeatures.geojson'])\n *\n * mergedStream.pipe(process.stdout);\n */\nfunction mergeFeatureCollectionStream (inputs) {\n    var out = geojsonStream.stringify();\n    inputs.forEach(function(file) {\n        fs.createReadStream(file)\n            .pipe(geojsonStream.parse())\n            .pipe(out);\n    });\n    return out;\n}\n\nmodule.exports.merge = merge;\nmodule.exports.mergeFeatureCollectionStream = mergeFeatureCollectionStream;\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"@mapbox/geojson-merge\",\n  \"version\": \"1.1.1\",\n  \"description\": \"merge multiple geojson files\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"tape test.js\",\n    \"doc\": \"documentation readme -s API\"\n  },\n  \"bin\": {\n    \"geojson-merge\": \"geojson-merge\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git@github.com:mapbox/geojson-merge.git\"\n  },\n  \"keywords\": [\n    \"geojson\",\n    \"merge\",\n    \"featurecollection\"\n  ],\n  \"author\": \"Tom MacWright\",\n  \"license\": \"ISC\",\n  \"bugs\": {\n    \"url\": \"https://github.com/mapbox/geojson-merge/issues\"\n  },\n  \"homepage\": \"https://github.com/mapbox/geojson-merge\",\n  \"dependencies\": {\n    \"@mapbox/geojson-normalize\": \"^0.0.1\",\n    \"geojson-fixtures\": \"~0.1.0\",\n    \"geojson-stream\": \"0.0.1\",\n    \"minimist\": \"^1.2.0\",\n    \"stream-concat\": \"0.1.0\",\n    \"tape\": \"^4.9.0\"\n  },\n  \"devDependencies\": {\n    \"concat-stream\": \"^1.6.0\",\n    \"cz-conventional-changelog\": \"1.2.0\",\n    \"documentation\": \"^4.0.0-beta.18\"\n  },\n  \"config\": {\n    \"commitizen\": {\n      \"path\": \"./node_modules/cz-conventional-changelog\"\n    }\n  }\n}\n"
  },
  {
    "path": "test.js",
    "content": "var geojsonMerge = require('./'),\n    test = require('tape'),\n    fixtures = require('geojson-fixtures')\n    concat = require('concat-stream');\n\n\ntest('merge', function(t) {\n    t.equal(geojsonMerge.merge([fixtures.geometry.point, fixtures.feature.one]).features.length, 2);\n    t.end();\n});\n\ntest('streaming merge', function (t) {\n    var stream = geojsonMerge.mergeFeatureCollectionStream(['fixtures/featureCollection.geojson', 'fixtures/featureCollection.geojson'], { stream: true });\n    t.equal(typeof stream, 'object');\n    t.equal(typeof stream.pipe,'function');\n    stream.pipe(concat(function (combined) {\n        t.equal(JSON.parse(combined).features.length, 2);\n        t.end();\n    }));\n});\n"
  }
]