Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Overlaps already exists - only append last coordinate of segment
if (overlapSegment) overlapSegment = concatSegment(overlapSegment, segment);
else overlapSegment = segment;
// Match segments which don't share nodes (Issue #901)
} else if (
(tolerance === 0) ?
booleanPointOnLine(coordsSegment[0], match) && booleanPointOnLine(coordsSegment[1], match) :
nearestPointOnLine(match, coordsSegment[0]).properties.dist <= tolerance &&
nearestPointOnLine(match, coordsSegment[1]).properties.dist <= tolerance) {
doesOverlaps = true;
if (overlapSegment) overlapSegment = concatSegment(overlapSegment, segment);
else overlapSegment = segment;
} else if (
(tolerance === 0) ?
booleanPointOnLine(coordsMatch[0], segment) && booleanPointOnLine(coordsMatch[1], segment) :
nearestPointOnLine(segment, coordsMatch[0]).properties.dist <= tolerance &&
nearestPointOnLine(segment, coordsMatch[1]).properties.dist <= tolerance) {
// Do not define (doesOverlap = true) since more matches can occur within the same segment
// doesOverlaps = true;
if (overlapSegment) overlapSegment = concatSegment(overlapSegment, match);
else overlapSegment = match;
}
}
});
export function projectStopOntoLine (stop: GtfsStop, line: GeoJsonLinestring): {
distanceInMeters: number,
insertIndex: number,
insertPoint: GeoJsonPoint
} {
const stopPoint = stopToPoint(stop)
// Find nearest point on line
const insertPoint = nearestPointOnLine(line, stopPoint)
// Determine insert index based on nearest point operation segment index.
// FIXME is this the right spot to insert
const insertIndex = insertPoint.properties.index
// Determine distance traveled to stop/shape point
// Distance returned from nearestPointOnLine defaults to km.
const distanceInMeters = insertPoint.properties.location * 1000
return {insertPoint, insertIndex, distanceInMeters}
}
const currentDistance = turfDistance(firstPoint, groundCoords, { units: 'meters' });
return turfDestination(firstPoint, currentDistance, lastBearing, {
units: 'meters'
}).geometry.coordinates;
}
return groundCoords;
}
// Allow only 90 degree turns
const lastPoint = clickSequence[clickSequence.length - 1];
const [approximatePoint] = generatePointsParallelToLinePoints(
clickSequence[clickSequence.length - 2],
lastPoint,
groundCoords
);
// align point with current ground
const nearestPt = nearestPointOnLine(lineString([lastPoint, approximatePoint]), groundCoords)
.geometry.coordinates;
return nearestPt;
}
featureEach(lines, function (segment) {
var pt = nearestPointOnLine(segment, point);
var dist = pt.properties.dist;
if (dist < closestDistance) {
closestFeature = segment;
closestDistance = dist;
}
});
return closestFeature;
lines.forEach(line => {
const snapPoint = nearestPointOnLine(line, firstPoint);
const distanceFromOrigin = turfDistance(snapPoint, firstPoint);
if (minDistance > distanceFromOrigin) {
minDistance = distanceFromOrigin;
closestPoint = snapPoint;
}
});
function lineSlice(startPt, stopPt, line) {
var coords;
if (line.type === 'Feature') {
coords = line.geometry.coordinates;
} else if (line.type === 'LineString') {
coords = line.coordinates;
} else {
throw new Error('input must be a LineString Feature or Geometry');
}
var startVertex = nearestPointOnLine(line, startPt);
var stopVertex = nearestPointOnLine(line, stopPt);
var ends;
if (startVertex.properties.index <= stopVertex.properties.index) {
ends = [startVertex, stopVertex];
} else {
ends = [stopVertex, startVertex];
}
var clipCoords = [ends[0].geometry.coordinates];
for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
clipCoords.push(coords[i]);
}
clipCoords.push(ends[1].geometry.coordinates);
return linestring(clipCoords, line.properties);
}
function lineSlice(startPt, stopPt, line) {
var coords;
if (line.type === 'Feature') {
coords = line.geometry.coordinates;
} else if (line.type === 'LineString') {
coords = line.coordinates;
} else {
throw new Error('input must be a LineString Feature or Geometry');
}
var startVertex = nearestPointOnLine(line, startPt);
var stopVertex = nearestPointOnLine(line, stopPt);
var ends;
if (startVertex.properties.index <= stopVertex.properties.index) {
ends = [startVertex, stopVertex];
} else {
ends = [stopVertex, startVertex];
}
var clipCoords = [ends[0].geometry.coordinates];
for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
clipCoords.push(coords[i]);
}
clipCoords.push(ends[1].geometry.coordinates);
return linestring(clipCoords, line.properties);
}
(lineString, prefix) => {
const lineStringFeature = toLineString(lineString);
const candidateIntermediatePoint = nearestPointOnLine(
lineStringFeature,
referencePoint
);
if (
!intermediatePoint ||
candidateIntermediatePoint.properties.dist < intermediatePoint.properties.dist
) {
intermediatePoint = candidateIntermediatePoint;
positionIndexPrefix = prefix;
}
}
);