How to use the @turf/helpers.point 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-along / index.ts View on Github external
export default function along(
    line: Feature | LineString,
    distance: number,
    options: {units?: Units} = {},
): Feature {
    // Get Coords
    const geom = getGeom(line);
    const coords = geom.coordinates;
    let travelled = 0;
    for (let i = 0; i < coords.length; i++) {
        if (distance >= travelled && i === coords.length - 1) { break;
        } else if (travelled >= distance) {
            const overshot = distance - travelled;
            if (!overshot) { return point(coords[i]);
            } else {
                const direction = bearing(coords[i], coords[i - 1]) - 180;
                const interpolated = destination(coords[i], overshot, direction, options);
                return interpolated;
            }
        } else {
            travelled += measureDistance(coords[i], coords[i + 1], options);
        }
    }
    return point(coords[coords.length - 1]);
}
github conveyal / analysis-ui / lib / components / report / reroute.js View on Github external
if (modification.fromStop && modification.toStop) nStopsRemoved-- // -1 because it's an exclusive interval on both sides, don't include from and to stops

  let nStopsAdded = stops.length

  // the endpoints are included, subtract them off where they overlap with existing stops
  if (modification.fromStop) nStopsAdded--
  if (modification.toStop) nStopsAdded--

  // NB using indices here so we get an object even if fromStop or toStop is null
  // stops in pattern are in fact objects but they only have stop ID.
  const fromStop = feed.stopsById[pattern.stops[fromStopIndex].stop_id]
  const toStop = feed.stopsById[pattern.stops[toStopIndex].stop_id]

  const geometry = lineSlice(
    point([fromStop.stop_lon, fromStop.stop_lat]),
    point([toStop.stop_lon, toStop.stop_lat]),
    {
      type: 'Feature',
      geometry: pattern.geometry,
      properties: {}
    }
  )

  const removedLengthThisPattern = turfLength(geometry)

  return (
    <table>
      <tbody>
        <tr></tr></tbody></table>
github conveyal / analysis-ui / lib / utils / get-existing-stops-along-pattern.js View on Github external
stops.forEach(stop =&gt; {
      // Ignore the source segment's start and end stops
      if (stop.stop_id !== segment.fromStopId &amp;&amp; stop.stop_id !== segment.toStopId) {
        const stopPoint = turf.point([stop.stop_lon, stop.stop_lat])
        if (pointToLineDistance(stopPoint, line) &lt;= STOP_SEARCH_BUFFER_KM) {
          const pointOnLine = nearestPointOnLine(line, stopPoint)
          // Ignore points too close to start or end stops
          if ((!segment.stopAtStart ||
            pointOnLine.properties.location &gt; APPROX_MIN_SPACING_KM) &amp;&amp;
            (!segment.stopAtEnd ||
            segmentLengthKm - pointOnLine.properties.location &gt; APPROX_MIN_SPACING_KM)
          ) {
            pointOnLine.properties.stopId = stop.stop_id
            pointOnLine.properties.stopCoords = [stop.stop_lon, stop.stop_lat]
            candidateStops.push(pointOnLine)
          }
        }
      }
    })
    // cluster stops that are close to each other
github terascope / teraslice / packages / xlucene-evaluator / src / parser / functions / geo / helpers.ts View on Github external
return (fieldData: JoinGeoShape) => {
        let polygon: any;
        if (isGeoShapePoint(fieldData)) {
            return equal(searchPoint, tPoint(fieldData.coordinates));
        }

        if (isGeoShapeMultiPolygon(fieldData)) {
            polygon = multiPolygon(fieldData.coordinates);
        }

        if (isGeoShapePolygon(fieldData)) {
            polygon = tPolygon(fieldData.coordinates);
        }
        // Nothing matches so return false
        if (!polygon) return false;
        return pointInPolygon(searchPoint, polygon);
    };
}
github sensebox / openSenseMap-API / packages / api / lib / transformers / idwTransformer.js View on Github external
idwTransformer.prototype.addMeasurementToAverage = function addMeasurementToAverage (measurement, cb) {
  const value = measurement.value;

  // for breaks
  if (value &lt; this._min) {
    this._min = value;
  }

  if (value &gt; this._max) {
    this._max = value;
  }

  if (!Object.keys(this._averages).includes(measurement.sensorId)) {
    this._averages[measurement.sensorId] = {
      count: 0,
      geom: point([measurement.lon, measurement.lat], { average: value })
    };

    return cb();
  }

  const avg = this._averages[measurement.sensorId];

  avg.count = avg.count + 1;
  avg.geom.properties.average = (
    ((avg.geom.properties.average * avg.count) + value) /
    (avg.count + 1)
  );

  cb();
};
github terascope / teraslice / packages / xlucene-evaluator / src / parser / functions / geo / helpers.ts View on Github external
return (fieldData: JoinGeoShape) => {
        let feature: any;
        if (isGeoShapePoint(fieldData)) {
            feature = tPoint(fieldData.coordinates);
        }

        if (isGeoShapeMultiPolygon(fieldData)) {
            feature = multiPolygon(fieldData.coordinates);
        }

        if (isGeoShapePolygon(fieldData)) {
            feature = tPolygon(fieldData.coordinates);
        }
        // Nothing matches so return false
        if (!feature) return false;
        try {
            return match(feature);
        } catch (err) {
            return false;
        }
github simonepri / geojson-geometries-lookup / test / point-in-point.js View on Github external
const geojson = featureCollection([
    point([4, 6], {id: 1}),
    point([4, 1], {id: 2}),
    point([9, 6], {id: 3}),
    point([4, 6], {id: 4})
  ]);

  const glookup = new M(geojson);

  const testCases = [
    {p: point([1, 5]), s: false},
    {p: point([6, 3]), s: false},
    {p: point([4, 6]), s: true},
    {p: point([5.5, 3.5]), s: false},
    {p: point([4, 1]), s: true},
    {p: point([9, 6]), s: true},
    {p: point([9.7, 6.7]), s: false},
    {p: point([10, 11]), s: false},
    {p: point([4, 6]), s: true}
  ];
  testCases.forEach((tc, id) => {
    const res = glookup.hasContainers(tc.p.geometry);
    t.is(res, tc.s, 'Failed at: ' + id);
  });
});
github Turfjs / turf / packages / turf-collect / bench.js View on Github external
const Benchmark = require('benchmark');
const { polygon, featureCollection, point } = require('@turf/helpers');
const collect = require('./').default;

