How to use the @turf/helpers.lineString 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 sharedstreets / sharedstreets-js / src / geometry.ts View on Github external
break
      default:
        if (data.id) {
          // Save SharedStreets Intersection GeoJSON Point
          const id = data.id
          const coords = latlonsToCoords(data.latlons)
          const properties = {
            id: data.id,
            fromIntersectionId: data.fromIntersectionId,
            toIntersectionId: data.toIntersectionId,
            forwardReferenceId: data.forwardReferenceId,
            backReferenceId: data.backReferenceId,
            roadClass: data.roadClass,
          }
          // console.log(data.latlons)
          results.push(lineString(coords, properties, {id}))
        }
        // Reset Data
        data.id = null
        data.fromIntersectionId = null
        data.toIntersectionId = null
        data.forwardReferenceId = null
        data.backReferenceId = null
        data.roadClass = null
        data.latlons = []
        return data
    }
  }, {
    id: null,
github Turfjs / turf / packages / turf-line-segment / types.ts View on Github external
import {lineString, polygon, featureCollection, geometryCollection} from '@turf/helpers'
import lineSegment from './'

const poly = polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
const line = lineString([[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]);
const collection = featureCollection([poly, line]);
const geomCollection = geometryCollection([poly.geometry, line.geometry]);

// Test Types
lineSegment(poly)
lineSegment(line)
lineSegment(collection)
lineSegment(geomCollection)
github uber / nebula.gl / modules / layers / src / curve-utils.js View on Github external
// generate curve
  const result = [];
  for (let i = 0; i < coords.length; i++) {
    // add control point
    result.push(coords[i]);

    // add interpolated values
    for (let t = knots[i] + INTERPOLATION_INTERVAL; t < knots[i + 1]; t += INTERPOLATION_INTERVAL) {
      if (knots[i + 1] - t > INTERPOLATION_THRESHOLD) {
        // Only add if not too close to a control point (knot = control point)
        result.push(hermite(t, coords, tangents, knots));
      }
    }
  }

  return lineString(result);
}
github Turfjs / turf / packages / turf-line-split / index.js View on Github external
if (index === closestSegment.id) {
            previous.push(splitterCoords);
            results.push(lineString(previous));
            // Don't duplicate splitter coordinate (Issue #688)
            if (pointsEquals(splitterCoords, currentCoords)) return [splitterCoords];
            return [splitterCoords, currentCoords];

        // Keep iterating over coords until finished or intersection is found
        } else {
            previous.push(currentCoords);
            return previous;
        }
    }, initialValue);
    // Append last line to final split results
    if (lastCoords.length > 1) {
        results.push(lineString(lastCoords));
    }
    return featureCollection(results);
}
github sharedstreets / sharedstreets-js / test_core.ts View on Github external
test("sharedstreets -- forwardReference", (t:any) => {
  const line = lineString([[110, 45], [115, 50], [120, 55]]);
  const forwardReference = sharedstreets.forwardReference(line).id;
  const backReference = sharedstreets.backReference(line).id;

  t.equal(forwardReference, "035dc67e1230f1f6c6ec63997f86ba27");
  t.equal(backReference, "21993e8f0cdb8fa629418b78552a4503");
  t.end();
});
github Turfjs / turf / packages / turf-bbox / bench.js View on Github external
const load = require('load-json-file');
const Benchmark = require('benchmark');
const { lineString } = require('@turf/helpers');
const bbox = require('./').default;

const line = lineString([[-74, 40], [-78, 42], [-82, 35]]);

/**
 * Benchmark Results
 *
 */
const suite = new Benchmark.Suite('turf-bbox');
suite
    .add('line', () => bbox(line))
    .on('cycle', e => console.log(String(e.target)))
    .on('complete', () => {})
    .run();
github Turfjs / turf / packages / turf-line-segment / index.ts View on Github external
coords.reduce((previousCoords, currentCoords) => {
        const segment = lineString([previousCoords, currentCoords], properties);
        segment.bbox = bbox(previousCoords, currentCoords);
        segments.push(segment);
        return currentCoords;
    });
    return segments;
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
(lineString, prefix) => {
            const lineStringFeature = toLineString(lineString);
            const candidateIntermediatePoint = nearestPointOnLine(
              lineStringFeature,
              referencePoint
            );
            if (
              !intermediatePoint ||
              candidateIntermediatePoint.properties.dist < intermediatePoint.properties.dist
            ) {
              intermediatePoint = candidateIntermediatePoint;
              positionIndexPrefix = prefix;
            }
          }
        );
github Turfjs / turf / src / concave / lib / turf-line-dissolve.js View on Github external
if (s1 === e2) {
        coords = coords2.concat(coords1.slice(1));
    }
    else if (s2 === e1) {
        coords = coords1.concat(coords2.slice(1));
    }
    else if (s1 === s2) {
        coords = coords1.slice(1).reverse().concat(coords2);
    }
    else if (e1 === e2) {
        coords = coords1.concat(coords2.reverse().slice(1));
    }
    else {
        return null;
    }
    return helpers_1.lineString(coords);
}
exports.default = lineDissolve;
github sharedstreets / sharedstreets-js / src / tile_index.ts View on Github external
function createGeometry(data:SharedStreetsGeometry) {

    var line = turfHelpers.lineString(lonlatsToCoords(data.lonlats));
    return turfHelpers.feature(line.geometry, {id: data.id});
}