Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Support all GeoJSON Geometry Objects
switch (type) {
case 'GeometryCollection':
geomEach(geojson, function (geometry) {
rewind(geometry, reverse);
});
return geojson;
case 'LineString':
rewindLineString(getCoords(geojson), reverse);
return geojson;
case 'Polygon':
rewindPolygon(getCoords(geojson), reverse);
return geojson;
case 'MultiLineString':
getCoords(geojson).forEach(function (lineCoords) {
rewindLineString(lineCoords, reverse);
});
return geojson;
case 'MultiPolygon':
getCoords(geojson).forEach(function (lineCoords) {
rewindPolygon(lineCoords, reverse);
});
return geojson;
case 'Point':
case 'MultiPoint':
return geojson;
}
}
function rewind(geojson, reverse) {
var type = (geojson.type === 'Feature') ? geojson.geometry.type : geojson.type;
// Support all GeoJSON Geometry Objects
switch (type) {
case 'GeometryCollection':
geomEach(geojson, function (geometry) {
rewind(geometry, reverse);
});
return geojson;
case 'LineString':
rewindLineString(getCoords(geojson), reverse);
return geojson;
case 'Polygon':
rewindPolygon(getCoords(geojson), reverse);
return geojson;
case 'MultiLineString':
getCoords(geojson).forEach(function (lineCoords) {
rewindLineString(lineCoords, reverse);
});
return geojson;
case 'MultiPolygon':
getCoords(geojson).forEach(function (lineCoords) {
rewindPolygon(lineCoords, reverse);
});
return geojson;
case 'Point':
case 'MultiPoint':
return geojson;
}
}
featureEach(tree.search(segment), function (match) {
if (doesOverlaps === false) {
var coordsSegment = getCoords(segment).sort();
var coordsMatch: any = getCoords(match).sort();
// Segment overlaps feature
if (equal(coordsSegment, coordsMatch)) {
doesOverlaps = true;
// 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);
var lastCoords = featureReduce(segments, function (previous, current, index) {
var currentCoords = getCoords(current)[1];
var splitterCoords = getCoords(splitter);
// Location where segment intersects with line
if (index === closestSegment.id) {
previous.push(splitterCoords);
results.push(lineString(previous));
// Don't duplicate splitter coordinate (Issue #688)
if (pointsEquals(splitterCoords, currentCoords)) return [splitterCoords];
return [splitterCoords, currentCoords];
// Keep iterating over coords until finished or intersection is found
} else {
previous.push(currentCoords);
return previous;
}
}, initialValue);
var lastCoords = featureReduce(segments, function (previous, current, index) {
var currentCoords = getCoords(current)[1];
var splitterCoords = getCoords(splitter);
// Location where segment intersects with line
if (index === closestSegment.id) {
previous.push(splitterCoords);
results.push(lineString(previous));
// Don't duplicate splitter coordinate (Issue #688)
if (pointsEquals(splitterCoords, currentCoords)) return [splitterCoords];
return [splitterCoords, currentCoords];
// Keep iterating over coords until finished or intersection is found
} else {
previous.push(currentCoords);
return previous;
}
}, initialValue);
// Append last line to final split results
function lineOffsetFeature(line, distance, units) {
var segments = [];
var offsetDegrees = lengthToDegrees(distance, units);
var coords = getCoords(line);
var finalCoords = [];
coords.forEach(function (currentCoords, index) {
if (index !== coords.length - 1) {
var segment = processSegment(currentCoords, coords[index + 1], offsetDegrees);
segments.push(segment);
if (index > 0) {
var seg2Coords = segments[index - 1];
var intersects = intersection(segment, seg2Coords);
// Handling for line segments that aren't straight
if (intersects !== false) {
seg2Coords[1] = intersects;
segment[0] = intersects;
}
finalCoords.push(seg2Coords[0]);
featureEach(tree.search(current), function (polySegment) {
if (!matched) {
// Segments match
var intersect = lineIntersect(current, polySegment).features[0];
if (intersect) {
// Create Segment
var newSegment = clone(previous);
if (index === 0) {
newSegment = lineString([getCoords(current)[0], getCoords(intersect)]);
} else {
newSegment.geometry.coordinates.push(getCoords(intersect));
}
// Push new split lines to results
if (validSegment(newSegment)) {
results.push(newSegment);
}
// Restart previous value to intersection point
previous.geometry.coordinates = [intersect.geometry.coordinates];
matched = true;
}
}
});
// Append last coordinate of current segment
var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {
if (flip) return getCoords(a[0])[1] - getCoords(b[0])[1];
else return getCoords(b[0])[1] - getCoords(a[0])[1];
});
function intersects(line1: Feature, line2: Feature) {
const coords1: any = getCoords(line1);
const coords2: any = getCoords(line2);
if (coords1.length !== 2) {
throw new Error(" line1 must only contain 2 coordinates");
}
if (coords2.length !== 2) {
throw new Error(" line2 must only contain 2 coordinates");
}
const x1 = coords1[0][0];
const y1 = coords1[0][1];
const x2 = coords1[1][0];
const y2 = coords1[1][1];
const x3 = coords2[0][0];
const y3 = coords2[0][1];
const x4 = coords2[1][0];
const y4 = coords2[1][1];
const denom = ((y4 - y3) * (x2 - x1)) - ((x4 - x3) * (y2 - y1));
const numeA = ((x4 - x3) * (y1 - y3)) - ((y4 - y3) * (x1 - x3));
function polygonTangents(pt, polygon) {
var pointCoords = getCoords(pt);
var polyCoords = getCoords(polygon);
var rtan;
var ltan;
var enext;
var eprev;
var type = getType(polygon);
switch (type) {
case 'Polygon':
rtan = polyCoords[0][0];
ltan = polyCoords[0][0];
eprev = isLeft(polyCoords[0][0], polyCoords[0][polyCoords[0].length - 1], pointCoords);
var out = processPolygon(polyCoords[0], pointCoords, eprev, enext, rtan, ltan);
rtan = out[0];
ltan = out[1];
break;