How to use the @turf/helpers.radiansToLength function in @turf/helpers

To help you get started, we’ve selected a few @turf/helpers 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 Turfjs / turf / packages / turf-standard-deviational-ellipse / index.js View on Github external
// Calculate axes:
    // sigmaX = sqrt((1 / n - 2) * sum((((x - X) * cos(theta)) - ((y - Y) * sin(theta)))^2))
    // sigmaY = sqrt((1 / n - 2) * sum((((x - X) * sin(theta)) - ((y - Y) * cos(theta)))^2))
    var sigmaXsum = 0;
    var sigmaYsum = 0;
    featureEach(points, function(point){
      xDeviation = getCoords(point)[0] - getCoords(theMeanCenter)[0];
      yDeviation = getCoords(point)[1] - getCoords(theMeanCenter)[1];
      sigmaXsum += Math.pow((xDeviation * Math.cos(theta)) - (yDeviation * Math.sin(theta)), 2);
      sigmaYsum += Math.pow((xDeviation * Math.sin(theta)) - (yDeviation * Math.cos(theta)), 2);
    });

    var sigmaX = Math.sqrt(sigmaXsum * (1 / (n)));
    var sigmaY = Math.sqrt(sigmaYsum * (1 / (n)));
    sigmaX = radiansToLength(degreesToRadians(sigmaX));
    sigmaY = radiansToLength(degreesToRadians(sigmaY));

    theta = radiansToDegrees(theta);
    var semiMajorAxis, semiMinorAxis;
    if (sigmaX > sigmaY) {
      semiMajorAxis = sigmaX;
      semiMinorAxis = sigmaY;
    } else {
      semiMinorAxis = sigmaX;
      semiMajorAxis = sigmaY;
      theta = theta - 90;
    }

    var theEllipse = ellipse(meanCenter, semiMajorAxis, semiMinorAxis, {angle: theta, steps: steps, properties: properties});
    var eccentricity = (Math.sqrt(Math.pow(semiMajorAxis, 2) - Math.pow(semiMinorAxis, 2))) / semiMajorAxis;
    var pointsWithinEllipse = pointsWithinPolygon(points, turf.featureCollection([theEllipse]));
    var standardDeviationalEllipseProperties = {
github Turfjs / turf / packages / turf-standard-deviational-ellipse / index.js View on Github external
// Calculate axes:
    // sigmaX = sqrt((1 / n - 2) * sum((((x - X) * cos(theta)) - ((y - Y) * sin(theta)))^2))
    // sigmaY = sqrt((1 / n - 2) * sum((((x - X) * sin(theta)) - ((y - Y) * cos(theta)))^2))
    var sigmaXsum = 0;
    var sigmaYsum = 0;
    featureEach(points, function(point){
      xDeviation = getCoords(point)[0] - getCoords(theMeanCenter)[0];
      yDeviation = getCoords(point)[1] - getCoords(theMeanCenter)[1];
      sigmaXsum += Math.pow((xDeviation * Math.cos(theta)) - (yDeviation * Math.sin(theta)), 2);
      sigmaYsum += Math.pow((xDeviation * Math.sin(theta)) - (yDeviation * Math.cos(theta)), 2);
    });

    var sigmaX = Math.sqrt(sigmaXsum * (1 / (n)));
    var sigmaY = Math.sqrt(sigmaYsum * (1 / (n)));
    sigmaX = radiansToLength(degreesToRadians(sigmaX));
    sigmaY = radiansToLength(degreesToRadians(sigmaY));

    theta = radiansToDegrees(theta);
    var semiMajorAxis, semiMinorAxis;
    if (sigmaX > sigmaY) {
      semiMajorAxis = sigmaX;
      semiMinorAxis = sigmaY;
    } else {
      semiMinorAxis = sigmaX;
      semiMajorAxis = sigmaY;
      theta = theta - 90;
    }

    var theEllipse = ellipse(meanCenter, semiMajorAxis, semiMinorAxis, {angle: theta, steps: steps, properties: properties});
    var eccentricity = (Math.sqrt(Math.pow(semiMajorAxis, 2) - Math.pow(semiMinorAxis, 2))) / semiMajorAxis;
    var pointsWithinEllipse = pointsWithinPolygon(points, turf.featureCollection([theEllipse]));
github cheeaun / taxirouter-sg / assets / turf.js View on Github external
// Optional parameters
    options = options || {};
    if (!helpers.isObject(options)) throw new Error('options is invalid');
    var units = options.units;

    var coordinates1 = invariant.getCoord(from);
    var coordinates2 = invariant.getCoord(to);
    var dLat = helpers.degreesToRadians((coordinates2[1] - coordinates1[1]));
    var dLon = helpers.degreesToRadians((coordinates2[0] - coordinates1[0]));
    var lat1 = helpers.degreesToRadians(coordinates1[1]);
    var lat2 = helpers.degreesToRadians(coordinates2[1]);

    var a = Math.pow(Math.sin(dLat / 2), 2) +
          Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);

    return helpers.radiansToLength(2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)), units);
}
github Turfjs / turf / packages / turf-kernel_density / index.js View on Github external
_stdDistance = function (points, weight, centroid, pointsCount) {
            let
                isWeighted = weight !== undefined && weight.length !== 0,
                m = getCoord(centroid),
                // added latitude correction factor to finetune the 'radiansToLength' function
                latCorrection = Math.cos(degreesToRadians(m[1])),
                _sum = featureReduce(output, (prev, current) => {
                    let
                        w = isWeighted ? (current.properties[weight] || 0) : 1,
                        c = getCoord(current).map((a, i) => Math.pow(w * a - m[i], 2));
                    return prev.map((a, i) => a + c[i]);
                }, [0, 0]),
                degDist = Math.sqrt((_sum[0] + _sum[1]) / pointsCount);
            return radiansToLength(degreesToRadians(degDist), 'kilometers') / latCorrection;
        };
github Turfjs / turf / packages / turf-distance / index.ts View on Github external
function distance(from: Coord, to: Coord, options: {
    units?: Units,
} = {}) {
    var coordinates1 = getCoord(from);
    var coordinates2 = getCoord(to);
    var dLat = degreesToRadians((coordinates2[1] - coordinates1[1]));
    var dLon = degreesToRadians((coordinates2[0] - coordinates1[0]));
    var lat1 = degreesToRadians(coordinates1[1]);
    var lat2 = degreesToRadians(coordinates2[1]);

    var a = Math.pow(Math.sin(dLat / 2), 2) +
          Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);

    return radiansToLength(2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)), options.units);
}
github antvis / L7 / packages / utils / src / geo.ts View on Github external
export function lnglatDistance(
  coordinates1: [number, number],
  coordinates2: [number, number],
  units?: Units,
): number {
  const dLat = degreesToRadians(coordinates2[1] - coordinates1[1]);
  const dLon = degreesToRadians(coordinates2[0] - coordinates1[0]);
  const lat1 = degreesToRadians(coordinates1[1]);
  const lat2 = degreesToRadians(coordinates2[1]);
  const a =
    Math.pow(Math.sin(dLat / 2), 2) +
    Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);

  return radiansToLength(
    2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)),
    (units = 'meters'),
  );
}