How to use @turf/random - 10 common examples

To help you get started, we’ve selected a few @turf/random examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DAVFoundation / community / src / lib / dummyData.js View on Github external
count: 306,
      bbox: [-6.13,50.45,1.46,57.29]
    }
  ];

  let points = await DummyData.find({}).exec();

  if(points.length>200){
    return;
  }

  let allPoints = [];

  for(var region in boundingBoxes){
    //let points = random.point(230, region.bbox);
    let points = turf('points', boundingBoxes[region].count, {
      bbox: boundingBoxes[region].bbox
    });

    for(var index in points.features){
      let obj = {"loc":points.features[index].geometry};
      allPoints.push(obj); // contains geojson point obj which can be saved in mongoose
    }
  }

  console.log(allPoints[0].loc.coordinates);

  DummyData.insertMany(allPoints)
    .then(docs => {
      console.log(`Added ${docs.length} geo points`);
    })
    .catch(err => {
github DenisCarriere / geojson-rbush / bench.js View on Github external
const Benchmark = require('benchmark');
const {randomPoint, randomPolygon} = require('@turf/random');
const geojsonRbush = require('./').default;

// Fixtures
const points = randomPoint(3);
const point = points.features[0];
const polygons = randomPolygon(3);
const polygon = polygons.features[0];

// Load trees before (used to benchmark search)
const pointsTree = geojsonRbush();
pointsTree.load(points);
const polygonsTree = geojsonRbush();
polygonsTree.load(polygons);

/**
 * Benchmark Results
 *
 * rbush.points x 313,979 ops/sec ±10.60% (67 runs sampled)
 * rbush.polygons x 428,333 ops/sec ±1.69% (70 runs sampled)
 * search.points x 5,986,675 ops/sec ±7.95% (77 runs sampled)
github DenisCarriere / geojson-rbush / bench.js View on Github external
const Benchmark = require('benchmark');
const {randomPoint, randomPolygon} = require('@turf/random');
const geojsonRbush = require('./').default;

// Fixtures
const points = randomPoint(3);
const point = points.features[0];
const polygons = randomPolygon(3);
const polygon = polygons.features[0];

// Load trees before (used to benchmark search)
const pointsTree = geojsonRbush();
pointsTree.load(points);
const polygonsTree = geojsonRbush();
polygonsTree.load(polygons);

/**
 * Benchmark Results
 *
 * rbush.points x 313,979 ops/sec ±10.60% (67 runs sampled)
 * rbush.polygons x 428,333 ops/sec ±1.69% (70 runs sampled)
 * search.points x 5,986,675 ops/sec ±7.95% (77 runs sampled)
 * search.polygons x 6,481,248 ops/sec ±0.93% (90 runs sampled)
 */
github Turfjs / turf / packages / turf-isolines / types.ts View on Github external
import random from '@turf/random'
import isolines from './'

const points = random('point', 100, {
    bbox: [0, 30, 20, 50]
})
for (let i = 0; i < points.features.length; i++) {
    points.features[i].properties.z = Math.random() * 10;
}
const breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const lines = isolines(points, breaks, 'temperature')
const properties = {apply: 'all'}

// Properties option
isolines(points, breaks, 'temperature', properties)
isolines(points, breaks, 'temperature', properties, [{name: 'break1'}, {name: 'break2'}])
github digidem / mapeo-mobile / scripts / anonymize_test_data.js View on Github external
function randomizeObs(o) {
  var r = JSON.parse(JSON.stringify(o));
  r.id = randomBytes(8).toString("hex");
  r.version = randomBytes(32).toString("hex");
  r.created_at = addDateFuzz(o.created_at);
  r.timestamp = addDateFuzz(o.timestamp, r.created_at);
  var pos = randomPosition(bbox);
  r.value.lon = pos[0];
  r.value.lat = pos[1];
  r.value.tags = {
    notes: txtgen.sentence(),
    categoryId: o.value.tags.categoryId
  };
  return r;
}
github Turfjs / turf / packages / turf-center-median / bench.js View on Github external
    .add('turf-center-median - 500 points', () => centerMedian(randomPoint(500)))
    .on('cycle', e => console.log(String(e.target)))
github Turfjs / turf / packages / turf-quadrat-analysis / bench.js View on Github external
const bbox = require('@turf/bbox').default;
const nearestNeighborAnalysis = require('@turf/nearest-neighbor-analysis').default;
const quadratAnalysis = require('.').default;

/**
 * Benchmark Results
 * quadrat: 1383.768ms
 * nearest: 12259.498ms
 * quadrat x 0.76 ops/sec ±1.24% (6 runs sampled)
 * nearest x 0.08 ops/sec ±0.97% (5 runs sampled)
 */
const suite = new Benchmark.Suite('turf-quadrat-analysis');


const smallBbox = [-10, -10, 10, 10];
const dataset = randomPoint(10000, { bbox: smallBbox });


var nameQ = 'quadrat';
var nameN = 'nearest'
console.time(nameQ);
quadratAnalysis(dataset, {
    studyBbox: smallBbox,
    confidenceLevel: 20
});
console.timeEnd(nameQ);

console.time(nameN);
nearestNeighborAnalysis(dataset);
console.timeEnd(nameN);

suite.add(nameQ, () => quadratAnalysis(dataset, {
github Turfjs / turf / packages / turf-meta / bench.js View on Github external
const Benchmark = require('benchmark');
const random = require('@turf/random');
const meta = require('./');

const fixtures = {
    point: random.randomPoint(),
    points: random.randomPoint(1000),
    polygon: random.randomPolygon(),
    polygons: random.randomPolygon(1000)
};

const suite = new Benchmark.Suite('turf-meta');

/**
 * Benchmark Results
 * segmentEach   - point x 3,541,484 ops/sec ±6.03% (88 runs sampled)
 * segmentReduce - point x 3,245,821 ops/sec ±0.95% (86 runs sampled)
 * flattenEach   - point x 6,447,234 ops/sec ±5.56% (79 runs sampled)
 * flattenReduce - point x 5,415,555 ops/sec ±1.28% (85 runs sampled)
 * coordEach     - point x 19,941,547 ops/sec ±0.64% (84 runs sampled)
 * coordReduce   - point x 11,959,189 ops/sec ±1.53% (85 runs sampled)
 * propEach      - point x 29,317,809 ops/sec ±1.38% (85 runs sampled)
 * propReduce    - point x 14,552,839 ops/sec ±1.06% (90 runs sampled)
github Turfjs / turf / packages / turf-center-median / bench.js View on Github external
    .add('turf-center-median - 100 points', () => centerMedian(randomPoint(100)))
    .add('turf-center-median - 200 points', () => centerMedian(randomPoint(200)))
github Turfjs / turf / packages / turf-center-median / bench.js View on Github external
    .add('turf-center-median - 200 points', () => centerMedian(randomPoint(200)))
    .add('turf-center-median - 500 points', () => centerMedian(randomPoint(500)))

@turf/random

turf random module

MIT
Latest version published 3 years ago

Package Health Score

80 / 100
Full package analysis