How to use the @turf/distance.default function in @turf/distance

To help you get started, we’ve selected a few @turf/distance 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 ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
1.5
          ]
        }
      };
      var foundFeatures = [];
      var closestDistance = 100000000000;
      var closest;

      var iterator = queryTestFeatureDao.queryIndexedFeaturesWithBoundingBox(bb);

      for (var row of iterator) {
        foundFeatures.push(row.values.name);
        var geometry = row.getGeometry().toGeoJSON();

        if (geometry.type == 'Point') {
          var distance = pointDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'LineString') {
          var distance = pointToLineDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
github hotosm / MapCampaigner / lambda_functions / process / make_pdf_grid / index.js View on Github external
async function main(event) {
    const response = await getS3File(event.campaign_uuid);
    const f = JSON.parse(response).features
    const options = {units:"meters"}
    const features = []
    for (let i = 0; i < f.length; i++) {
        const box = bbox(f[i]);
        const w = distance([box[0], box[1]],[box[2],box[1]],{units:"meters"})
        const h = distance([box[0], box[1]],[box[0],box[3]],{units:"meters"})
        const wDiff = 1000 - (w % 1000);
        const hDiff = 706 - (h % 706);
        const poly = bboxPolygon(box);
        const c = centerOfMass(poly);
        const maxY = destination(c,(50 + h + hDiff)/2, 0, options).geometry.coordinates[1];
        const minY = destination(c,(50 +h + hDiff)/2, 180,options).geometry.coordinates[1];
        const maxX = destination(c,(50 + w + wDiff)/2, 90,options).geometry.coordinates[0];
        const minX = destination(c,(50 + w + wDiff)/2, -90,options).geometry.coordinates[0];
        const grid = rectangleGrid([minX, minY, maxX, maxY], 1000, 706, {units:"meters"});
        for (let j=0; j
github hotosm / MapCampaigner / lambda_functions / process / make_pdf_grid / index.js View on Github external
async function main(event) {
    const response = await getS3File(event.campaign_uuid);
    const f = JSON.parse(response).features
    const options = {units:"meters"}
    const features = []
    for (let i = 0; i < f.length; i++) {
        const box = bbox(f[i]);
        const w = distance([box[0], box[1]],[box[2],box[1]],{units:"meters"})
        const h = distance([box[0], box[1]],[box[0],box[3]],{units:"meters"})
        const wDiff = 1000 - (w % 1000);
        const hDiff = 706 - (h % 706);
        const poly = bboxPolygon(box);
        const c = centerOfMass(poly);
        const maxY = destination(c,(50 + h + hDiff)/2, 0, options).geometry.coordinates[1];
        const minY = destination(c,(50 +h + hDiff)/2, 180,options).geometry.coordinates[1];
        const maxX = destination(c,(50 + w + wDiff)/2, 90,options).geometry.coordinates[0];
        const minX = destination(c,(50 + w + wDiff)/2, -90,options).geometry.coordinates[0];
        const grid = rectangleGrid([minX, minY, maxX, maxY], 1000, 706, {units:"meters"});
        for (let j=0; j
github mapstertech / mapbox-gl-draw-rotate-mode / index.js View on Github external
state.originalFeature.geometry.coordinates.forEach(function(coords,index) {
                var distanceFromCenter = distance(state.originalCenter, coords);
                var bearingFromCenter = bearing(state.originalCenter, coords);
                var newPoint = destination(state.originalCenter, distanceFromCenter, bearingFromCenter+draggedBearing);
                rotatedCoords.push(newPoint.geometry.coordinates);
              })
              break;

@turf/distance

turf distance module

MIT
Latest version published 5 months ago

Package Health Score

97 / 100
Full package analysis

Popular @turf/distance functions