├── .eslintrc ├── README.md ├── cli.js ├── definitions.json ├── index.js └── package.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-unstyled" 3 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # turf-cli 2 | 3 | [![Circle CI](https://circleci.com/gh/Turfjs/turf-cli.svg?style=svg)](https://circleci.com/gh/Turfjs/turf-cli) 4 | 5 | A command-line interface to the [Turf](https://github.com/Turfjs/turf) library. This is autogenerated 6 | from [Turf documentation](https://github.com/Turfjs/turf-www) and features all turf operations. 7 | 8 | ## installation 9 | 10 | npm install -g turf-cli 11 | 12 | ## usage 13 | 14 | Generate random points 15 | 16 | turf random points 1000 {} > randompoints.geojson 17 | 18 | Sample 10 points from that set 19 | 20 | turf sample randompoints.geojson 10 21 | 22 | Documentation 23 | 24 | turf -h 25 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var turf = require('turf'), 4 | chalk = require('chalk'), 5 | fs = require('fs'), 6 | getStdin = require('get-stdin'), 7 | defs = require('./definitions.json'), 8 | argv = require('minimist')(process.argv.slice(2), { 9 | boolean: ['h', 'help'] 10 | }); 11 | 12 | function isGeoJsonArgument(type) { 13 | return type.type === 'NameExpression' && 14 | ['FeatureCollection', 'Feature', 'Point', 'GeoJSON', 'Geometry', 15 | 'LineString', 'Polygon', 'MultiPolygon', 'MultiPoint'] 16 | .indexOf(type.name) !== -1; 17 | } 18 | 19 | function isJsonArgument(type) { 20 | return (type.type === 'NameExpression' && 21 | type.name === 'Object') || 22 | (type.type === 'TypeApplication' && 23 | type.expression.name === 'Array'); 24 | } 25 | 26 | function isBooleanArgument(type) { 27 | return type.type === 'NameExpression' && type.name === 'boolean'; 28 | } 29 | 30 | function parseArguments(def, argv, stdin) { 31 | if ((argv._.length - 1) !== def.params.length) { 32 | console.log('Definition %s requires %s arguments, given %s', 33 | def.name, def.params.length, argv._.length - 1); 34 | showParams(def.params); 35 | throw new Error('invalid argument length given'); 36 | } 37 | var args = []; 38 | def.params.forEach(function(param, i) { 39 | var arg = argv._[i + 1]; 40 | if (isGeoJsonArgument(param.type) || isJsonArgument(param.type)) { 41 | args.push(getJsonFromArg(def, arg, stdin)); 42 | } else if (isBooleanArgument(param.type)) { 43 | args.push(JSON.parse(arg)); // parses 'false' to false 44 | } else { 45 | args.push(arg); 46 | } 47 | }); 48 | return args; 49 | } 50 | 51 | var usedStdin = false 52 | function getJsonFromArg(def, arg, stdin) { 53 | if (arg === '-' && usedStdin) { 54 | console.log('STDIN ("-") can only be used once for JSON/GeoJSON input'); 55 | showParams(def.params); 56 | throw new Error('stdin used for multiple file arguments'); 57 | } 58 | 59 | var raw 60 | if (arg === '-') { 61 | raw = stdin 62 | usedStdin = true 63 | } else { 64 | try { 65 | // throws for a nonexistent file 66 | raw = fs.readFileSync(arg) 67 | } catch (e) { 68 | // if `arg` doesn't point to a file, fall back to treating it as literal JSON 69 | raw = arg 70 | } 71 | } 72 | 73 | try { 74 | return JSON.parse(raw); 75 | } catch (e) { 76 | console.log("Could not parse JSON: ", raw); 77 | } 78 | } 79 | 80 | function showParams(params) { 81 | params.forEach(function(p) { 82 | console.log(' %s\t%s', chalk.bold(p.name), p.description); 83 | }); 84 | } 85 | 86 | function getDef(name) { 87 | return defs.filter(function(def) { 88 | return def.name === name; 89 | })[0]; 90 | } 91 | 92 | function help() { 93 | console.log(chalk.green('turf')); 94 | defs.forEach(function(def) { 95 | console.log(''); 96 | console.log(' ' + chalk.bold(def.name)); 97 | console.log(' ' + def.description); 98 | console.log(''); 99 | showParams(def.params); 100 | }); 101 | } 102 | 103 | (function() { 104 | if (argv.h || argv.help || !argv._.length) { 105 | help(); 106 | process.exit(0); 107 | } 108 | var op = argv._[0]; 109 | if (!turf[op]) { 110 | help(); 111 | throw new Error('turf operation ' + op + ' not found'); 112 | } 113 | var def = getDef(argv._[0]); 114 | getStdin().then(function (stdin) { 115 | var args = parseArguments(def, argv, stdin); 116 | console.log(JSON.stringify(turf[op].apply(null, args), null, 2)); 117 | }); 118 | })(); 119 | -------------------------------------------------------------------------------- /definitions.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "aggregate", 4 | "description": "Calculates a series of aggregations for a set of {@link Point} features within a set of {@link Polygon} features. Sum, average, count, min, max, and deviation are supported.", 5 | "params": [ 6 | { 7 | "title": "param", 8 | "description": "a FeatureCollection of {@link Polygon} features", 9 | "lineNumber": 5, 10 | "type": { 11 | "type": "NameExpression", 12 | "name": "FeatureCollection" 13 | }, 14 | "name": "polygons" 15 | }, 16 | { 17 | "title": "param", 18 | "description": "a FeatureCollection of {@link Point} features", 19 | "lineNumber": 6, 20 | "type": { 21 | "type": "NameExpression", 22 | "name": "FeatureCollection" 23 | }, 24 | "name": "points" 25 | }, 26 | { 27 | "title": "param", 28 | "description": "an array of aggregation objects", 29 | "lineNumber": 7, 30 | "type": { 31 | "type": "NameExpression", 32 | "name": "Array" 33 | }, 34 | "name": "aggregations" 35 | } 36 | ] 37 | }, 38 | { 39 | "name": "along", 40 | "description": "Takes a {@link LineString} feature and returns a {@link Point} feature at a specified distance along a line.", 41 | "params": [ 42 | { 43 | "title": "param", 44 | "description": "a LineString feature", 45 | "lineNumber": 5, 46 | "type": { 47 | "type": "NameExpression", 48 | "name": "LineString" 49 | }, 50 | "name": "line" 51 | }, 52 | { 53 | "title": "param", 54 | "description": "distance along the line", 55 | "lineNumber": 6, 56 | "type": { 57 | "type": "NameExpression", 58 | "name": "Number" 59 | }, 60 | "name": "distance" 61 | }, 62 | { 63 | "title": "param", 64 | "description": "can be degrees, radians, miles, or kilometers", 65 | "lineNumber": 7, 66 | "type": { 67 | "type": "OptionalType", 68 | "expression": { 69 | "type": "NameExpression", 70 | "name": "String" 71 | } 72 | }, 73 | "name": "units", 74 | "default": "miles" 75 | } 76 | ] 77 | }, 78 | { 79 | "name": "area", 80 | "description": "Takes a {@link GeoJSON} feature or {@link FeatureCollection} of any type and returns the area of that feature\nin square meters.", 81 | "params": [ 82 | { 83 | "title": "param", 84 | "description": "a {@link Feature} or {@link FeatureCollection} of any type", 85 | "lineNumber": 6, 86 | "type": { 87 | "type": "NameExpression", 88 | "name": "GeoJSON" 89 | }, 90 | "name": "input" 91 | } 92 | ] 93 | }, 94 | { 95 | "name": "average", 96 | "description": "Calculates the average value of a field for a set of {@link Point} features within a set of {@link Polygon} features.", 97 | "params": [ 98 | { 99 | "title": "param", 100 | "description": "a FeatureCollection of {@link Polygon} features", 101 | "lineNumber": 5, 102 | "type": { 103 | "type": "NameExpression", 104 | "name": "FeatureCollection" 105 | }, 106 | "name": "polygons" 107 | }, 108 | { 109 | "title": "param", 110 | "description": "a FeatureCollection of {@link Point} features", 111 | "lineNumber": 6, 112 | "type": { 113 | "type": "NameExpression", 114 | "name": "FeatureCollection" 115 | }, 116 | "name": "points" 117 | }, 118 | { 119 | "title": "param", 120 | "description": "the field in the `points` features from which to pull values to average", 121 | "lineNumber": 7, 122 | "type": { 123 | "type": "NameExpression", 124 | "name": "string" 125 | }, 126 | "name": "field" 127 | }, 128 | { 129 | "title": "param", 130 | "description": "the field in the `polygons` FeatureCollection to put results of the averages", 131 | "lineNumber": 8, 132 | "type": { 133 | "type": "NameExpression", 134 | "name": "string" 135 | }, 136 | "name": "outputField" 137 | } 138 | ] 139 | }, 140 | { 141 | "name": "bboxPolygon", 142 | "description": "Takes a bbox and returns the equivalent {@link Polygon} feature.", 143 | "params": [ 144 | { 145 | "title": "param", 146 | "description": "an Array of bounding box coordinates in the form: ```[xLow, yLow, xHigh, yHigh]```", 147 | "lineNumber": 5, 148 | "type": { 149 | "type": "TypeApplication", 150 | "expression": { 151 | "type": "NameExpression", 152 | "name": "Array" 153 | }, 154 | "applications": [ 155 | { 156 | "type": "NameExpression", 157 | "name": "number" 158 | } 159 | ] 160 | }, 161 | "name": "bbox" 162 | } 163 | ] 164 | }, 165 | { 166 | "name": "bearing", 167 | "description": "Takes two {@link Point} features and finds the bearing between them.", 168 | "params": [ 169 | { 170 | "title": "param", 171 | "description": "starting Point", 172 | "lineNumber": 5, 173 | "type": { 174 | "type": "NameExpression", 175 | "name": "Point" 176 | }, 177 | "name": "start" 178 | }, 179 | { 180 | "title": "param", 181 | "description": "ending Point", 182 | "lineNumber": 6, 183 | "type": { 184 | "type": "NameExpression", 185 | "name": "Point" 186 | }, 187 | "name": "end" 188 | } 189 | ] 190 | }, 191 | { 192 | "name": "bezier", 193 | "description": "Takes a {@link LineString} feature and returns a curved version of the line\nby applying a [Bezier spline](http://en.wikipedia.org/wiki/B%C3%A9zier_spline)\nalgorithm.\n\nThe bezier spline implementation is by [Leszek Rybicki](http://leszek.rybicki.cc/).", 194 | "params": [ 195 | { 196 | "title": "param", 197 | "description": "the input LineString", 198 | "lineNumber": 9, 199 | "type": { 200 | "type": "NameExpression", 201 | "name": "LineString" 202 | }, 203 | "name": "line" 204 | }, 205 | { 206 | "title": "param", 207 | "description": "time in milliseconds between points", 208 | "lineNumber": 10, 209 | "type": { 210 | "type": "OptionalType", 211 | "expression": { 212 | "type": "NameExpression", 213 | "name": "number" 214 | } 215 | }, 216 | "name": "resolution", 217 | "default": "10000" 218 | }, 219 | { 220 | "title": "param", 221 | "description": "a measure of how curvy the path should be between splines", 222 | "lineNumber": 11, 223 | "type": { 224 | "type": "OptionalType", 225 | "expression": { 226 | "type": "NameExpression", 227 | "name": "number" 228 | } 229 | }, 230 | "name": "sharpness", 231 | "default": "0.85" 232 | } 233 | ] 234 | }, 235 | { 236 | "name": "buffer", 237 | "description": "Calculates a buffer for a {@link Point}, {@link LineString}, or {@link Polygon} {@link Feature}/{@link FeatureCollection} for a given radius. Units supported are miles, kilometers, and degrees.", 238 | "params": [ 239 | { 240 | "title": "param", 241 | "description": "a Feature or FeatureCollection of any type", 242 | "lineNumber": 5, 243 | "type": { 244 | "type": "NameExpression", 245 | "name": "FeatureCollection" 246 | }, 247 | "name": "feature" 248 | }, 249 | { 250 | "title": "param", 251 | "description": "distance to draw the buffer", 252 | "lineNumber": 6, 253 | "type": { 254 | "type": "NameExpression", 255 | "name": "Number" 256 | }, 257 | "name": "distance" 258 | }, 259 | { 260 | "title": "param", 261 | "description": "'miles' or 'kilometers'", 262 | "lineNumber": 7, 263 | "type": { 264 | "type": "NameExpression", 265 | "name": "String" 266 | }, 267 | "name": "unit" 268 | } 269 | ] 270 | }, 271 | { 272 | "name": "center", 273 | "description": "Takes a {@link FeatureCollection} of any type and returns the absolute center point of all features.", 274 | "params": [ 275 | { 276 | "title": "param", 277 | "description": "a FeatureCollection of any type", 278 | "lineNumber": 5, 279 | "type": { 280 | "type": "NameExpression", 281 | "name": "FeatureCollection" 282 | }, 283 | "name": "features" 284 | } 285 | ] 286 | }, 287 | { 288 | "name": "centroid", 289 | "description": "Takes a {@link Feature} or {@link FeatureCollection} of any type and calculates the centroid using the arithmetic mean of all vertices.\nThis lessens the effect of small islands and artifacts when calculating\nthe centroid of a set of polygons.", 290 | "params": [ 291 | { 292 | "title": "param", 293 | "description": "a {@link Feature} or FeatureCollection of any type", 294 | "lineNumber": 7, 295 | "type": { 296 | "type": "NameExpression", 297 | "name": "GeoJSON" 298 | }, 299 | "name": "features" 300 | } 301 | ] 302 | }, 303 | { 304 | "name": "combine", 305 | "description": "Combines a {@link FeatureCollection} of {@link Point}, {@link LineString}, or {@link Polygon} features into {@link MultiPoint}, {@link MultiLineString}, or {@link MultiPolygon} features.", 306 | "params": [ 307 | { 308 | "title": "param", 309 | "description": "a FeatureCollection of any type", 310 | "lineNumber": 5, 311 | "type": { 312 | "type": "NameExpression", 313 | "name": "FeatureCollection" 314 | }, 315 | "name": "fc" 316 | } 317 | ] 318 | }, 319 | { 320 | "name": "concave", 321 | "description": "Takes a {@link FeatureCollection} of {@link Point} features and\nreturns a concave hull.\n\nInternally, this implements\na [Monotone chain algorithm](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain#JavaScript).", 322 | "params": [ 323 | { 324 | "title": "param", 325 | "description": "a FeatureCollection of {@link Point} features", 326 | "lineNumber": 9, 327 | "type": { 328 | "type": "NameExpression", 329 | "name": "FeatureCollection" 330 | }, 331 | "name": "points" 332 | }, 333 | { 334 | "title": "param", 335 | "description": "the size of an edge necessary for part of the\nhull to become concave (in miles)", 336 | "lineNumber": 10, 337 | "type": { 338 | "type": "NameExpression", 339 | "name": "number" 340 | }, 341 | "name": "maxEdge" 342 | }, 343 | { 344 | "title": "param", 345 | "description": "used for maxEdge distance (miles or kilometers)", 346 | "lineNumber": 12, 347 | "type": { 348 | "type": "NameExpression", 349 | "name": "String" 350 | }, 351 | "name": "units" 352 | } 353 | ] 354 | }, 355 | { 356 | "name": "convex", 357 | "description": "Takes any {@link GeoJSON} object and returns a\n[convex hull](http://en.wikipedia.org/wiki/Convex_hull) polygon.\n\nInternally this uses\nthe [convex-hull](https://github.com/mikolalysenko/convex-hull) module that\nimplements a [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).", 358 | "params": [ 359 | { 360 | "title": "param", 361 | "description": "any GeoJSON object", 362 | "lineNumber": 10, 363 | "type": { 364 | "type": "NameExpression", 365 | "name": "GeoJSON" 366 | }, 367 | "name": "input" 368 | } 369 | ] 370 | }, 371 | { 372 | "name": "count", 373 | "description": "Takes a {@link FeatureCollection} of {@link Point} features and a {@link FeatureCollection} of {@link Polygon} features and calculates the number of points that fall within the set of polygons.", 374 | "params": [ 375 | { 376 | "title": "param", 377 | "description": "a FeatureCollection of {@link Polygon} features", 378 | "lineNumber": 5, 379 | "type": { 380 | "type": "NameExpression", 381 | "name": "FeatureCollection" 382 | }, 383 | "name": "polygons" 384 | }, 385 | { 386 | "title": "param", 387 | "description": "a FeatureCollection of {@link Point} features", 388 | "lineNumber": 6, 389 | "type": { 390 | "type": "NameExpression", 391 | "name": "FeatureCollection" 392 | }, 393 | "name": "points" 394 | }, 395 | { 396 | "title": "param", 397 | "description": "a field to append to the attributes of the Polygon features representing Point counts", 398 | "lineNumber": 7, 399 | "type": { 400 | "type": "NameExpression", 401 | "name": "String" 402 | }, 403 | "name": "countField" 404 | } 405 | ] 406 | }, 407 | { 408 | "name": "destination", 409 | "description": "Takes a {@link Point} feature and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees. This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.", 410 | "params": [ 411 | { 412 | "title": "param", 413 | "description": "a Point feature at the starting point", 414 | "lineNumber": 5, 415 | "type": { 416 | "type": "NameExpression", 417 | "name": "Point" 418 | }, 419 | "name": "start" 420 | }, 421 | { 422 | "title": "param", 423 | "description": "distance from the starting point", 424 | "lineNumber": 6, 425 | "type": { 426 | "type": "NameExpression", 427 | "name": "Number" 428 | }, 429 | "name": "distance" 430 | }, 431 | { 432 | "title": "param", 433 | "description": "ranging from -180 to 180", 434 | "lineNumber": 7, 435 | "type": { 436 | "type": "NameExpression", 437 | "name": "Number" 438 | }, 439 | "name": "bearing" 440 | }, 441 | { 442 | "title": "param", 443 | "description": "miles, kilometers, degrees, or radians", 444 | "lineNumber": 8, 445 | "type": { 446 | "type": "NameExpression", 447 | "name": "String" 448 | }, 449 | "name": "units" 450 | } 451 | ] 452 | }, 453 | { 454 | "name": "deviation", 455 | "description": "Calculates the standard deviation value of a field for points within a set of polygons.", 456 | "params": [ 457 | { 458 | "title": "param", 459 | "description": "a FeatureCollection of {@link Polygon} features", 460 | "lineNumber": 5, 461 | "type": { 462 | "type": "NameExpression", 463 | "name": "FeatureCollection" 464 | }, 465 | "name": "polygons" 466 | }, 467 | { 468 | "title": "param", 469 | "description": "a FeatureCollection of {@link Point} features", 470 | "lineNumber": 6, 471 | "type": { 472 | "type": "NameExpression", 473 | "name": "FeatureCollection" 474 | }, 475 | "name": "points" 476 | }, 477 | { 478 | "title": "param", 479 | "description": "the field in `points` from which to aggregate", 480 | "lineNumber": 7, 481 | "type": { 482 | "type": "NameExpression", 483 | "name": "String" 484 | }, 485 | "name": "inField" 486 | }, 487 | { 488 | "title": "param", 489 | "description": "the field to append to `polygons` representing deviation", 490 | "lineNumber": 8, 491 | "type": { 492 | "type": "NameExpression", 493 | "name": "String" 494 | }, 495 | "name": "outField" 496 | } 497 | ] 498 | }, 499 | { 500 | "name": "distance", 501 | "description": "Takes two {@link Point} features and calculates\nthe distance between them in degress, radians,\nmiles, or kilometers. This uses the\n[Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula)\nto account for global curvature.", 502 | "params": [ 503 | { 504 | "title": "param", 505 | "description": "origin point", 506 | "lineNumber": 9, 507 | "type": { 508 | "type": "NameExpression", 509 | "name": "Feature" 510 | }, 511 | "name": "from" 512 | }, 513 | { 514 | "title": "param", 515 | "description": "destination point", 516 | "lineNumber": 10, 517 | "type": { 518 | "type": "NameExpression", 519 | "name": "Feature" 520 | }, 521 | "name": "to" 522 | }, 523 | { 524 | "title": "param", 525 | "description": "can be degrees, radians, miles, or kilometers", 526 | "lineNumber": 11, 527 | "type": { 528 | "type": "OptionalType", 529 | "expression": { 530 | "type": "NameExpression", 531 | "name": "String" 532 | } 533 | }, 534 | "name": "units", 535 | "default": "kilometers" 536 | } 537 | ] 538 | }, 539 | { 540 | "name": "envelope", 541 | "description": "Takes a {@link Feature} or {@link FeatureCollection} and returns a rectangular {@link Polygon} feature that encompasses all vertices.", 542 | "params": [ 543 | { 544 | "title": "param", 545 | "description": "a FeatureCollection of any type", 546 | "lineNumber": 5, 547 | "type": { 548 | "type": "NameExpression", 549 | "name": "FeatureCollection" 550 | }, 551 | "name": "fc" 552 | } 553 | ] 554 | }, 555 | { 556 | "name": "erase", 557 | "description": "Finds the difference between two polygons by clipping the second\npolygon from the first.", 558 | "params": [ 559 | { 560 | "title": "param", 561 | "description": "input Polygon feaure", 562 | "lineNumber": 6, 563 | "type": { 564 | "type": "NameExpression", 565 | "name": "Polygon" 566 | }, 567 | "name": "poly1" 568 | }, 569 | { 570 | "title": "param", 571 | "description": "Polygon feature to erase from `poly1`", 572 | "lineNumber": 7, 573 | "type": { 574 | "type": "NameExpression", 575 | "name": "Polygon" 576 | }, 577 | "name": "poly2" 578 | } 579 | ] 580 | }, 581 | { 582 | "name": "explode", 583 | "description": "Takes any {@link GeoJSON} object and return all positions as\na {@link FeatureCollection} of {@link Point} features.", 584 | "params": [ 585 | { 586 | "title": "param", 587 | "description": "input features", 588 | "lineNumber": 6, 589 | "type": { 590 | "type": "NameExpression", 591 | "name": "GeoJSON" 592 | }, 593 | "name": "input" 594 | } 595 | ] 596 | }, 597 | { 598 | "name": "extent", 599 | "description": "Takes any {@link GeoJSON} object, calculates the extent of all input features, and returns a bounding box.", 600 | "params": [ 601 | { 602 | "title": "param", 603 | "description": "any valid GeoJSON Object", 604 | "lineNumber": 5, 605 | "type": { 606 | "type": "NameExpression", 607 | "name": "GeoJSON" 608 | }, 609 | "name": "input" 610 | } 611 | ] 612 | }, 613 | { 614 | "name": "featurecollection", 615 | "description": "Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}", 616 | "params": [ 617 | { 618 | "title": "param", 619 | "description": "input Features", 620 | "lineNumber": 5, 621 | "type": { 622 | "type": "NameExpression", 623 | "name": "Feature" 624 | }, 625 | "name": "features" 626 | } 627 | ] 628 | }, 629 | { 630 | "name": "filter", 631 | "description": "Takes a {@link FeatureCollection} and filters it by a given property and value", 632 | "params": [ 633 | { 634 | "title": "param", 635 | "description": "input FeatureCollection of any type", 636 | "lineNumber": 5, 637 | "type": { 638 | "type": "NameExpression", 639 | "name": "FeatureCollection" 640 | }, 641 | "name": "features" 642 | }, 643 | { 644 | "title": "param", 645 | "description": "the property on which to filter", 646 | "lineNumber": 6, 647 | "type": { 648 | "type": "NameExpression", 649 | "name": "String" 650 | }, 651 | "name": "key" 652 | }, 653 | { 654 | "title": "param", 655 | "description": "the value of that property on which to filter", 656 | "lineNumber": 7, 657 | "type": { 658 | "type": "NameExpression", 659 | "name": "String" 660 | }, 661 | "name": "value" 662 | } 663 | ] 664 | }, 665 | { 666 | "name": "flip", 667 | "description": "Takes a {@link GeoJSON} object of any type and flips all of its coordinates\nfrom `[x, y]` to `[y, x]`.", 668 | "params": [ 669 | { 670 | "title": "param", 671 | "description": "input GeoJSON object", 672 | "lineNumber": 6, 673 | "type": { 674 | "type": "NameExpression", 675 | "name": "GeoJSON" 676 | }, 677 | "name": "input" 678 | } 679 | ] 680 | }, 681 | { 682 | "name": "hexGrid", 683 | "description": "Takes a bounding box and a cell size in degrees and returns a {@link FeatureCollection} of flat-topped\nhexagons ({@link Polygon} features) aligned in an \"odd-q\" vertical grid as\ndescribed in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/)", 684 | "params": [ 685 | { 686 | "title": "param", 687 | "description": "bounding box in [minX, minY, maxX, maxY] order", 688 | "lineNumber": 7, 689 | "type": { 690 | "type": "TypeApplication", 691 | "expression": { 692 | "type": "NameExpression", 693 | "name": "Array" 694 | }, 695 | "applications": [ 696 | { 697 | "type": "NameExpression", 698 | "name": "number" 699 | } 700 | ] 701 | }, 702 | "name": "bbox" 703 | }, 704 | { 705 | "title": "param", 706 | "description": "width of cell in specified units", 707 | "lineNumber": 8, 708 | "type": { 709 | "type": "NameExpression", 710 | "name": "Number" 711 | }, 712 | "name": "cellWidth" 713 | }, 714 | { 715 | "title": "param", 716 | "description": "used in calculating cellWidth ('miles' or 'kilometers')", 717 | "lineNumber": 9, 718 | "type": { 719 | "type": "NameExpression", 720 | "name": "String" 721 | }, 722 | "name": "units" 723 | } 724 | ] 725 | }, 726 | { 727 | "name": "inside", 728 | "description": "Takes a {@link Point} feature and a {@link Polygon} feature and determines if the Point resides inside the Polygon. The Polygon can\nbe convex or concave. The function accepts any valid Polygon or {@link MultiPolygon}\nand accounts for holes.", 729 | "params": [ 730 | { 731 | "title": "param", 732 | "description": "a Point feature", 733 | "lineNumber": 7, 734 | "type": { 735 | "type": "NameExpression", 736 | "name": "Point" 737 | }, 738 | "name": "point" 739 | }, 740 | { 741 | "title": "param", 742 | "description": "a Polygon feature", 743 | "lineNumber": 8, 744 | "type": { 745 | "type": "NameExpression", 746 | "name": "Polygon" 747 | }, 748 | "name": "polygon" 749 | } 750 | ] 751 | }, 752 | { 753 | "name": "intersect", 754 | "description": "Takes two {@link Polygon} features and finds their intersection.", 755 | "params": [ 756 | { 757 | "title": "param", 758 | "description": "the first Polygon", 759 | "lineNumber": 5, 760 | "type": { 761 | "type": "NameExpression", 762 | "name": "Polygon" 763 | }, 764 | "name": "poly1" 765 | }, 766 | { 767 | "title": "param", 768 | "description": "the second Polygon", 769 | "lineNumber": 6, 770 | "type": { 771 | "type": "NameExpression", 772 | "name": "Polygon" 773 | }, 774 | "name": "poly2" 775 | } 776 | ] 777 | }, 778 | { 779 | "name": "isolines", 780 | "description": "Takes a {@link FeatureCollection} of {@link Point} features with z-values and an array of\nvalue breaks and generates [isolines](http://en.wikipedia.org/wiki/Isoline).", 781 | "params": [ 782 | { 783 | "title": "param", 784 | "description": "a FeatureCollection of {@link Point} features", 785 | "lineNumber": 6, 786 | "type": { 787 | "type": "NameExpression", 788 | "name": "FeatureCollection" 789 | }, 790 | "name": "points" 791 | }, 792 | { 793 | "title": "param", 794 | "description": "the property name in `points` from which z-values will be pulled", 795 | "lineNumber": 7, 796 | "type": { 797 | "type": "NameExpression", 798 | "name": "string" 799 | }, 800 | "name": "z" 801 | }, 802 | { 803 | "title": "param", 804 | "description": "resolution of the underlying grid", 805 | "lineNumber": 8, 806 | "type": { 807 | "type": "NameExpression", 808 | "name": "number" 809 | }, 810 | "name": "resolution" 811 | }, 812 | { 813 | "title": "param", 814 | "description": "where to draw contours", 815 | "lineNumber": 9, 816 | "type": { 817 | "type": "TypeApplication", 818 | "expression": { 819 | "type": "NameExpression", 820 | "name": "Array" 821 | }, 822 | "applications": [ 823 | { 824 | "type": "NameExpression", 825 | "name": "number" 826 | } 827 | ] 828 | }, 829 | "name": "breaks" 830 | } 831 | ] 832 | }, 833 | { 834 | "name": "jenks", 835 | "description": "Takes a {@FeatureCollection} of any type and returns an array of the [Jenks Natural breaks](http://en.wikipedia.org/wiki/Jenks_natural_breaks_optimization)\nfor a given property", 836 | "params": [ 837 | { 838 | "title": "param", 839 | "description": "a FeatureCollection of any type", 840 | "lineNumber": 4, 841 | "type": { 842 | "type": "NameExpression", 843 | "name": "FeatureCollection" 844 | }, 845 | "name": "input" 846 | }, 847 | { 848 | "title": "param", 849 | "description": "the property in `input` on which to calculate Jenks natural breaks", 850 | "lineNumber": 5, 851 | "type": { 852 | "type": "NameExpression", 853 | "name": "string" 854 | }, 855 | "name": "field" 856 | }, 857 | { 858 | "title": "param", 859 | "description": "number of classes in which to group the data", 860 | "lineNumber": 6, 861 | "type": { 862 | "type": "NameExpression", 863 | "name": "number" 864 | }, 865 | "name": "numberOfBreaks" 866 | } 867 | ] 868 | }, 869 | { 870 | "name": "kinks", 871 | "description": "Takes a {@link Polygon} feature and returns a {@link FeatureCollection} of {@link Point} features at all self-intersections.", 872 | "params": [ 873 | { 874 | "title": "param", 875 | "description": "a Polygon feature", 876 | "lineNumber": 5, 877 | "type": { 878 | "type": "NameExpression", 879 | "name": "Polygon" 880 | }, 881 | "name": "polygon" 882 | } 883 | ] 884 | }, 885 | { 886 | "name": "lineDistance", 887 | "description": "Takes a {@link LineString} feature and measures its length in the specified units.", 888 | "params": [ 889 | { 890 | "title": "param", 891 | "description": "to measure", 892 | "lineNumber": 5, 893 | "type": { 894 | "type": "NameExpression", 895 | "name": "LineString" 896 | }, 897 | "name": "Line" 898 | }, 899 | { 900 | "title": "param", 901 | "description": "can be degrees, radians, miles, or kilometers", 902 | "lineNumber": 6, 903 | "type": { 904 | "type": "OptionalType", 905 | "expression": { 906 | "type": "NameExpression", 907 | "name": "String" 908 | } 909 | }, 910 | "name": "units", 911 | "default": "miles" 912 | } 913 | ] 914 | }, 915 | { 916 | "name": "lineSlice", 917 | "description": "Slices a LineString at start and stop Points", 918 | "params": [ 919 | { 920 | "title": "param", 921 | "description": "to start the slice", 922 | "lineNumber": 5, 923 | "type": { 924 | "type": "NameExpression", 925 | "name": "Point" 926 | }, 927 | "name": "Point" 928 | }, 929 | { 930 | "title": "param", 931 | "description": "to stop the slice", 932 | "lineNumber": 6, 933 | "type": { 934 | "type": "NameExpression", 935 | "name": "Point" 936 | }, 937 | "name": "Point" 938 | }, 939 | { 940 | "title": "param", 941 | "description": "to slice", 942 | "lineNumber": 7, 943 | "type": { 944 | "type": "NameExpression", 945 | "name": "LineString" 946 | }, 947 | "name": "Line" 948 | } 949 | ] 950 | }, 951 | { 952 | "name": "linestring", 953 | "description": "Creates a {@link LineString} {@link Feature} based on a\ncoordinate array. Properties can be added optionally.", 954 | "params": [ 955 | { 956 | "title": "param", 957 | "description": "an array of Positions", 958 | "lineNumber": 6, 959 | "type": { 960 | "type": "TypeApplication", 961 | "expression": { 962 | "type": "NameExpression", 963 | "name": "Array" 964 | }, 965 | "applications": [ 966 | { 967 | "type": "TypeApplication", 968 | "expression": { 969 | "type": "NameExpression", 970 | "name": "Array" 971 | }, 972 | "applications": [ 973 | { 974 | "type": "NameExpression", 975 | "name": "Number" 976 | } 977 | ] 978 | } 979 | ] 980 | }, 981 | "name": "coordinates" 982 | }, 983 | { 984 | "title": "param", 985 | "description": "an Object of key-value pairs to add as properties", 986 | "lineNumber": 7, 987 | "type": { 988 | "type": "NameExpression", 989 | "name": "Object" 990 | }, 991 | "name": "properties" 992 | } 993 | ] 994 | }, 995 | { 996 | "name": "max", 997 | "description": "Calculates the maximum value of a field for a set of {@link Point} features within a set of {@link Polygon} features.", 998 | "params": [ 999 | { 1000 | "title": "param", 1001 | "description": "a FeatureCollection of {@link Polygon} features", 1002 | "lineNumber": 5, 1003 | "type": { 1004 | "type": "NameExpression", 1005 | "name": "FeatureCollection" 1006 | }, 1007 | "name": "polygons" 1008 | }, 1009 | { 1010 | "title": "param", 1011 | "description": "a FeatureCollection of {@link Point} features", 1012 | "lineNumber": 6, 1013 | "type": { 1014 | "type": "NameExpression", 1015 | "name": "FeatureCollection" 1016 | }, 1017 | "name": "points" 1018 | }, 1019 | { 1020 | "title": "param", 1021 | "description": "the field in input data to analyze", 1022 | "lineNumber": 7, 1023 | "type": { 1024 | "type": "NameExpression", 1025 | "name": "string" 1026 | }, 1027 | "name": "inField" 1028 | }, 1029 | { 1030 | "title": "param", 1031 | "description": "the field in which to store results", 1032 | "lineNumber": 8, 1033 | "type": { 1034 | "type": "NameExpression", 1035 | "name": "string" 1036 | }, 1037 | "name": "outField" 1038 | } 1039 | ] 1040 | }, 1041 | { 1042 | "name": "median", 1043 | "description": "Calculates the median value of a field for a set of {@link Point} features within a set of {@link Polygon} features.", 1044 | "params": [ 1045 | { 1046 | "title": "param", 1047 | "description": "a FeatureCollection of {@link Polygon} features", 1048 | "lineNumber": 5, 1049 | "type": { 1050 | "type": "NameExpression", 1051 | "name": "FeatureCollection" 1052 | }, 1053 | "name": "polygons" 1054 | }, 1055 | { 1056 | "title": "param", 1057 | "description": "a FeatureCollection of {@link Point} features", 1058 | "lineNumber": 6, 1059 | "type": { 1060 | "type": "NameExpression", 1061 | "name": "FeatureCollection" 1062 | }, 1063 | "name": "points" 1064 | }, 1065 | { 1066 | "title": "param", 1067 | "description": "the field in input data to analyze", 1068 | "lineNumber": 7, 1069 | "type": { 1070 | "type": "NameExpression", 1071 | "name": "string" 1072 | }, 1073 | "name": "inField" 1074 | }, 1075 | { 1076 | "title": "param", 1077 | "description": "the field in which to store results", 1078 | "lineNumber": 8, 1079 | "type": { 1080 | "type": "NameExpression", 1081 | "name": "string" 1082 | }, 1083 | "name": "outField" 1084 | } 1085 | ] 1086 | }, 1087 | { 1088 | "name": "merge", 1089 | "description": "Takes a {@link FeatureCollection} of {@link Polygon} features and returns a single merged\npolygon feature. If the input Polygon features are not contiguous, this function returns a {@link MultiPolygon} feature.", 1090 | "params": [ 1091 | { 1092 | "title": "param", 1093 | "description": "a FeatureCollection of {@link Polygon} features", 1094 | "lineNumber": 5, 1095 | "type": { 1096 | "type": "NameExpression", 1097 | "name": "FeatureCollection" 1098 | }, 1099 | "name": "fc" 1100 | } 1101 | ] 1102 | }, 1103 | { 1104 | "name": "midpoint", 1105 | "description": "Takes two {@link Point} features and returns a Point midway between the two.", 1106 | "params": [ 1107 | { 1108 | "title": "param", 1109 | "description": "first point", 1110 | "lineNumber": 5, 1111 | "type": { 1112 | "type": "NameExpression", 1113 | "name": "Point" 1114 | }, 1115 | "name": "pt1" 1116 | }, 1117 | { 1118 | "title": "param", 1119 | "description": "second point", 1120 | "lineNumber": 6, 1121 | "type": { 1122 | "type": "NameExpression", 1123 | "name": "Point" 1124 | }, 1125 | "name": "pt2" 1126 | } 1127 | ] 1128 | }, 1129 | { 1130 | "name": "min", 1131 | "description": "Calculates the minimum value of a field for {@link Point} features within a set of {@link Polygon} features.", 1132 | "params": [ 1133 | { 1134 | "title": "param", 1135 | "description": "a FeatureCollection of {@link Polygon} features", 1136 | "lineNumber": 5, 1137 | "type": { 1138 | "type": "NameExpression", 1139 | "name": "FeatureCollection" 1140 | }, 1141 | "name": "polygons" 1142 | }, 1143 | { 1144 | "title": "param", 1145 | "description": "a FeatureCollection of {@link Point} features", 1146 | "lineNumber": 6, 1147 | "type": { 1148 | "type": "NameExpression", 1149 | "name": "FeatureCollection" 1150 | }, 1151 | "name": "points" 1152 | }, 1153 | { 1154 | "title": "param", 1155 | "description": "the field in input data to analyze", 1156 | "lineNumber": 7, 1157 | "type": { 1158 | "type": "NameExpression", 1159 | "name": "string" 1160 | }, 1161 | "name": "inField" 1162 | }, 1163 | { 1164 | "title": "param", 1165 | "description": "the field in which to store results", 1166 | "lineNumber": 8, 1167 | "type": { 1168 | "type": "NameExpression", 1169 | "name": "string" 1170 | }, 1171 | "name": "outField" 1172 | } 1173 | ] 1174 | }, 1175 | { 1176 | "name": "nearest", 1177 | "description": "Takes a {@link Point} feature and a {@link FeatureCollection} of Point features and returns the Point feature from the FeatureCollection closest to the input point.", 1178 | "params": [ 1179 | { 1180 | "title": "param", 1181 | "description": "the reference point", 1182 | "lineNumber": 5, 1183 | "type": { 1184 | "type": "NameExpression", 1185 | "name": "Point" 1186 | }, 1187 | "name": "point" 1188 | }, 1189 | { 1190 | "title": "param", 1191 | "description": "a FeatureCollection of Point features", 1192 | "lineNumber": 6, 1193 | "type": { 1194 | "type": "NameExpression", 1195 | "name": "FeatureCollection" 1196 | }, 1197 | "name": "against" 1198 | } 1199 | ] 1200 | }, 1201 | { 1202 | "name": "planepoint", 1203 | "description": "Takes a triangular plane as a {@link Polygon} feature\nand a {@link Point} feature within that triangle and returns the z-value\nat that point. The Polygon needs to have properties `a`, `b`, and `c`\nthat define the values at its three corners.", 1204 | "params": [ 1205 | { 1206 | "title": "param", 1207 | "description": "the Point for which a z-value will be calculated", 1208 | "lineNumber": 8, 1209 | "type": { 1210 | "type": "NameExpression", 1211 | "name": "Point" 1212 | }, 1213 | "name": "interpolatedPoint" 1214 | }, 1215 | { 1216 | "title": "param", 1217 | "description": "a Polygon feature with three vertices", 1218 | "lineNumber": 9, 1219 | "type": { 1220 | "type": "NameExpression", 1221 | "name": "Polygon" 1222 | }, 1223 | "name": "triangle" 1224 | } 1225 | ] 1226 | }, 1227 | { 1228 | "name": "point", 1229 | "description": "Takes coordinates and properties (optional) and returns a new {@link Point} feature.", 1230 | "params": [ 1231 | { 1232 | "title": "param", 1233 | "description": "position west to east in decimal degrees", 1234 | "lineNumber": 5, 1235 | "type": { 1236 | "type": "NameExpression", 1237 | "name": "number" 1238 | }, 1239 | "name": "longitude" 1240 | }, 1241 | { 1242 | "title": "param", 1243 | "description": "position south to north in decimal degrees", 1244 | "lineNumber": 6, 1245 | "type": { 1246 | "type": "NameExpression", 1247 | "name": "number" 1248 | }, 1249 | "name": "latitude" 1250 | }, 1251 | { 1252 | "title": "param", 1253 | "description": "an Object that is used as the {@link Feature}'s\nproperties", 1254 | "lineNumber": 7, 1255 | "type": { 1256 | "type": "NameExpression", 1257 | "name": "Object" 1258 | }, 1259 | "name": "properties" 1260 | } 1261 | ] 1262 | }, 1263 | { 1264 | "name": "pointGrid", 1265 | "description": "Takes a bounding box and a cell depth and returns a {@link FeatureCollection} of {@link Point} features in a grid.", 1266 | "params": [ 1267 | { 1268 | "title": "param", 1269 | "description": "extent in [minX, minY, maxX, maxY] order", 1270 | "lineNumber": 5, 1271 | "type": { 1272 | "type": "TypeApplication", 1273 | "expression": { 1274 | "type": "NameExpression", 1275 | "name": "Array" 1276 | }, 1277 | "applications": [ 1278 | { 1279 | "type": "NameExpression", 1280 | "name": "number" 1281 | } 1282 | ] 1283 | }, 1284 | "name": "extent" 1285 | }, 1286 | { 1287 | "title": "param", 1288 | "description": "how many cells to output", 1289 | "lineNumber": 6, 1290 | "type": { 1291 | "type": "NameExpression", 1292 | "name": "Number" 1293 | }, 1294 | "name": "depth" 1295 | } 1296 | ] 1297 | }, 1298 | { 1299 | "name": "pointOnLine", 1300 | "description": "Takes a Point and a LineString and calculates the closest Point on the LineString", 1301 | "params": [ 1302 | { 1303 | "title": "param", 1304 | "description": "to snap to", 1305 | "lineNumber": 5, 1306 | "type": { 1307 | "type": "NameExpression", 1308 | "name": "LineString" 1309 | }, 1310 | "name": "Line" 1311 | }, 1312 | { 1313 | "title": "param", 1314 | "description": "to snap from", 1315 | "lineNumber": 6, 1316 | "type": { 1317 | "type": "NameExpression", 1318 | "name": "Point" 1319 | }, 1320 | "name": "Point" 1321 | } 1322 | ] 1323 | }, 1324 | { 1325 | "name": "pointOnSurface", 1326 | "description": "Finds a {@link Point} guaranteed to be on the surface of\n{@link GeoJSON} object.\n\n* Given a {@link Polygon}, the point will be in the area of the polygon\n* Given a {@link LineString}, the point will be along the string\n* Given a {@link Point}, the point will the same as the input", 1327 | "params": [ 1328 | { 1329 | "title": "param", 1330 | "description": "any GeoJSON object", 1331 | "lineNumber": 10, 1332 | "type": { 1333 | "type": "NameExpression", 1334 | "name": "GeoJSON" 1335 | }, 1336 | "name": "input" 1337 | } 1338 | ] 1339 | }, 1340 | { 1341 | "name": "polygon", 1342 | "description": "Takes an array of LinearRings and optionally an {@link Object} with properties and returns a GeoJSON {@link Polygon} feature.", 1343 | "params": [ 1344 | { 1345 | "title": "param", 1346 | "description": "an array of LinearRings", 1347 | "lineNumber": 5, 1348 | "type": { 1349 | "type": "TypeApplication", 1350 | "expression": { 1351 | "type": "NameExpression", 1352 | "name": "Array" 1353 | }, 1354 | "applications": [ 1355 | { 1356 | "type": "TypeApplication", 1357 | "expression": { 1358 | "type": "NameExpression", 1359 | "name": "Array" 1360 | }, 1361 | "applications": [ 1362 | { 1363 | "type": "NameExpression", 1364 | "name": "Number" 1365 | } 1366 | ] 1367 | } 1368 | ] 1369 | }, 1370 | "name": "rings" 1371 | }, 1372 | { 1373 | "title": "param", 1374 | "description": "an optional properties object", 1375 | "lineNumber": 6, 1376 | "type": { 1377 | "type": "NameExpression", 1378 | "name": "Object" 1379 | }, 1380 | "name": "properties" 1381 | } 1382 | ] 1383 | }, 1384 | { 1385 | "name": "quantile", 1386 | "description": "Takes a {@link FeatureCollection}, a property name, and a set of percentiles and returns a quantile array.", 1387 | "params": [ 1388 | { 1389 | "title": "param", 1390 | "description": "a FeatureCollection of any type", 1391 | "lineNumber": 4, 1392 | "type": { 1393 | "type": "NameExpression", 1394 | "name": "FeatureCollection" 1395 | }, 1396 | "name": "input" 1397 | }, 1398 | { 1399 | "title": "param", 1400 | "description": "the property in `input` from which to retrieve quantile values", 1401 | "lineNumber": 5, 1402 | "type": { 1403 | "type": "NameExpression", 1404 | "name": "String" 1405 | }, 1406 | "name": "field" 1407 | }, 1408 | { 1409 | "title": "param", 1410 | "description": "an Array of percentiles on which to calculate quantile values", 1411 | "lineNumber": 6, 1412 | "type": { 1413 | "type": "TypeApplication", 1414 | "expression": { 1415 | "type": "NameExpression", 1416 | "name": "Array" 1417 | }, 1418 | "applications": [ 1419 | { 1420 | "type": "NameExpression", 1421 | "name": "number" 1422 | } 1423 | ] 1424 | }, 1425 | "name": "percentiles" 1426 | } 1427 | ] 1428 | }, 1429 | { 1430 | "name": "random", 1431 | "description": "Generates random {@link GeoJSON} data, including {@link Point|Points} and {@link Polygon|Polygons}, for testing\nand experimentation.", 1432 | "params": [ 1433 | { 1434 | "title": "param", 1435 | "description": "type of features desired: 'points' or 'polygons'", 1436 | "lineNumber": 6, 1437 | "type": { 1438 | "type": "OptionalType", 1439 | "expression": { 1440 | "type": "NameExpression", 1441 | "name": "String" 1442 | } 1443 | }, 1444 | "name": "type", 1445 | "default": "'point'" 1446 | }, 1447 | { 1448 | "title": "param", 1449 | "description": "how many geometries should be generated.", 1450 | "lineNumber": 7, 1451 | "type": { 1452 | "type": "OptionalType", 1453 | "expression": { 1454 | "type": "NameExpression", 1455 | "name": "Number" 1456 | } 1457 | }, 1458 | "name": "count", 1459 | "default": "1" 1460 | }, 1461 | { 1462 | "title": "param", 1463 | "description": "options relevant to the feature desired. Can include:", 1464 | "lineNumber": 8, 1465 | "type": { 1466 | "type": "NameExpression", 1467 | "name": "Object" 1468 | }, 1469 | "name": "options", 1470 | "properties": [ 1471 | { 1472 | "title": "param", 1473 | "description": "a bounding box inside of which geometries\nare placed. In the case of {@link Point} features, they are guaranteed to be within this bounds,\nwhile {@link Polygon} features have their centroid within the bounds.", 1474 | "lineNumber": 9, 1475 | "type": { 1476 | "type": "TypeApplication", 1477 | "expression": { 1478 | "type": "NameExpression", 1479 | "name": "Array" 1480 | }, 1481 | "applications": [ 1482 | { 1483 | "type": "NameExpression", 1484 | "name": "number" 1485 | } 1486 | ] 1487 | }, 1488 | "name": "options.bbox" 1489 | }, 1490 | { 1491 | "title": "param", 1492 | "description": "options.vertices the number of vertices added\nto polygon features.", 1493 | "lineNumber": 12, 1494 | "type": { 1495 | "type": "OptionalType", 1496 | "expression": { 1497 | "type": "NameExpression", 1498 | "name": "Number" 1499 | } 1500 | }, 1501 | "name": "options.num_vertices", 1502 | "default": "10" 1503 | }, 1504 | { 1505 | "title": "param", 1506 | "description": "the total number of decimal\ndegrees longitude or latitude that a polygon can extent outwards to\nfrom its center.", 1507 | "lineNumber": 14, 1508 | "type": { 1509 | "type": "OptionalType", 1510 | "expression": { 1511 | "type": "NameExpression", 1512 | "name": "Number" 1513 | } 1514 | }, 1515 | "name": "options.max_radial_length", 1516 | "default": "10" 1517 | } 1518 | ] 1519 | } 1520 | ] 1521 | }, 1522 | { 1523 | "name": "reclass", 1524 | "description": "Takes a {@link FeatureCollection}, an input field, an output field, and\nan array of translations and outputs an identical FeatureCollection with\nthe output field property populated.", 1525 | "params": [ 1526 | { 1527 | "title": "param", 1528 | "description": "a FeatureCollection of any type", 1529 | "lineNumber": 6, 1530 | "type": { 1531 | "type": "NameExpression", 1532 | "name": "FeatureCollection" 1533 | }, 1534 | "name": "input" 1535 | }, 1536 | { 1537 | "title": "param", 1538 | "description": "the field to translate", 1539 | "lineNumber": 7, 1540 | "type": { 1541 | "type": "NameExpression", 1542 | "name": "string" 1543 | }, 1544 | "name": "inField" 1545 | }, 1546 | { 1547 | "title": "param", 1548 | "description": "the field in which to store translated results", 1549 | "lineNumber": 8, 1550 | "type": { 1551 | "type": "NameExpression", 1552 | "name": "string" 1553 | }, 1554 | "name": "outField" 1555 | }, 1556 | { 1557 | "title": "param", 1558 | "description": "an array of translations", 1559 | "lineNumber": 9, 1560 | "type": { 1561 | "type": "TypeApplication", 1562 | "expression": { 1563 | "type": "NameExpression", 1564 | "name": "Array" 1565 | }, 1566 | "applications": [ 1567 | { 1568 | "type": "NameExpression", 1569 | "name": "number" 1570 | } 1571 | ] 1572 | }, 1573 | "name": "translations" 1574 | } 1575 | ] 1576 | }, 1577 | { 1578 | "name": "remove", 1579 | "description": "Takes a {@link FeatureCollection} of any type, a property, and a value and\nreturns a FeatureCollection with features matching that\nproperty-value pair removed.", 1580 | "params": [ 1581 | { 1582 | "title": "param", 1583 | "description": "a FeatureCollection of any type", 1584 | "lineNumber": 7, 1585 | "type": { 1586 | "type": "NameExpression", 1587 | "name": "FeatureCollection" 1588 | }, 1589 | "name": "features" 1590 | }, 1591 | { 1592 | "title": "param", 1593 | "description": "the property to filter", 1594 | "lineNumber": 8, 1595 | "type": { 1596 | "type": "NameExpression", 1597 | "name": "String" 1598 | }, 1599 | "name": "property" 1600 | }, 1601 | { 1602 | "title": "param", 1603 | "description": "the value to filter", 1604 | "lineNumber": 9, 1605 | "type": { 1606 | "type": "NameExpression", 1607 | "name": "String" 1608 | }, 1609 | "name": "value" 1610 | } 1611 | ] 1612 | }, 1613 | { 1614 | "name": "sample", 1615 | "description": "Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.", 1616 | "params": [ 1617 | { 1618 | "title": "param", 1619 | "description": "a FeatureCollection of any type", 1620 | "lineNumber": 5, 1621 | "type": { 1622 | "type": "NameExpression", 1623 | "name": "FeatureCollection" 1624 | }, 1625 | "name": "features" 1626 | }, 1627 | { 1628 | "title": "param", 1629 | "description": "number of features to select", 1630 | "lineNumber": 6, 1631 | "type": { 1632 | "type": "NameExpression", 1633 | "name": "number" 1634 | }, 1635 | "name": "n" 1636 | } 1637 | ] 1638 | }, 1639 | { 1640 | "name": "simplify", 1641 | "description": "Takes a {@link LineString} or {@link Polygon} feature and returns a simplified version. Internally uses [simplify-js](http://mourner.github.io/simplify-js/) to perform simplification.", 1642 | "params": [ 1643 | { 1644 | "title": "param", 1645 | "description": "a {@link LineString} or {@link Polygon} feature to be simplified", 1646 | "lineNumber": 5, 1647 | "type": { 1648 | "type": "NameExpression", 1649 | "name": "Feature" 1650 | }, 1651 | "name": "feature" 1652 | }, 1653 | { 1654 | "title": "param", 1655 | "description": "simplification tolerance", 1656 | "lineNumber": 6, 1657 | "type": { 1658 | "type": "NameExpression", 1659 | "name": "number" 1660 | }, 1661 | "name": "tolerance" 1662 | }, 1663 | { 1664 | "title": "param", 1665 | "description": "whether or not to spend more time to create\na higher-quality simplification with a different algorithm", 1666 | "lineNumber": 7, 1667 | "type": { 1668 | "type": "NameExpression", 1669 | "name": "boolean" 1670 | }, 1671 | "name": "highQuality" 1672 | } 1673 | ] 1674 | }, 1675 | { 1676 | "name": "size", 1677 | "description": "Takes a bounding box and returns a new bounding box with a size expanded or contracted\nby a factor of X.", 1678 | "params": [ 1679 | { 1680 | "title": "param", 1681 | "description": "a bounding box", 1682 | "lineNumber": 6, 1683 | "type": { 1684 | "type": "TypeApplication", 1685 | "expression": { 1686 | "type": "NameExpression", 1687 | "name": "Array" 1688 | }, 1689 | "applications": [ 1690 | { 1691 | "type": "NameExpression", 1692 | "name": "number" 1693 | } 1694 | ] 1695 | }, 1696 | "name": "bbox" 1697 | }, 1698 | { 1699 | "title": "param", 1700 | "description": "the ratio of the new bbox to the input bbox", 1701 | "lineNumber": 7, 1702 | "type": { 1703 | "type": "NameExpression", 1704 | "name": "number" 1705 | }, 1706 | "name": "factor" 1707 | } 1708 | ] 1709 | }, 1710 | { 1711 | "name": "square", 1712 | "description": "Takes a bounding box and calculates the minimum square bounding box that would contain the input.", 1713 | "params": [ 1714 | { 1715 | "title": "param", 1716 | "description": "a bounding box", 1717 | "lineNumber": 5, 1718 | "type": { 1719 | "type": "TypeApplication", 1720 | "expression": { 1721 | "type": "NameExpression", 1722 | "name": "Array" 1723 | }, 1724 | "applications": [ 1725 | { 1726 | "type": "NameExpression", 1727 | "name": "number" 1728 | } 1729 | ] 1730 | }, 1731 | "name": "bbox" 1732 | } 1733 | ] 1734 | }, 1735 | { 1736 | "name": "squareGrid", 1737 | "description": "Takes a bounding box and a cell depth and returns a {@link FeatureCollection} of {@link Polygon} features in a grid.", 1738 | "params": [ 1739 | { 1740 | "title": "param", 1741 | "description": "extent in [minX, minY, maxX, maxY] order", 1742 | "lineNumber": 5, 1743 | "type": { 1744 | "type": "TypeApplication", 1745 | "expression": { 1746 | "type": "NameExpression", 1747 | "name": "Array" 1748 | }, 1749 | "applications": [ 1750 | { 1751 | "type": "NameExpression", 1752 | "name": "number" 1753 | } 1754 | ] 1755 | }, 1756 | "name": "extent" 1757 | }, 1758 | { 1759 | "title": "param", 1760 | "description": "width of each cell", 1761 | "lineNumber": 6, 1762 | "type": { 1763 | "type": "NameExpression", 1764 | "name": "Number" 1765 | }, 1766 | "name": "cellWidth" 1767 | }, 1768 | { 1769 | "title": "param", 1770 | "description": "units to use for cellWidth", 1771 | "lineNumber": 7, 1772 | "type": { 1773 | "type": "NameExpression", 1774 | "name": "String" 1775 | }, 1776 | "name": "units" 1777 | } 1778 | ] 1779 | }, 1780 | { 1781 | "name": "sum", 1782 | "description": "Calculates the sum of a field for {@link Point} features within a set of {@link Polygon} features.", 1783 | "params": [ 1784 | { 1785 | "title": "param", 1786 | "description": "a FeatureCollection of {@link Polygon} features", 1787 | "lineNumber": 5, 1788 | "type": { 1789 | "type": "NameExpression", 1790 | "name": "FeatureCollection" 1791 | }, 1792 | "name": "polygons" 1793 | }, 1794 | { 1795 | "title": "param", 1796 | "description": "a FeatureCollection of {@link Point} features", 1797 | "lineNumber": 6, 1798 | "type": { 1799 | "type": "NameExpression", 1800 | "name": "FeatureCollection" 1801 | }, 1802 | "name": "points" 1803 | }, 1804 | { 1805 | "title": "param", 1806 | "description": "the field in input data to analyze", 1807 | "lineNumber": 7, 1808 | "type": { 1809 | "type": "NameExpression", 1810 | "name": "String" 1811 | }, 1812 | "name": "inField" 1813 | }, 1814 | { 1815 | "title": "param", 1816 | "description": "the field in which to store results", 1817 | "lineNumber": 8, 1818 | "type": { 1819 | "type": "NameExpression", 1820 | "name": "String" 1821 | }, 1822 | "name": "outField" 1823 | } 1824 | ] 1825 | }, 1826 | { 1827 | "name": "tag", 1828 | "description": "Takes a {@link FeatureCollection} of {@link Point} features and a FeatureCollection of {@link Polygon} features and performs a spatial join.", 1829 | "params": [ 1830 | { 1831 | "title": "param", 1832 | "description": "a FeatureCollection of {@link Point} features", 1833 | "lineNumber": 5, 1834 | "type": { 1835 | "type": "NameExpression", 1836 | "name": "FeatureCollection" 1837 | }, 1838 | "name": "points" 1839 | }, 1840 | { 1841 | "title": "param", 1842 | "description": "a FeatureCollection of {@link Polygon} features", 1843 | "lineNumber": 6, 1844 | "type": { 1845 | "type": "NameExpression", 1846 | "name": "FeatureCollection" 1847 | }, 1848 | "name": "polygons" 1849 | }, 1850 | { 1851 | "title": "param", 1852 | "description": "property in `polygons` to add to joined Point features", 1853 | "lineNumber": 7, 1854 | "type": { 1855 | "type": "NameExpression", 1856 | "name": "String" 1857 | }, 1858 | "name": "polyId" 1859 | }, 1860 | { 1861 | "title": "param", 1862 | "description": "property in `points` in which to store joined property from `polygons", 1863 | "lineNumber": 8, 1864 | "type": { 1865 | "type": "NameExpression", 1866 | "name": "String" 1867 | }, 1868 | "name": "containingPolyId" 1869 | } 1870 | ] 1871 | }, 1872 | { 1873 | "name": "tin", 1874 | "description": "Takes a set of points and the name of a z-value property and\ncreates a [Triangulated Irregular Network](http://en.wikipedia.org/wiki/Triangulated_irregular_network),\nor a TIN for short, returned as a collection of Polygons. These are often used\nfor developing elevation contour maps or stepped heat visualizations.\n\nThis triangulates the points, as well as adds properties called `a`, `b`,\nand `c` representing the value of the given `propertyName` at each of\nthe points that represent the corners of the triangle.", 1875 | "params": [ 1876 | { 1877 | "title": "param", 1878 | "description": "a GeoJSON FeatureCollection containing\nFeatures with {@link Point} geometries", 1879 | "lineNumber": 12, 1880 | "type": { 1881 | "type": "NameExpression", 1882 | "name": "FeatureCollection" 1883 | }, 1884 | "name": "points" 1885 | }, 1886 | { 1887 | "title": "param", 1888 | "description": "name of the property from which to pull z values.\nThis is optional: if not given, then there will be no extra data added to the derived triangles.", 1889 | "lineNumber": 14, 1890 | "type": { 1891 | "type": "OptionalType", 1892 | "expression": { 1893 | "type": "NameExpression", 1894 | "name": "string" 1895 | } 1896 | }, 1897 | "name": "propertyName" 1898 | } 1899 | ] 1900 | }, 1901 | { 1902 | "name": "triangleGrid", 1903 | "description": "Takes a bounding box and a cell depth and returns a {@link FeatureCollection} of {@link Polygon} features in a grid.", 1904 | "params": [ 1905 | { 1906 | "title": "param", 1907 | "description": "extent in [minX, minY, maxX, maxY] order", 1908 | "lineNumber": 5, 1909 | "type": { 1910 | "type": "TypeApplication", 1911 | "expression": { 1912 | "type": "NameExpression", 1913 | "name": "Array" 1914 | }, 1915 | "applications": [ 1916 | { 1917 | "type": "NameExpression", 1918 | "name": "number" 1919 | } 1920 | ] 1921 | }, 1922 | "name": "extent" 1923 | }, 1924 | { 1925 | "title": "param", 1926 | "description": "width of each cell", 1927 | "lineNumber": 6, 1928 | "type": { 1929 | "type": "NameExpression", 1930 | "name": "Number" 1931 | }, 1932 | "name": "cellWidth" 1933 | }, 1934 | { 1935 | "title": "param", 1936 | "description": "units to use for cellWidth", 1937 | "lineNumber": 7, 1938 | "type": { 1939 | "type": "NameExpression", 1940 | "name": "String" 1941 | }, 1942 | "name": "units" 1943 | } 1944 | ] 1945 | }, 1946 | { 1947 | "name": "union", 1948 | "description": "Takes two {@link Polygon} features and returnes a combined {@link Polygon} feature. If the input Polygon features are not contiguous, this function returns a {@link MultiPolygon} feature.", 1949 | "params": [ 1950 | { 1951 | "title": "param", 1952 | "description": "an input Polygon", 1953 | "lineNumber": 5, 1954 | "type": { 1955 | "type": "NameExpression", 1956 | "name": "Polygon" 1957 | }, 1958 | "name": "poly1" 1959 | }, 1960 | { 1961 | "title": "param", 1962 | "description": "another input Polygon", 1963 | "lineNumber": 6, 1964 | "type": { 1965 | "type": "NameExpression", 1966 | "name": "Polygon" 1967 | }, 1968 | "name": "poly2" 1969 | } 1970 | ] 1971 | }, 1972 | { 1973 | "name": "variance", 1974 | "description": "Calculates the variance value of a field for {@link Point} features within a set of {@link Polygon} features.", 1975 | "params": [ 1976 | { 1977 | "title": "param", 1978 | "description": "a FeatureCollection of {@link Polygon} features", 1979 | "lineNumber": 5, 1980 | "type": { 1981 | "type": "NameExpression", 1982 | "name": "FeatureCollection" 1983 | }, 1984 | "name": "polygons" 1985 | }, 1986 | { 1987 | "title": "param", 1988 | "description": "a FeatureCollection of {@link Point} features", 1989 | "lineNumber": 6, 1990 | "type": { 1991 | "type": "NameExpression", 1992 | "name": "FeatureCollection" 1993 | }, 1994 | "name": "points" 1995 | }, 1996 | { 1997 | "title": "param", 1998 | "description": "the field in input data to analyze", 1999 | "lineNumber": 7, 2000 | "type": { 2001 | "type": "NameExpression", 2002 | "name": "string" 2003 | }, 2004 | "name": "inField" 2005 | }, 2006 | { 2007 | "title": "param", 2008 | "description": "the field in which to store results", 2009 | "lineNumber": 8, 2010 | "type": { 2011 | "type": "NameExpression", 2012 | "name": "string" 2013 | }, 2014 | "name": "outField" 2015 | } 2016 | ] 2017 | }, 2018 | { 2019 | "name": "within", 2020 | "description": "Takes a {@link FeatureCollection} of {@link Point} features and a FeatureCollection of {@link Polygon} features and returns a FeatureCollection of Point features representing all points that fall within a collection of polygons.", 2021 | "params": [ 2022 | { 2023 | "title": "param", 2024 | "description": "a FeatureCollection of {@link Point} features", 2025 | "lineNumber": 5, 2026 | "type": { 2027 | "type": "NameExpression", 2028 | "name": "FeatureCollection" 2029 | }, 2030 | "name": "points" 2031 | }, 2032 | { 2033 | "title": "param", 2034 | "description": "a FeatureCollection of {@link Polygon} features", 2035 | "lineNumber": 6, 2036 | "type": { 2037 | "type": "NameExpression", 2038 | "name": "FeatureCollection" 2039 | }, 2040 | "name": "polygons" 2041 | } 2042 | ] 2043 | } 2044 | ] 2045 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var runtime = require('runtime-documentation'), 2 | queue = require('queue-async'), 3 | path = require('path'), 4 | camelcase = require('camelcase'), 5 | glob = require('glob'); 6 | 7 | var q = queue(1); 8 | 9 | glob.sync('./node_modules/turf/node_modules/turf-*').forEach(function(t) { 10 | q.defer(runtime.require, t, __dirname, { shallow: true }); 11 | }); 12 | 13 | q.awaitAll(function(err, res) { 14 | var functions = []; 15 | res.forEach(function(docs) { 16 | docs.forEach(function(doc) { 17 | var dir = path.dirname(doc.context.file).split('/'); 18 | var name = camelcase(dir[dir.length - 1].replace('turf-', '')); 19 | functions.push({ 20 | name: name, 21 | description: doc.description, 22 | params: doc.params 23 | }); 24 | }); 25 | }); 26 | console.log(JSON.stringify(functions, null, 2)); 27 | }); 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "turf-cli", 3 | "version": "1.2.0", 4 | "description": "a command line interface for turfjs", 5 | "main": "index.js", 6 | "dependencies": { 7 | "chalk": "^1.0.0", 8 | "get-stdin": "^5.0.1", 9 | "minimist": "^1.1.1", 10 | "turf": "^2.0.2" 11 | }, 12 | "devDependencies": { 13 | "glob": "^5.0.10", 14 | "camelcase": "^1.1.0", 15 | "queue-async": "^1.0.7", 16 | "runtime-documentation": "^1.0.0", 17 | "eslint": "~1.00.0", 18 | "eslint-config-unstyled": "^1.1.0" 19 | }, 20 | "bin": { 21 | "turf": "cli.js" 22 | }, 23 | "scripts": { 24 | "test": "eslint index.js cli.js" 25 | }, 26 | "keywords": [ 27 | "turf", 28 | "turfjs", 29 | "gis", 30 | "cli" 31 | ], 32 | "author": "Tom MacWright", 33 | "license": "ISC" 34 | } 35 | --------------------------------------------------------------------------------