Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function lineSplit(line, splitter) {
if (!line) throw new Error('line is required');
if (!splitter) throw new Error('splitter is required');
var lineType = getType(line);
var splitterType = getType(splitter);
if (lineType !== 'LineString') throw new Error('line must be LineString');
if (splitterType === 'FeatureCollection') throw new Error('splitter cannot be a FeatureCollection');
if (splitterType === 'GeometryCollection') throw new Error('splitter cannot be a GeometryCollection');
// remove excessive decimals from splitter
// to avoid possible approximation issues in rbush
var truncatedSplitter = truncate(splitter, {precision: 7});
switch (splitterType) {
case 'Point':
return splitLineWithPoint(line, truncatedSplitter);
case 'MultiPoint':
return splitLineWithPoints(line, truncatedSplitter);
case 'LineString':
function centerOfMass<p>(geojson: any, options: {
properties?: P,
} = {}): Feature {
switch (getType(geojson)) {
case 'Point':
return point(getCoord(geojson), options.properties);
case 'Polygon':
var coords = [];
coordEach(geojson, function (coord) {
coords.push(coord);
});
// First, we neutralize the feature (set it around coordinates [0,0]) to prevent rounding errors
// We take any point to translate all the points around 0
var centre = centroid(geojson, {properties: options.properties});
var translation = centre.geometry.coordinates;
var sx = 0;
var sy = 0;
var sArea = 0;
var i, pi, pj, xi, xj, yi, yj, a;</p>
function dissolve(geojson: FeatureCollection, options: {
mutate?: boolean,
} = {}): Feature | null {
// Optional parameters
options = options || {};
if (!isObject(options)) { throw new Error("options is invalid"); }
const mutate = options.mutate;
// Validation
if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
if (!geojson.features.length) { throw new Error("geojson is empty"); }
// Clone geojson to avoid side effects
// Topojson modifies in place, so we need to deep clone first
if (mutate === false || mutate === undefined) { geojson = clone(geojson); }
// Assert homogenity
const type = getHomogenousType(geojson);
if (!type) { throw new Error("geojson must be homogenous"); }
// Data => Typescript hack
const data: any = geojson;
switch (type) {
case "LineString":
return lineDissolve(data, options);
function lineDissolve(geojson, options) {
if (options === void 0) { options = {}; }
// Optional parameters
options = options || {};
if (!helpers_1.isObject(options)) {
throw new Error("options is invalid");
}
var mutate = options.mutate;
// Validation
if (invariant_1.getType(geojson) !== "FeatureCollection") {
throw new Error("geojson must be a FeatureCollection");
}
if (!geojson.features.length) {
throw new Error("geojson is empty");
}
// Clone geojson to avoid side effects
if (mutate === false || mutate === undefined) {
geojson = clone_1.default(geojson);
}
var result = [];
var lastLine = meta_1.lineReduce(geojson, function (previousLine, currentLine) {
// Attempt to merge this LineString with the other LineStrings, updating
// the reference as it is merged with others and grows.
var merged = mergeLineStrings(previousLine, currentLine);
// Accumulate the merged LineString
if (merged) {
function scale(feature, factor, origin) {
// Default params
var isPoint = getType(feature) === 'Point';
origin = defineOrigin(feature, origin);
// Shortcut no-scaling
if (factor === 1 || isPoint) return feature;
// Scale each coordinate
coordEach(feature, function (coord) {
var originalDistance = rhumbDistance(origin, coord);
var bearing = rhumbBearing(origin, coord);
var newDistance = originalDistance * factor;
var newCoord = getCoords(rhumbDestination(origin, newDistance, bearing));
coord[0] = newCoord[0];
coord[1] = newCoord[1];
if (coord.length === 3) coord[2] *= factor;
});
function lineDissolve(
geojson: FeatureCollection,
options: {mutate?: boolean} = {},
): Feature | null {
// Optional parameters
options = options || {};
if (!isObject(options)) { throw new Error("options is invalid"); }
const mutate = options.mutate;
// Validation
if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
if (!geojson.features.length) { throw new Error("geojson is empty"); }
// Clone geojson to avoid side effects
if (mutate === false || mutate === undefined) { geojson = clone(geojson); }
const result: any[] = [];
const lastLine = lineReduce(geojson, (previousLine: any, currentLine: any) => {
// Attempt to merge this LineString with the other LineStrings, updating
// the reference as it is merged with others and grows.
const merged = mergeLineStrings(previousLine, currentLine);
// Accumulate the merged LineString
if (merged) { return merged;
// Put the unmerged LineString back into the list
} else {
result.push(previousLine);
points: FeatureCollection | Feature | GeometryCollection,
line: Feature | LineString,
options: {
units?: Units,
properties?: Properties,
} = {},
): Feature {
const units = options.units;
const properties = options.properties || {};
// validation
const pts = normalize(points);
if (!pts.features.length) { throw new Error("points must contain features"); }
if (!line) { throw new Error("line is required"); }
if (getType(line) !== "LineString") { throw new Error("line must be a LineString"); }
let dist = Infinity;
let pt: any = null;
featureEach(pts, (point) => {
const d = pointToLineDistance(point, line, { units });
if (d < dist) {
dist = d;
pt = point;
}
});
/**
* Translate Properties to final Point, priorities:
* 1. options.properties
* 2. inherent Point properties
* 3. dist custom properties created by NearestPointToLine
function lineDissolve(
geojson: FeatureCollection,
options: {mutate?: boolean} = {},
): Feature | null {
// Optional parameters
options = options || {};
if (!isObject(options)) { throw new Error("options is invalid"); }
const mutate = options.mutate;
// Validation
if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
if (!geojson.features.length) { throw new Error("geojson is empty"); }
// Clone geojson to avoid side effects
if (mutate === false || mutate === undefined) { geojson = clone(geojson); }
const result: any[] = [];
const lastLine = lineReduce(geojson, (previousLine: any, currentLine: any) => {
// Attempt to merge this LineString with the other LineStrings, updating
// the reference as it is merged with others and grows.
const merged = mergeLineStrings(previousLine, currentLine);
// Accumulate the merged LineString
if (merged) { return merged;
// Put the unmerged LineString back into the list
} else {
result.push(previousLine);