How to use the @turf/helpers.lengthToRadians 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-buffer / index.js View on Github external
var bbox = turfBbox(geojson);
    var needsTransverseMercator = bbox[1] > 50 && bbox[3] > 50;

    if (needsTransverseMercator) {
        projected = {
            type: geometry.type,
            coordinates: projectCoords(geometry.coordinates, defineProjection(geometry))
        };
    } else {
        projected = toMercator(geometry);
    }

    // JSTS buffer operation
    var reader = new GeoJSONReader();
    var geom = reader.read(projected);
    var distance = radiansToLength(lengthToRadians(radius, units), 'meters');
    var buffered = BufferOp.bufferOp(geom, distance);
    var writer = new GeoJSONWriter();
    buffered = writer.write(buffered);

    // Detect if empty geometries
    if (coordsIsNaN(buffered.coordinates)) return undefined;

    // Unproject coordinates (convert to Degrees)
    var result;
    if (needsTransverseMercator) {
        result = {
            type: buffered.type,
            coordinates: unprojectCoords(buffered.coordinates, defineProjection(geometry))
        };
    } else {
        result = toWgs84(buffered);
github Turfjs / turf / packages / turf-destination / index.ts View on Github external
export default function destination<p>(
    origin: Coord,
    distance: number,
    bearing: number,
    options: {
        units?: Units,
        properties?: P,
    } = {},
): Feature {
    // Handle input
    const coordinates1 = getCoord(origin);
    const longitude1 = degreesToRadians(coordinates1[0]);
    const latitude1 = degreesToRadians(coordinates1[1]);
    const bearingRad = degreesToRadians(bearing);
    const radians = lengthToRadians(distance, options.units);

    // Main
    const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
        Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
    const longitude2 = longitude1 + Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),
        Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
    const lng = radiansToDegrees(longitude2);
    const lat = radiansToDegrees(latitude2);

    return point([lng, lat], options.properties);
}
</p>
github cheeaun / taxirouter-sg / assets / turf.js View on Github external
function destination(origin, distance, bearing, options) {
    // Optional parameters
    options = options || {};
    if (!helpers.isObject(options)) throw new Error('options is invalid');
    var units = options.units;
    var properties = options.properties;

    // Handle input
    var coordinates1 = invariant.getCoord(origin);
    var longitude1 = helpers.degreesToRadians(coordinates1[0]);
    var latitude1 = helpers.degreesToRadians(coordinates1[1]);
    var bearing_rad = helpers.degreesToRadians(bearing);
    var radians = helpers.lengthToRadians(distance, units);

    // Main
    var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
        Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_rad));
    var longitude2 = longitude1 + Math.atan2(Math.sin(bearing_rad) * Math.sin(radians) * Math.cos(latitude1),
        Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
    var lng = helpers.radiansToDegrees(longitude2);
    var lat = helpers.radiansToDegrees(latitude2);

    return helpers.point([lng, lat], properties);
}
github wbkd / leaflet-truesize / src / helper.js View on Github external
export function destination(origin, distance, bearing, options) {
  var degrees2radians = Math.PI / 180;
  var radians2degrees = 180 / Math.PI;
  // Optional parameters
  options = options || {};
  if (!isObject(options)) throw new Error('options is invalid');
  var units = options.units;
  var properties = options.properties;
  // Optional parameters

  // Handle input
  var coordinates1 = getCoord(origin);
  var longitude1 = degrees2radians * coordinates1[0];
  var latitude1 = degrees2radians * coordinates1[1];
  var bearing_rad = degrees2radians * bearing;
  var radians = lengthToRadians(distance, units);

  // Main
  var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
      Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_rad));
  var longitude2 = longitude1 + Math.atan2(Math.sin(bearing_rad) * Math.sin(radians) * Math.cos(latitude1),
      Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
  var lng = radians2degrees * longitude2;
  var lat = radians2degrees * latitude2;

  return point([lng, lat], properties);
}