Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function splitLineWithPoints(line, splitter) {
var results = [];
var tree = rbush();
flattenEach(splitter, function (point) {
// Add index/id to features (needed for filter)
results.forEach(function (feature, index) {
feature.id = index;
});
// First Point - doesn't need to handle any previous line results
if (!results.length) {
results = splitLineWithPoint(line, point).features;
// Add Square BBox to each feature for GeoJSON-RBush
results.forEach(function (feature) {
if (!feature.bbox) feature.bbox = square(bbox(feature));
});
tree.load(featureCollection(results));
// Split with remaining points - lines might needed to be split multiple times
function splitLineWithPoint(line, splitter) {
var results = [];
// handle endpoints
var startPoint = getCoords(line)[0];
var endPoint = getCoords(line)[line.geometry.coordinates.length - 1];
if (pointsEquals(startPoint, getCoords(splitter)) ||
pointsEquals(endPoint, getCoords(splitter))) return featureCollection([line]);
// Create spatial index
var tree = rbush();
var segments = lineSegment(line);
tree.load(segments);
// Find all segments that are within bbox of splitter
var search = tree.search(splitter);
// Return itself if point is not within spatial index
if (!search.features.length) return featureCollection([line]);
// RBush might return multiple lines - only process the closest line to splitter
var closestSegment = findClosestFeature(splitter, search);
// Initial value is the first point of the first segments (beginning of line)
var initialValue = [startPoint];
var lastCoords = featureReduce(segments, function (previous, current, index) {
var currentCoords = getCoords(current)[1];
if (!isObject(options)) throw new Error('options is invalid');
var propertyName = options.propertyName;
// Input validation
collectionOf(featureCollection, 'Polygon', 'dissolve');
// Main
var fc = clone(featureCollection);
var features = fc.features;
var originalIndexOfItemsRemoved = [];
features.forEach(function (f, i) {
f.properties.origIndexPosition = i;
});
var tree = rbush();
tree.load(fc);
for (var i in features) {
var polygon = features[i];
var featureChanged = false;
tree.search(polygon).features.forEach(function (potentialMatchingFeature) {
polygon = features[i];
var matchFeaturePosition = potentialMatchingFeature.properties.origIndexPosition;
if (originalIndexOfItemsRemoved.length > 0 && matchFeaturePosition !== 0) {
if (matchFeaturePosition > originalIndexOfItemsRemoved[originalIndexOfItemsRemoved.length - 1]) {
matchFeaturePosition = matchFeaturePosition - (originalIndexOfItemsRemoved.length);
} else {
if (line2.type === "LineString") { line2 = feature(line2); }
if (line1.type === "Feature" &&
line2.type === "Feature" &&
line1.geometry !== null &&
line2.geometry !== null &&
line1.geometry.type === "LineString" &&
line2.geometry.type === "LineString" &&
line1.geometry.coordinates.length === 2 &&
line2.geometry.coordinates.length === 2) {
const intersect = intersects(line1, line2);
if (intersect) { results.push(intersect); }
return featureCollection(results);
}
// Handles complex GeoJSON Geometries
const tree = rbush();
tree.load(lineSegment(line2));
featureEach(lineSegment(line1), (segment) => {
featureEach(tree.search(segment), (match) => {
const intersect = intersects(segment, match);
if (intersect) {
// prevent duplicate points https://github.com/Turfjs/turf/issues/688
const key = getCoords(intersect).join(",");
if (!unique[key]) {
unique[key] = true;
results.push(intersect);
}
}
});
});
return featureCollection(results);
}
function lineOverlap(
line1: Feature | G1,
line2: Feature | G2,
options: {tolerance?: number}={}
): FeatureCollection {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var tolerance = options.tolerance || 0;
// Containers
var features = [];
// Create Spatial Index
var tree = rbush();
// To-Do -- HACK way to support typescript
const line: any = lineSegment(line1);
tree.load(line);
var overlapSegment;
// Line Intersection
// Iterate over line segments
segmentEach(line2, function (segment) {
var doesOverlaps = false;
// Iterate over each segments which falls within the same bounds
featureEach(tree.search(segment), function (match) {
if (doesOverlaps === false) {
var coordsSegment = getCoords(segment).sort();
module.exports = function(data, tile, writeData, done) {
// Load an rbush with the existing OSM buildings
var osmCover = rbush();
for (let feature of data.osm.osm.features) {
if (feature.geometry.type !== 'Polygon' || !feature.properties.building) {
continue;
}
osmCover.insert(feature);
}
var features = [];
for (let bFeature of data.buildings.bingbuildings.features) {
var bingOsmIntersect = osmCover.search(bFeature);
if (bingOsmIntersect.features.length == 0) {
// No intersection in the rbush means we should just write out the building
features.push(bFeature);
continue;
constructor(options) {
super(options);
this.tree = rbush();
}
constructor() {
this.jkstraGraph = new jkstra.Graph();
this.graphVertices = {};
this.nextVertexId = 1;
this.tiles = new Set();
this.objectIndex = new Map();
this.featureIndex = new Map();
this.intersectionIndex = geojsonRbush(9);
this.geometryIndex = geojsonRbush(9);
}
constructor() {
this.jkstraGraph = new jkstra.Graph();
this.graphVertices = {};
this.nextVertexId = 1;
this.tiles = new Set();
this.objectIndex = new Map();
this.featureIndex = new Map();
this.intersectionIndex = geojsonRbush(9);
this.geometryIndex = geojsonRbush(9);
}