How to use the @turf/turf.featureCollection 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 open-apparel-registry / open-apparel-registry / src / app / src / components / Map.jsx View on Github external
!targetFeature ||
            !targetFeature.geometry ||
            !targetFeature.geometry.coordinates
        ) {
            return;
        }
        const targetPoint = turf.point(targetFeature.geometry.coordinates);
        const uniqueFeatues = allFeatures.filter(a =>
            a.geometry.coordinates[0] !==
                    targetFeature.geometry.coordinates[0] &&
                a.geometry.coordinates[1] !==
                    targetFeature.geometry.coordinates[1]);

        const allPoints = uniqueFeatues.map(f =>
            turf.point(f.geometry.coordinates));
        const points = turf.featureCollection(allPoints);
        const nearest = turf.nearestPoint(targetPoint, points);
        if (!nearest) {
            return;
        }
        const nearestFeature = uniqueFeatues[nearest.properties.featureIndex];
        return [targetFeature, nearestFeature]; // eslint-disable-line consistent-return
    };
github osmlab / osmlint / validators / overlapHighways / map.js View on Github external
} else {
            output[coordinates] = turf.point(coordinates, props);
          }
          fromHighway.properties._osmlint = osmlint;
          toHighway.properties._osmlint = osmlint;
          output[bbox.id] = fromHighway;
          output[overlap.id] = toHighway;
          // }
        }
      }
    }
  }
  var result = _.values(output);

  if (result.length > 0) {
    var fc = turf.featureCollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }

  done(null, null);
};
github hotosm / tasking-manager / frontend / src / components / projectCreate / setAOI.js View on Github external
const updateArea = event => {
      // Validate area first.
      const id = event.features[0].id;
      const geom = turf.featureCollection(event.features);
      mapObj.draw.delete(id);
      setArbitrary(false);
      setDataGeom(geom);
    };
github osmlab / osmlint / validators / islandsHighways / map.js View on Github external
valueHighway.properties._osmlint = osmlint;
    var firstCoord = valueHighway.geometry.coordinates[0];
    var endCoord =
      valueHighway.geometry.coordinates[
        valueHighway.geometry.coordinates.length - 1
      ];
    if (
      !turf.booleanPointInPolygon(turf.point(firstCoord), bufferLayer) &&
      !turf.booleanPointInPolygon(turf.point(endCoord), bufferLayer)
    ) {
      var overlapBboxes = highwaysTree.search(valueBbox);

      if (overlapBboxes.length === 1) {
        output[valueBbox.id.id] = valueHighway;
      } else {
        var nearHighways = turf.featureCollection([]);
        for (var j = 0; j < overlapBboxes.length; j++) {
          var overlapBbox = overlapBboxes[j];
          if (valueBbox.id.id !== overlapBbox.id.id) {
            nearHighways.features.push(highways[overlapBbox.id.id]);
          }
        }
        var valueCoordinates = geojsonCoords(valueHighway);
        var nearCoordinates = geojsonCoords(nearHighways);
        //filter all highways without any connection
        if (
          _.intersection(
            _.flatten(valueCoordinates),
            _.flatten(nearCoordinates)
          ).length < 2
        ) {
          var obj = {};
github osmlab / osmlint / validators / missingOnewayDrivethrough / map.js View on Github external
val.properties.service == 'drive-through' &&	    
      !val.properties.oneway &&
      val.properties.oneway !== 'no' &&
      !val.properties.layer
    ) {
      val.properties._osmlint = 'missingonewaydrivethrough';
      val.properties._type = classification(
        minorRoads,
        val.properties.highway
      );
      return true;
    }
  });

  if (result.length > 0) {
    var fc = turf.featureCollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }

  done(null, null);
};
github osmlab / osmlint / validators / untaggedWays / map.js View on Github external
return true;
    }
  });

  result = result.filter(function(value) {
    var firstCoord = value.geometry.coordinates[0];
    var endCoord =
      value.geometry.coordinates[value.geometry.coordinates.length - 1];
    if (firstCoord[0] === endCoord[0] && firstCoord[1] === endCoord[1]) {
      return false;
    }
    return true;
  });

  if (result.length > 0) {
    var fc = turf.featureCollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }

  done(null, null);
};
github osmlab / osmlint / validators / misspelledTags / map.js View on Github external
for (var k = preserveTypeValueKeys.length - 1; k >= 0; k--) {
          if (
            val.properties[keys[i]] !== preserveTypeValueKeys[k] &&
            levenshtein.get(val.properties[keys[i]], preserveTypeValueKeys[k]) <
              2
          ) {
            val.properties._osmlint = osmlint;
            return true;
          }
        }
      }
    }
  });

  if (result.length > 0) {
    var fc = turf.featureCollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }
  done(null, null);
};
github osmlab / osmlint / validators / doublePlaces / map.js View on Github external
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);
    }
  });

  if (result.length > 0) {
    var fc = turf.featureCollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }

  done(null, null);
};
github osmlab / osmlint / validators / exitAndDestination / map.js View on Github external
module.exports = function(tileLayers, tile, writeData, done) {
  var layer = tileLayers.osm.osm;
  var output = {};
  for (var z = 0; z < layer.features.length; z++) {
    var obj = layer.features[z];
    if (
      obj.properties.highway &&
      hasTag(obj.properties) &&
      obj.properties['@timestamp'] >= start
    ) {
      output[obj.properties['@id']] = obj;
    }
  }
  var result = _.values(output);
  if (result.length > 0) {
    var fc = turf.featureCollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }
  done(null, null);
};
github osmlab / osmlint / validators / crossingHighwaysBridges / map.js View on Github external
output[overlapHighway.properties['@id']] = overlapHighway;
                output[
                  highwayToEvaluate.properties['@id'] +
                    overlapHighway.properties['@id']
                ] = intersectPoint;
              }
            }
          }
        }
      }
    }
  }

  var result = _.values(output);
  if (result.length > 0) {
    var fc = turf.featureCollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }

  done(null, null);
};