How to use the @turf/turf.combine 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 / selfIntersectingHighways / map.js View on Github external
// 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];
            }
          }
          var intersectCoords = _.values(intersectObjs);
          for (var t = 0; t < intersectCoords.length; t++) {
            var intersectPoint = turf.point(intersectCoords[t]);
github osmlab / osmlint / validators / crossingWaterwaysHighways / map.js View on Github external
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,
            pathRoads,
            highways[overlapHigBbox.id].properties.highway
          )
        };
        intersect.properties = props;
        highways[overlapHigBbox.id].properties._osmlint = osmlint;
        waterways[waterBbox.id].properties._osmlint = osmlint;
github osmlab / osmlint / validators / crossingBuildings / map.js View on Github external
if (val.geometry.type === 'Polygon' && val.properties.building) {
      var kinks = turf.kinks(val);
      if (kinks && kinks.features.length === 0) {
        // var valBbox = turf.bbox(val);
        // valBbox.push(val.properties['@id']);
        bboxes.push(objBbox(val));
        buildings[val.properties['@id']] = val;
      } else if (kinks && kinks.features.length === 1) {
        val.properties._osmlint = osmlint;
        kinks.features[0].properties._osmlint = osmlint;
        kinks.features[0].properties['@id'] = val.properties['@id'];
        //save detection
        output[val.properties['@id']] = val;
        output[val.properties['@id'] + 'P'] = kinks.features[0];
      } else if (kinks && kinks.features.length > 1) {
        var multiPt = turf.combine(kinks).features[0];
        multiPt.properties._osmlint = osmlint;
        multiPt.properties._fromWay = val.properties['@id'];
        //save detection
        output[val.properties['@id']] = val;
        output[val.properties['@id'] + 'M'] = multiPt;
      }
    }
  }
  var buildingTraceTree = rbush(bboxes.length);
  buildingTraceTree.load(bboxes);
  for (var z = 0; z < bboxes.length; z++) {
    var bbox = bboxes[z];
    var overlaps = buildingTraceTree.search(bbox);
    for (var k = 0; k < overlaps.length; k++) {
      var overlap = overlaps[k];
      if (overlap.id !== bbox.id) {
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) {
        return false;
      } else {
        return intersectPoint;
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'],
                _toWay: overlapObj.properties['@id'],
                _osmlint: osmlint,
                _type: classification(
github osmlab / osmlint / validators / crossingBuildings / map.js View on Github external
buildings[overlap.id],
          buildings[bbox.id]
        );
        if (
          intersect &&
          (intersect.geometry.type === 'Polygon' ||
            intersect.geometry.type === 'MultiPolygon')
        ) {
          var area = turf.area(intersect);
          if (area > overlapArea) {
            var buildingA = buildings[overlap.id];
            buildingA.properties._osmlint = osmlint;
            var buildingB = buildings[bbox.id];
            buildingB.properties._osmlint = osmlint;
            var points = turf.explode(intersect);
            var multiPoint = turf.combine(points).features[0];
            multiPoint.properties = {
              _fromWay: buildingA.properties['@id'],
              _toWay: buildingB.properties['@id'],
              _osmlint: osmlint
            };
            //save detection
            output[overlap.id] = buildingA;
            output[bbox.id] = buildingB;
            output[overlap.id + bbox.id + 'M'] = multiPoint;
          }
        }
      }
    }
  }

  var result = _.values(output);
github osmlab / osmlint / validators / duplicateBuilding / map.js View on Github external
for (var j = 0; j < bboxes.length; j++) {
    var bbox = bboxes[j];
    var buildingA = buildings[bbox.id];
    var areabuildingA = turf.area(buildingA);
    var overlaps = buildingTraceTree.search(bbox);
    for (var k = 0; k < overlaps.length; k++) {
      var overlap = overlaps[k];
      var buildingB = buildings[overlap.id];
      if (overlap.id !== bbox.id) {
        var difference = turf.difference(
          buildingA, buildingB
        );
        //detecting buildings that have > 90% overlap
        if (difference && (areabuildingA - turf.area(difference)) > (areabuildingA * 0.9)) {
          var points = turf.explode(buildingA);
          var multiPoint = turf.combine(points).features[0];
          multiPoint.properties = {
            _fromWay: buildingA.properties['@id'],
            _toWay: buildingB.properties['@id'],
            _osmlint: osmlint
          };
          //save detection
          output[overlap.id] = buildingA;
          output[bbox.id] = buildingB;
          output[overlap.id + bbox.id + 'M'] = multiPoint;
        }
      }
    }
  }

  var result = _.values(output);
  if (result.length > 0) {