How to use @turf/square-grid - 5 common examples

To help you get started, we’ve selected a few @turf/square-grid 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 WorldBank-Transport / ram-backend / __converter / app / calculate-eta / index.js View on Github external
poi: poiByType,
    villages,
    osrmFile,
    adminArea,
    gridSize,
    maxTime,
    maxSpeed
  } = e;

  const osrm = new OSRM(osrmFile);
  process.send({type: 'status', data: 'srv_loaded_files', id: id});

  // Split the input region in squares for parallelisation.
  let box = envelope(adminArea);
  let extent = [box.geometry.coordinates[0][0][0], box.geometry.coordinates[0][0][1], box.geometry.coordinates[0][2][0], box.geometry.coordinates[0][2][1]];
  let squares = squareGrid(extent, gridSize || 30, 'kilometers').features;
  process.send({type: 'squarecount', data: squares.length, id: id});

  // Create a task for each square to be run below.
  var squareTasks = squares.map(square => {
    // Clip the square with the input geometry. In this way we work with a
    // smaller area..
    let workArea = intersect(adminArea, square);
    return createProcessAreaTask(workArea, poiByType, villages, osrm, maxTime, maxSpeed, id);
  });

  async.parallelLimit(squareTasks, config.cpus, (err, allSquaresRes) => {
    if (err) {
      throw err;
    }
    // allSquaresRes -> is an array of square results.
    // Flatten the array.
github stvno / worlda11y / calculate-eta / index.js View on Github external
id,
    poi,
    origins,
    osrmFile,
    adminArea,
    gridSize,
    maxTime,
    maxSpeed
  } = e;


  const osrm = new OSRM(osrmFile);
  process.send({type: 'status', data: 'srv_loaded_files', id: id});
  // Split the input region in squares for parallelisation.
  let extent = bbox(adminArea);
  let squares = squareGrid(extent, gridSize || 500, 'kilometers').features;
  process.send({type: 'squarecount', data: squares.length, id: id});

  // Create a task for each square to be run below.
  var squareTasks = squares.map(square => {
    // Clip the square with the input geometry. In this way we work with a
    // smaller area..
    let workArea = intersect(adminArea, square);
    return createProcessAreaTask(workArea, poi, origins, osrm, maxTime, maxSpeed, id);
  });

  async.parallelLimit(squareTasks, config.cpus, (err, allSquaresRes) => {
    if (err) {
      throw err;
    }
    // allSquaresRes -> is an array of square results.
    // Flatten the array.
github Turfjs / turf / packages / turf-quadrat-analysis / index.js View on Github external
export default function quadratAnalysis(pointFeatureSet, options) {

  options = options || {};
  var studyBbox = options.studyBbox || bbox(pointFeatureSet);
  var confidenceLevel = options.confidenceLevel || 20;
  var points = pointFeatureSet.features;
  
  // create square-grid
  var numOfPoints = points.length;
  var sizeOfArea = area(bboxPolygon(studyBbox));
  var lengthOfSide = Math.sqrt((sizeOfArea / numOfPoints) * 2);
  var grid = squareGrid(studyBbox, lengthOfSide, {
    units: 'meters'
  });
  var quadrats = grid.features;

  // count the number of features in each quadrat
  var quadratIdDict = {};
  for (var i = 0; i < quadrats.length; i++) {
    quadratIdDict[i] = {
      box: bbox(quadrats[i]),
      cnt: 0
    }
  }

  var sumOfPoint = 0;
  for (var i = 0; i < points.length; i++) {
    var point = points[i];
github Turfjs / turf / packages / turf-idw / index.js View on Github external
export default function (controlPoints, valueField, weight, cellWidth, units) {
    // validation
    if (!valueField) throw new Error('valueField is required');
    if (weight === undefined || weight === null) throw new Error('weight is required');
    if (cellWidth === undefined || cellWidth === null) throw new Error('cellWidth is required');

    // check if field containing data exists.
    var filtered = controlPoints.features.filter(function (feature) {
        return feature.properties &&
            feature.properties.hasOwnProperty(valueField);
    });
    if (filtered.length === 0) throw new Error('Specified Data Field is Missing');

    // create a sample square grid
    // compared to a point grid helps visualizing the output (like a raster..)
    var samplingGrid = squareGrid(bbox(controlPoints), cellWidth, units);
    var N = samplingGrid.features.length;
    for (var i = 0; i < N; i++) {
        var zw = 0;
        var sw = 0;
        // calculate the distance from each control point to cell's centroid
        for (var j = 0; j < controlPoints.features.length; j++) {
            var d = distance(centroid(samplingGrid.features[i]), controlPoints.features[j], units);
            if (d === 0) {
                zw = controlPoints.features[j].properties[valueField];
            }
            var w = 1.0 / Math.pow(d, weight);
            sw += w;
            zw += w * controlPoints.features[j].properties[valueField];
        }
        // write IDW value for each grid cell
        samplingGrid.features[i].properties[valueField] = zw / sw;
github Turfjs / turf / packages / turf-interpolate / index.js View on Github external
// default values
    property = property || 'elevation';
    gridType = gridType || 'square';
    weight = weight || 1;

    var box = bbox(points);
    var grid;
    switch (gridType) {
    case 'point':
    case 'points':
        grid = poinGrid(box, cellSize, {units: units, bboxIsMask: true});
        break;
    case 'square':
    case 'squares':
        grid = squareGrid(box, cellSize, {units: units});
        break;
    case 'hex':
    case 'hexes':
        grid = hexGrid(box, cellSize, {units: units});
        break;
    case 'triangle':
    case 'triangles':
        grid = triangleGrid(box, cellSize, {units: units});
        break;
    default:
        throw new Error('invalid gridType');
    }
    var results = [];
    featureEach(grid, function (gridFeature) {
        var zw = 0;
        var sw = 0;

@turf/square-grid

turf square-grid module

MIT
Latest version published 4 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/square-grid functions