How to use the turf.linestring function in turf

To help you get started, we’ve selected a few turf 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 mapbox / osm-sidewalker / sidewalker.js View on Github external
function clipNormalize(features, tile) {

  var newLines = [];

  for (var i = 0; i < features.length; i++) {
    if (features[i].geometry.type !== 'LineString' && features[i].geometry.type !== 'MultiLineString') continue;
    
    var coords = (features[i].geometry.type === 'MultiLineString') ? 
      features[i].geometry.coordinates :
      [features[i].geometry.coordinates];

    for (var c = 0; c < coords.length; c++) {
      // Certain erroneous linestrings are present in the ways data. Possibly an artifact
      // of tile clippingice
      if (coords[c].length > 0 && typeof coords[c][0] === 'number') continue;
      newLines.push(turf.linestring(coords[c], features[i].properties));
    }
  }
  
  return newLines;
}
github mapbox / osrm-matching-inspection / src / match_trace.js View on Github external
function filterGeoJSON(geojson) {
  var outputLine = turf.linestring([]),
      outputGeoJSON = turf.featurecollection([]),
      minTimeDiff = 5, // 12 sampels / minute
      minDistance = 20;

  var feature = geojson.features[0],
      coords = feature.geometry.coordinates,
      times = feature.properties && feature.properties.coordTimes || null,
      prevCoord,
      prevTime,
      newCoords,
      newTimes = [];

  // added no times option
  if (times && !times[0].match(/^\d+$/)) {
    // check if for special fucked up date format.
    if (times[0].match(/^\d\d\d\d-\d-\d\d/)) {
github mapbox / cheap-ruler / bench / bench-line-slice-along.js View on Github external
'turf.along + turf.lineSlice': function () {
        for (var i = 0; i < lines.length; i++) {
            var feature = turf.linestring(lines[i]);
            turf.lineSlice(
                turf.along(feature, distances[i] * 0.3),
                turf.along(feature, distances[i] * 0.7),
                turf.linestring(lines[i]));
        }
    },
    'ruler.lineSliceAlong': function () {
github mapbox / cheap-ruler / bench / bench-point-on-line.js View on Github external
'turf.pointOnLine': function () {
        for (var i = 0; i < lines.length; i++) {
            turf.pointOnLine(turf.linestring(lines[i]), turf.point(p));
        }
    },
    'ruler.pointOnLine': function () {
github fidelthomet / WHERE / scripts / inquire.js View on Github external
if(lineIntersect(linestring.geometry, obj.geometry)){
			result = true
		} else {
			for (var i = 0; i < obj.geometry.coordinates.length; i++) {
				point = turf.point(obj.geometry.coordinates[i])
				if(turf.inside(point, feature)){
					result = true
					break
				}
			}
		}
	}

	if (obj.geometry.type == "Polygon" && type == "LineString"){
		result = false
		var linestring = turf.linestring(obj.geometry.coordinates[0])
		if(lineIntersect(linestring.geometry, feature.geometry)){
			result = true
		} else {
			for (var i = 0; i < feature.geometry.coordinates.length; i++) {
				point = turf.point(feature.geometry.coordinates[i])
				if(turf.inside(point, obj)){
					result = true
					break
				}
			}
		}
	}

	if (obj.geometry.type == "LineString" && type == "LineString"){
		if(lineIntersect(obj.geometry, feature.geometry)){
			result = true
github mapbox / cheap-ruler / bench / bench-line-slice-along.js View on Github external
'turf.along + turf.lineSlice': function () {
        for (var i = 0; i < lines.length; i++) {
            var feature = turf.linestring(lines[i]);
            turf.lineSlice(
                turf.along(feature, distances[i] * 0.3),
                turf.along(feature, distances[i] * 0.7),
                turf.linestring(lines[i]));
        }
    },
    'ruler.lineSliceAlong': function () {