How to use the @turf/turf.lineIntersect function in @turf/turf

To help you get started, we’ve selected a few @turf/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 osmlab / osmlint / validators / overlapHighways / map.js View on Github external
bboxes.push(bboxHighway);
      highways[val.properties['@id']] = val;
    }
  }
  var traceTree = rbush(bboxes.length);
  traceTree.load(bboxes);
  var output = {};
  for (var j = 0; j < bboxes.length; j++) {
    var bbox = bboxes[j];
    var overlaps = traceTree.search(bbox);
    for (var k = 0; k < overlaps.length; k++) {
      var overlap = overlaps[k];
      if (bbox.id !== overlap.id) {
        var fromHighway = highways[bbox.id];
        var toHighway = highways[overlap.id];
        var intersect = turf.lineIntersect(toHighway, fromHighway);
        if (intersect && intersect.features.length > 0) {
          if (intersect.features.length > 1) {
            intersect = turf.combine(intersect);
          }
          intersect = intersect.features[0];
          // if (intersect.geometry.type === 'LineString' || intersect.geometry.type === 'MultiLineString') {
          var coordinates = intersect.geometry.coordinates;
          var type;
          if (
            majorRoads[fromHighway.properties.highway] &&
            majorRoads[toHighway.properties.highway]
          ) {
            type = 'major-major';
          } else if (
            (majorRoads[fromHighway.properties.highway] &&
              minorRoads[toHighway.properties.highway]) ||
github osmlab / osmlint / validators / selfIntersectingHighways / map.js View on Github external
highwayToEvaluate.properties.highway
    );
    if (repeatedCoords.length > 1) {
      // Save multipoints
      for (var p = 0; p < repeatedCoords.length; p++) {
        var repeatedPoint = turf.point(repeatedCoords[p]);
        repeatedPoint.properties._osmlint = osmlint;
        repeatedPoint.properties._fromWay = highwayToEvaluate.properties['@id'];
        repeatedPoint.properties._type = type;
        result.push(repeatedPoint);
      }
      highwayToEvaluate.properties._type = type;
      highwayToEvaluate.properties._osmlint = osmlint;
      result.push(highwayToEvaluate);
    } else {
      var intersect = turf.lineIntersect(highwayToEvaluate, highwayToEvaluate);
      if (intersect && intersect.features.length > 0) {
        if (intersect.features.length > 1) {
          intersect = turf.combine(intersect);
        }
        intersect = intersect.features[0];
        if (
          intersect.geometry.coordinates.length + 1 >
          highwayToEvaluateCoords.length
        ) {
          var intersectObjs = {};
          for (var m = 0; m < intersect.geometry.coordinates.length; m++) {
            if (!vhObjs[intersect.geometry.coordinates[m].join('-')]) {
              intersectObjs[intersect.geometry.coordinates[m].join('-')] =
                intersect.geometry.coordinates[m];
            }
          }
github osmlab / osmlint / validators / crossingWaterwaysHighways / map.js View on Github external
waterways[idWaterway] = val;
    } else if (val.properties.ford === 'yes' && val.geometry.type === 'Point') {
      fords[val.geometry.coordinates.join(',')] = true;
    }
  }

  var highwaysTree = rbush(highwaybboxes.length);
  highwaysTree.load(highwaybboxes);
  var output = {};

  for (var j = 0; j < waterwaybboxes.length; j++) {
    var waterBbox = waterwaybboxes[j];
    var overlaphighwaysBbox = highwaysTree.search(waterBbox);
    for (var k = 0; k < overlaphighwaysBbox.length; k++) {
      var overlapHigBbox = overlaphighwaysBbox[k];
      var intersect = turf.lineIntersect(
        highways[overlapHigBbox.id],
        waterways[waterBbox.id]
      );
      // var intersectPoint = turf.lineIntersect(overlapObj, objToEvaluate);
      if (intersect && intersect.features.length > 0) {
        if (intersect.features.length > 1) {
          intersect = turf.combine(intersect); //conver to feature collection
        }
        intersect = intersect.features[0];
        var props = {
          _fromWay: highways[overlapHigBbox.id].properties['@id'],
          _toWay: waterways[waterBbox.id].properties['@id'],
          _osmlint: osmlint,
          _type: classification(
            majorRoads,
            minorRoads,
github osmlab / osmlint / validators / crossingHighwaysBridges / map.js View on Github external
function isIntersectingInNode(road1, road2) {
  var intersectPoint = turf.lineIntersect(road1, road2);
  if (intersectPoint.features.length > 0) {
    if (intersectPoint.features.length > 1) {
      intersectPoint = turf.combine(intersectPoint);
    }
    intersectPoint = intersectPoint.features[0];
    if (
      intersectPoint &&
      (intersectPoint.geometry.type === 'Point' ||
        intersectPoint.geometry.type === 'MultiPoint')
    ) {
      var intersectCoords = _.flatten(intersectPoint.geometry.coordinates);
      var roadsCoords = _.flatten([
        road1.geometry.coordinates,
        road2.geometry.coordinates
      ]);
      if (_.intersection(intersectCoords, roadsCoords).length === 0) {
github osmlab / osmlint / validators / crossingHighways / map.js View on Github external
var highwaysTree = rbush(highwaysBboxes.length);
  highwaysTree.load(highwaysBboxes);
  var output = {};
  for (var j = 0; j < highwaysBboxes.length; j++) {
    var bbox = highwaysBboxes[j];
    var highwayToEvaluate = listOfHighways[bbox.id];
    var overlaps = highwaysTree.search(bbox);
    for (var k = 0; k < overlaps.length; k++) {
      var overlapBbox = overlaps[k];
      var overlapHighway = listOfHighways[overlapBbox.id];
      if (
        bbox.id !== overlapBbox.id &&
        isIntersecting(highwayToEvaluate, overlapHighway) &&
        !checkCoordinates(highwayToEvaluate, overlapHighway)
      ) {
        var intersectPoint = turf.lineIntersect(
          overlapHighway,
          highwayToEvaluate
        );
        if (intersectPoint && intersectPoint.features.length > 0) {
          intersectPoint = intersectPoint.features[0];
          if (
            intersectPoint.geometry.type === 'Point' ||
            intersectPoint.geometry.type === 'MultiPoint'
          ) {
            var mergeHighwaysCoords = _.flatten(
              overlapHighway.geometry.coordinates
            );
            mergeHighwaysCoords.concat(
              _.flatten(highwayToEvaluate.geometry.coordinates)
            );
            var intersectPointCoord = _.flatten(
github osmlab / osmlint / validators / junctionsToSplit / map.js View on Github external
valueHighway.properties._osmlint = osmlint;
    if (valueHighway.properties.highway === 'motorway_link') {
      var overlaps = highwaysTree.search(valueBbox);
      var isEntrance = false;
      var valueHighwayCoords = valueHighway.geometry.coordinates;
      var intersectHighway;
      for (var k = 0; k < overlaps.length; k++) {
        var overlap = overlaps[k];
        var isIntersect = false;
        var overlapHighway = highways[overlap.id];
        if (
          valueHighway.properties['@id'] !== overlapHighway.properties['@id'] &&
          overlapHighway.properties.highway !== 'motorway_link'
        ) {
          var overlapHighwayCoords = overlapHighway.geometry.coordinates;
          var intersection = turf.lineIntersect(valueHighway, overlapHighway);
          if (intersection && intersection.features.length > 0) {
            intersection = intersection.features[0];
            var interCoordsF = flatten(intersection.geometry.coordinates);
            if (
              _.intersection(valueHighwayCoords[0], interCoordsF).length === 2
            ) {
              isEntrance = true;
            }
            if (
              _.intersection(valueHighwayCoords[0], interCoordsF).length !==
                2 &&
              _.intersection(
                valueHighwayCoords[valueHighwayCoords.length - 1],
                interCoordsF
              ).length !== 2
            ) {
github osmlab / osmlint / validators / crossingHighwaysBuildings / map.js View on Github external
}
  }

  var objsTree = rbush(objsBboxes.length);
  objsTree.load(objsBboxes);
  var output = {};
  for (var j = 0; j < objsBboxes.length; j++) {
    var bbox = objsBboxes[j];
    var objToEvaluate = listOfObjects[bbox.id];
    if (objToEvaluate.properties.highway) {
      var overlaps = objsTree.search(bbox);
      for (var k = 0; k < overlaps.length; k++) {
        var overlapBbox = overlaps[k];
        var overlapObj = listOfObjects[overlapBbox.id];
        if (overlapObj.properties.building) {
          var intersectPoint = turf.lineIntersect(overlapObj, objToEvaluate);
          if (intersectPoint && intersectPoint.features.length > 0) {
            if (intersectPoint.features.length > 1) {
              intersectPoint = turf.combine(intersectPoint); //conver to feature collection
            }
            intersectPoint = intersectPoint.features[0];
            if (
              (intersectPoint.geometry.type === 'Point' &&
                listOfAvoidPoints[
                  intersectPoint.geometry.coordinates.join(',')
                ]) ||
              intersectPoint.geometry.type === 'MultiPoint'
            ) {
              objToEvaluate.properties._osmlint = osmlint;
              overlapObj.properties._osmlint = osmlint;
              intersectPoint.properties = {
                _fromWay: objToEvaluate.properties['@id'],
github osmlab / osmlint / validators / selfIntersectingWaterway / map.js View on Github external
var osmlint = 'selfintersectingwaterway';
  var result = [];
  var preserveType = {
    river: true,
    stream: true,
    canal: true,
    drain: true
  };
  for (var i = 0; i < layer.features.length; i++) {
    var val = layer.features[i];
    if (
      val.properties.waterway &&
      preserveType[val.properties.waterway] &&
      val.geometry.type === 'LineString'
    ) {
      var intersect = turf.lineIntersect(val, val);
      if (intersect && intersect.features.length > 0) {
        if (
          intersect &&
          intersect.features.length + 1 > val.geometry.coordinates.length
        ) {
          var coords = {};
          for (var x = 0; x < val.geometry.coordinates.length; x++) {
            var coord = val.geometry.coordinates[x];
            coords[coord.join('-')] = true;
          }
          var pointFC = turf.explode(intersect);
          var intersectObjs = [];
          for (var n = 0; n < pointFC.features.length; n++) {
            var p = pointFC.features[n];
            if (!coords[p.geometry.coordinates.join('-')]) {
              intersectObjs.push(p.geometry.coordinates);