How to use the @turf/turf.explode 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 / lib / postProcessing.js View on Github external
transform._transform = function (line, encoding, done) {
    var obj = JSON.parse(line);
    var geojson = {
      'type': 'FeatureCollection',
      'features': []
    };
    for (var i = 0; i < obj.features.length; i++) {
      if (obj.features[i].geometry.type === 'LineString' || obj.features[i].geometry.type === 'Polygon') {
        var multipoints = turf.combine(turf.explode(obj.features[i]));
        multipoints.features[0].properties = obj.features[i].properties;
        geojson.features.push(multipoints.features[0]);
      } else {
        geojson.features.push(obj.features[i]);
      }
    }
    this.push(JSON.stringify(geojson) + '\n');
    done();
  };
  return transform;
github osmlab / osmlint / validators / missingNameHighwaysUS / map.js View on Github external
) {
      tigerFC.push(tigerVal);
    }
  }

  var result = [];

  if (osmFC.length > 0) {
    for (var i = 0; i < osmFC.length; i++) {
      var osmWay = osmFC[i];
      var buffer = turf.buffer(osmWay, 0.004, {
        units: 'miles'
      });
      for (var j = 0; j < tigerFC.length; j++) {
        var tigerWay = tigerFC[j];
        var tigerPoints = turf.explode(tigerWay);
        var nodes;
        nodes = turf.within(tigerPoints, turf.featureCollection([buffer]));
        if (
          nodes.features.length >= tigerPoints.features.length / 2 &&
          tigerWay.properties.FULLNAME
        ) {
          osmWay.properties._osmlint = osmlint;
          osmWay.properties.name = tigerWay.properties.FULLNAME;
          result.push(osmWay);
        }
      }
    }
  }

  if (result.length > 0) {
    var fc = turf.featureCollection(result);
github osmlab / osmlint / validators / selfIntersectingWaterway / map.js View on Github external
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);
            }
          }
          var point;
          if (intersectObjs.length === 1) {
            point = turf.point(intersectObjs[0]);
          } else {
            point = {
              type: 'Feature',
              geometry: {
                type: 'MultiPoint',
                coordinates: intersectObjs
github osmlab / osmlint / validators / duplicateBuilding / map.js View on Github external
buildingTraceTree.load(bboxes);
  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);
github osmlab / osmlint / validators / missingRoundabout / map.js View on Github external
function isOval(highway) {
  var centroidPt = turf.centroid(highway);
  var points = turf.explode(highway);
  var range = 1.2;
  var flag = true;
  var totalDistace = 0;
  var distances = [];
  for (var i = 0; i < points.features.length; i++) {
    var distance = turf.distance(centroidPt, points.features[i], {
      units: 'kilometers'
    });
    distances.push(distance);
    totalDistace += distance;
  }
  var averageDistance = totalDistace / points.features.length;
  for (var f = 0; f < distances.length; f++) {
    if (distances[f] > averageDistance * range) {
      flag = false;
    }
github osmlab / osmlint / validators / crossingBuildings / map.js View on Github external
var intersect = turf.intersect(
          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;
          }
        }
      }
    }
  }
github osmlab / osmlint / validators / doublePlaces / map.js View on Github external
_.each(objs, function(v) {
    var coordPoints = [];
    if (v.length > 1) {
      for (var i = 0; i < v.length; i++) {
        if (v[i].geometry.type === 'Polygon') {
          var points = turf.explode(v[i]);
          for (var n = 0; n < points.features.length; n++) {
            coordPoints.push(points.features[n].geometry.coordinates);
          }
        } else if (v[i].geometry.type === 'Point') {
          coordPoints.push(v[i].geometry.coordinates);
        }
      }
      var multiPt = turf.multiPoint(coordPoints);
      multiPt.properties = v[0].properties;
      multiPt.properties._osmlint = osmlint;
      result.push(multiPt);
    }
  });