Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} = {}): FeatureCollection {
// Input validation being handled by Typescript
// collectionOf(points, 'Point', 'points must consist of a FeatureCollection of only Points');
// if (maxDistance === null || maxDistance === undefined) throw new Error('maxDistance is required');
// if (!(Math.sign(maxDistance) > 0)) throw new Error('maxDistance is invalid');
// if (!(minPoints === undefined || minPoints === null || Math.sign(minPoints) > 0)) throw new Error('options.minPoints is invalid');
// Clone points to prevent any mutations
if (options.mutate !== true) points = clone(points);
// Defaults
options.minPoints = options.minPoints || 3;
// create clustered ids
var dbscan = new clustering.DBSCAN();
var clusteredIds = dbscan.run(coordAll(points), convertLength(maxDistance, options.units), options.minPoints, distance);
// Tag points to Clusters ID
var clusterId = -1;
clusteredIds.forEach(function (clusterIds) {
clusterId++;
// assign cluster ids to input points
clusterIds.forEach(function (idx) {
var clusterPoint = points.features[idx];
if (!clusterPoint.properties) clusterPoint.properties = {};
clusterPoint.properties.cluster = clusterId;
clusterPoint.properties.dbscan = 'core';
});
});
// handle noise points, if any
// edges points are tagged by DBSCAN as both 'noise' and 'cluster' as they can "reach" less than 'minPoints' number of points
numberOfClusters?: number,
mutate?: boolean
} = {}): FeatureCollection {
// Default Params
var count = points.features.length;
options.numberOfClusters = options.numberOfClusters || Math.round(Math.sqrt(count / 2));
// numberOfClusters can't be greater than the number of points
// fallbacks to count
if (options.numberOfClusters > count) options.numberOfClusters = count;
// Clone points to prevent any mutations (enabled by default)
if (options.mutate !== true) points = clone(points);
// collect points coordinates
var data = coordAll(points);
// create seed to avoid skmeans to drift
var initialCentroids = data.slice(0, options.numberOfClusters);
// create skmeans clusters
var skmeansResult = skmeans(data, options.numberOfClusters, initialCentroids);
// store centroids {clusterId: [number, number]}
var centroids = {};
skmeansResult.centroids.forEach(function (coord, idx) {
centroids[idx] = coord;
});
// add associated cluster number
featureEach(points, function (point, index) {
var clusterId = skmeansResult.idxs[index];
const geom2 = getGeom(feature2);
const type1 = geom1.type;
const type2 = geom2.type;
if (type1 !== type2) throw new Error('features must be of the same type');
if (type1 === 'Point') throw new Error('Point geometry not supported');
// features must be not equal
const equality = new GeojsonEquality({precision: 6});
if (equality.compare(feature1, feature2)) return false;
let overlap = 0;
switch (type1) {
case 'MultiPoint':
const coords1 = coordAll(feature1);
const coords2 = coordAll(feature2);
coords1.forEach((coord1) => {
coords2.forEach((coord2) => {
if (coord1[0] === coord2[0] && coord1[1] === coord2[1]) overlap++;
});
});
break;
case 'LineString':
case 'MultiLineString':
segmentEach(feature1, (segment1) => {
segmentEach(feature2, (segment2) => {
if (lineOverlap(segment1, segment2).features.length) overlap++;
});
});
break;
const geom1 = getGeom(feature1);
const geom2 = getGeom(feature2);
const type1 = geom1.type;
const type2 = geom2.type;
if (type1 !== type2) throw new Error('features must be of the same type');
if (type1 === 'Point') throw new Error('Point geometry not supported');
// features must be not equal
const equality = new GeojsonEquality({precision: 6});
if (equality.compare(feature1, feature2)) return false;
let overlap = 0;
switch (type1) {
case 'MultiPoint':
const coords1 = coordAll(feature1);
const coords2 = coordAll(feature2);
coords1.forEach((coord1) => {
coords2.forEach((coord2) => {
if (coord1[0] === coord2[0] && coord1[1] === coord2[1]) overlap++;
});
});
break;
case 'LineString':
case 'MultiLineString':
segmentEach(feature1, (segment1) => {
segmentEach(feature2, (segment2) => {
if (lineOverlap(segment1, segment2).features.length) overlap++;
});
});
break;
function ringsIntersect(poly1, poly2) {
var line1 = lineString(coordAll(poly1));
var line2 = lineString(coordAll(poly2));
var points = lineIntersect(line1, line2).features;
return points.length > 0;
}
function ringsIntersect(poly1, poly2) {
var line1 = lineString(coordAll(poly1));
var line2 = lineString(coordAll(poly2));
var points = lineIntersect(line1, line2).features;
return points.length > 0;
}
export const createOneWayStreetFromIntersection = (direction: string, intersectionId: string) : SharedStreetsMatchGeomPath => {
const points = randomPoint(2);
const geometryId = uuid();
const referenceId = uuid();
const toIntersectionId = uuid();
const fromIntersectionId = intersectionId;
const pathProperties: ISharedStreetsMatchGeomPathProperties = {
direction,
fromIntersectionId,
fromStreetnames: ['street-'+referenceId],
geometryId,
originalFeature: {
geometry: {
coordinates: coordAll(points),
type: "LineString",
},
properties: {},
type: "Feature"
},
point: 1,
referenceId,
referenceLength: 1,
roadClass: '',
section: [1],
side: '',
streetname: 'street-'+referenceId,
toIntersectionId,
toStreetnames: ['street-'+toIntersectionId]
};
const path = new SharedStreetsMatchGeomPath(
},
properties: {},
type: "Feature"
},
point: 1,
referenceId,
referenceLength: 1,
roadClass: '',
section: [1],
side: '',
streetname: 'street-'+referenceId,
toIntersectionId,
toStreetnames: ['street-'+toIntersectionId]
};
const path = new SharedStreetsMatchGeomPath(
lineString(coordAll(points), pathProperties)
);
return path;
}