diff options
author | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-19 11:38:08 +1000 |
---|---|---|
committer | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-19 11:38:08 +1000 |
commit | c04a881049b0409242edfb019e5b3d531af2dec2 (patch) | |
tree | 4cb6d614b96d609aa2c41042793c8c94d0634cb2 | |
parent | 85e651517a70c29fc22abb3928d5d22b28c9073c (diff) |
sketch out possible MapRoulette Cooperative Challenge code for matches
-rwxr-xr-x | bin/mr.js | 81 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | yarn.lock | 14 |
3 files changed, 96 insertions, 0 deletions
diff --git a/bin/mr.js b/bin/mr.js new file mode 100755 index 0000000..a016db2 --- /dev/null +++ b/bin/mr.js @@ -0,0 +1,81 @@ +#!/usr/bin/env node + +/** + * Create a MapRoulette Cooperative Challenge from the exact matches, + * which suggests updating the OSM objects tags with those from Vicmap. + * + * https://github.com/osmlab/maproulette3/wiki/Cooperative-Challenges + */ + +// TODO need a higher level json structre +// TODO maybe these need to be grouped by block? + +const fs = require('fs') +const { Transform, pipeline } = require('stream') +const ndjson = require('ndjson') +const omit = require('object.omit') +const path = require('path') + +const argv = require('yargs/yargs')(process.argv.slice(2)) + .argv + +if (argv._.length < 2) { + console.error("Usage: ./mr.js dist/conflate dist/mr.geojson") + process.exit(1) +} + +const sourceDirectory = argv._[0] +const outputFile = argv._[1] + +if (!fs.existsSync(path.join(sourceDirectory, 'exactMatch.geojson'))) { + console.error(`${path.join(sourceDirectory, 'exactMatch.geojson')} not found`) + process.exit(1) +} + +let sourceCount = 0 +const mr = new Transform({ + readableObjectMode: true, + writableObjectMode: true, + transform(feature, encoding, callback) { + sourceCount++ + + if (process.stdout.isTTY && sourceCount % 10000 === 0) { + process.stdout.write(` ${sourceCount / 1000}k\r`) + } + + const matches = feature.properties._matches.split(',') + + for (const match of matches) { + const operation = { + operationType: 'modifyElement', + data: { + id: match, + operations: [{ + operation: 'setTags', + data: omit(feature.properties, '_matches') + }] + } + } + + this.push(operation) + } + + callback() + } +}) + +pipeline( + fs.createReadStream(path.join(sourceDirectory, 'exactMatch.geojson')), + ndjson.parse(), + mr, + ndjson.stringify(), + fs.createWriteStream(outputFile), + err => { + if (err) { + console.log(err) + process.exit(1) + } else { + process.exit(0) + } + } +) diff --git a/package.json b/package.json index df6f54b..80c099a 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "geoflatbush": "^1.0.0", "mktemp": "^1.0.0", "ndjson": "^2.0.0", + "object.omit": "^3.0.0", "polygon-lookup": "^2.6.0", "readable-stream": "^3.6.0", "tape": "^5.2.2", @@ -324,6 +324,13 @@ is-date-object@^1.0.1, is-date-object@^1.0.2: resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.2.tgz#bda736f2cd8fd06d32844e7743bfa7494c3bfd7e" integrity sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g== +is-extendable@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-1.0.1.tgz#a7470f9e426733d81bd81e1155264e3a3507cab4" + integrity sha512-arnXMxT1hhoKo9k1LZdmlNyJdDDfy2v0fXjFlmok4+i8ul/6WlbVge9bhM74OpNPQPMGUToDtz+KXa1PneJxOA== + dependencies: + is-plain-object "^2.0.4" + is-fullwidth-code-point@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" @@ -493,6 +500,13 @@ object.assign@^4.1.2: has-symbols "^1.0.1" object-keys "^1.1.1" +object.omit@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/object.omit/-/object.omit-3.0.0.tgz#0e3edc2fce2ba54df5577ff529f6d97bd8a522af" + integrity sha512-EO+BCv6LJfu+gBIF3ggLicFebFLN5zqzz/WWJlMFfkMyGth+oBkhxzDl0wx2W4GkLzuQs/FsSkXZb2IMWQqmBQ== + dependencies: + is-extendable "^1.0.0" + once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" |