How to use the @turf/rhumb-destination function in @turf/rhumb-destination

To help you get started, we’ve selected a few @turf/rhumb-destination 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-isolines / lib / matrix-to-grid.js View on Github external
for (var row = 1; row < matrixRows; row++) {
        if (matrix[row].length !== matrixCols) throw new Error('matrix requires all rows of equal size');
    }

    var points = [];
    for (var r = 0; r < matrixRows; r++) {
        // create first point in the row
        var first = rhumbDestination(origin, cellSize * r, 0, { units: units });
        first.properties[zProperty] = matrix[matrixRows - 1 - r][0];
        for (var prop in properties) {
            first.properties[prop] = properties[prop];
        }
        points.push(first);
        for (var c = 1; c < matrixCols; c++) {
            // create the other points in the same row
            var pt = rhumbDestination(first, cellSize * c, 90, { units: units });
            for (var prop2 in properties) {
                pt.properties[prop2] = properties[prop2];
            }
            // add matrix property
            var val = matrix[matrixRows - 1 - r][c];
            pt.properties[zProperty] = val;
            points.push(pt);
        }
    }
    var grid = featureCollection(points);
    return grid;
}
github Turfjs / turf / packages / turf-ellipse / index.js View on Github external
var pivot = options.pivot || center;
    var properties = options.properties || center.properties || {};

    // validation
    if (!center) throw new Error('center is required');
    if (!xSemiAxis) throw new Error('xSemiAxis is required');
    if (!ySemiAxis) throw new Error('ySemiAxis is required');
    if (!isObject(options)) throw new Error('options must be an object');
    if (!isNumber(steps)) throw new Error('steps must be a number');
    if (!isNumber(angle)) throw new Error('angle must be a number');

    var centerCoords = getCoord(center);
    if (units === 'degrees') {
        var angleRad = degreesToRadians(angle);
    } else {
        xSemiAxis = rhumbDestination(center, xSemiAxis, 90, {units: units});
        ySemiAxis = rhumbDestination(center, ySemiAxis, 0, {units: units});
        xSemiAxis = getCoord(xSemiAxis)[0] - centerCoords[0];
        ySemiAxis = getCoord(ySemiAxis)[1] - centerCoords[1];
    }

    var coordinates = [];
    for (var i = 0; i < steps; i += 1) {
        var stepAngle = i * -360 / steps;
        var x = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(ySemiAxis, 2) + (Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2))));
        var y = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(xSemiAxis, 2) + (Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2))));

        if (stepAngle < -90 && stepAngle >= -270) x = -x;
        if (stepAngle < -180 && stepAngle >= -360) y = -y;
        if (units === 'degrees') {
            var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
            var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
github Turfjs / turf / packages / turf-isolines / lib / matrix-to-grid.js View on Github external
if (!matrix || !Array.isArray(matrix)) throw new Error('matrix is required');
    if (!origin) throw new Error('origin is required');
    if (Array.isArray(origin)) {
        origin = point(origin); // Convert coordinates array to point
    }
    // all matrix array have to be of the same size
    var matrixCols = matrix[0].length;
    var matrixRows = matrix.length;
    for (var row = 1; row < matrixRows; row++) {
        if (matrix[row].length !== matrixCols) throw new Error('matrix requires all rows of equal size');
    }

    var points = [];
    for (var r = 0; r < matrixRows; r++) {
        // create first point in the row
        var first = rhumbDestination(origin, cellSize * r, 0, { units: units });
        first.properties[zProperty] = matrix[matrixRows - 1 - r][0];
        for (var prop in properties) {
            first.properties[prop] = properties[prop];
        }
        points.push(first);
        for (var c = 1; c < matrixCols; c++) {
            // create the other points in the same row
            var pt = rhumbDestination(first, cellSize * c, 90, { units: units });
            for (var prop2 in properties) {
                pt.properties[prop2] = properties[prop2];
            }
            // add matrix property
            var val = matrix[matrixRows - 1 - r][c];
            pt.properties[zProperty] = val;
            points.push(pt);
        }
github Turfjs / turf / packages / turf-ellipse / index.js View on Github external
var properties = options.properties || center.properties || {};

    // validation
    if (!center) throw new Error('center is required');
    if (!xSemiAxis) throw new Error('xSemiAxis is required');
    if (!ySemiAxis) throw new Error('ySemiAxis is required');
    if (!isObject(options)) throw new Error('options must be an object');
    if (!isNumber(steps)) throw new Error('steps must be a number');
    if (!isNumber(angle)) throw new Error('angle must be a number');

    var centerCoords = getCoord(center);
    if (units === 'degrees') {
        var angleRad = degreesToRadians(angle);
    } else {
        xSemiAxis = rhumbDestination(center, xSemiAxis, 90, {units: units});
        ySemiAxis = rhumbDestination(center, ySemiAxis, 0, {units: units});
        xSemiAxis = getCoord(xSemiAxis)[0] - centerCoords[0];
        ySemiAxis = getCoord(ySemiAxis)[1] - centerCoords[1];
    }

    var coordinates = [];
    for (var i = 0; i < steps; i += 1) {
        var stepAngle = i * -360 / steps;
        var x = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(ySemiAxis, 2) + (Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2))));
        var y = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(xSemiAxis, 2) + (Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2))));

        if (stepAngle < -90 && stepAngle >= -270) x = -x;
        if (stepAngle < -180 && stepAngle >= -360) y = -y;
        if (units === 'degrees') {
            var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
            var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
            x = newx;
github Turfjs / turf / packages / turf-transform-scale / index.js View on Github external
coordEach(feature, function (coord) {
        var originalDistance = rhumbDistance(origin, coord);
        var bearing = rhumbBearing(origin, coord);
        var newDistance = originalDistance * factor;
        var newCoord = getCoords(rhumbDestination(origin, newDistance, bearing));
        coord[0] = newCoord[0];
        coord[1] = newCoord[1];
        if (coord.length === 3) coord[2] *= factor;
    });
github Turfjs / turf / packages / turf-transform-rotate / index.js View on Github external
coordEach(geojson, function (pointCoords) {
        var initialAngle = rhumbBearing(pivot, pointCoords);
        var finalAngle = initialAngle + angle;
        var distance = rhumbDistance(pivot, pointCoords);
        var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));
        pointCoords[0] = newCoords[0];
        pointCoords[1] = newCoords[1];
    });
    return geojson;
github Turfjs / turf / packages / turf-transform-translate / index.js View on Github external
coordEach(geojson, function (pointCoords) {
        var newCoords = getCoords(rhumbDestination(pointCoords, distance, direction, units));
        pointCoords[0] = newCoords[0];
        pointCoords[1] = newCoords[1];
        if (zTranslation && pointCoords.length === 3) pointCoords[2] += zTranslation;
    });
    return geojson;

@turf/rhumb-destination

turf rhumb-destination module

MIT
Latest version published 3 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/rhumb-destination functions