var poly1 = polygon([[[0, 0], [10, 0], [0, 10], [0, 10], [0, 0]]]);
var poly2 = polygon([[[10, 0], [20, 10], [20, 20], [20, 0], [10, 0]]]);
var polyFC = featureCollection([poly1, poly2]);
var pt1 = point([5, 5], {population: 200});
var pt2 = point([1, 3], {population: 600});
var pt3 = point([14, 2], {population: 100});
var pt4 = point([13, 1], {population: 200});
var pt5 = point([19, 7], {population: 300});

var ptFC = featureCollection([pt1, pt2, pt3, pt4, pt5]);
var suite = new Benchmark.Suite('turf-collect');
suite
  .add('turf-collect', function () {
      collect(polyFC, ptFC, 'population', 'outPopulation');
  })
  .on('cycle', function (event) {
      console.log(String(event.target));
  })
  .on('complete', function () {
  })
  .run();
github Turfjs / turf / packages / turf-center-mean / index.ts View on Github external
let sumYs = 0;
    let sumNs = 0;
    geomEach(geojson, function (geom, featureIndex, properties) {
        let weight = properties[options.weight];
        weight = (weight === undefined || weight === null) ? 1 : weight;
        if (!isNumber(weight)) throw new Error('weight value must be a number for feature index ' + featureIndex);
        weight = Number(weight);
        if (weight > 0) {
            coordEach(geom, function (coord) {
                sumXs += coord[0] * weight;
                sumYs += coord[1] * weight;
                sumNs += weight;
            });
        }
    });
    return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
}