Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
if (!geojson) throw new Error('geojson is required');
if (typeof options !== 'object') throw new Error('options must be an object');
if (typeof steps !== 'number') throw new Error('steps must be an number');
// Allow negative buffers ("erosion") or zero-sized buffers ("repair geometry")
if (radius === undefined) throw new Error('radius is required');
if (steps <= 0) throw new Error('steps must be greater than 0');
// default params
steps = steps || 64;
units = units || 'kilometers';
var results = [];
switch (geojson.type) {
case 'GeometryCollection':
geomEach(geojson, function (geometry) {
var buffered = bufferFeature(geometry, radius, units, steps);
if (buffered) results.push(buffered);
});
return featureCollection(results);
case 'FeatureCollection':
featureEach(geojson, function (feature) {
var multiBuffered = bufferFeature(feature, radius, units, steps);
if (multiBuffered) {
featureEach(multiBuffered, function (buffered) {
if (buffered) results.push(buffered);
});
}
});
return featureCollection(results);
}
return bufferFeature(geojson, radius, units, steps);
function centerMean<p>(
geojson: any, // To-Do include Typescript AllGeoJSON
options: {properties?: P, bbox?: BBox, id?: Id, weight?: string} = {},
): Feature {
let sumXs = 0;
let sumYs = 0;
let sumNs = 0;
geomEach(geojson, function (geom, featureIndex, properties) {
let weight = properties[options.weight];
weight = (weight === undefined || weight === null) ? 1 : weight;
if (!isNumber(weight)) throw new Error('weight value must be a number for feature index ' + featureIndex);
weight = Number(weight);
if (weight > 0) {
coordEach(geom, function (coord) {
sumXs += coord[0] * weight;
sumYs += coord[1] * weight;
sumNs += weight;
});
}
});
return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
}
</p>
function simplify(geojson, options) {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var tolerance = options.tolerance !== undefined ? options.tolerance : 1;
var highQuality = options.highQuality || false;
var mutate = options.mutate || false;
if (!geojson) throw new Error('geojson is required');
if (tolerance && tolerance < 0) throw new Error('invalid tolerance');
// Clone geojson to avoid side effects
if (mutate !== true) geojson = clone(geojson);
geomEach(geojson, function (geom) {
simplifyGeom(geom, tolerance, highQuality);
});
return geojson;
}
function polygonSmooth(inputPolys, options) {
var outPolys = [];
// Optional parameters
var iterations = options.iterations || 1;
if (!inputPolys) throw new Error('inputPolys is required');
geomEach(inputPolys, function (geom, geomIndex, properties) {
var outCoords;
var poly;
var tempOutput;
switch (geom.type) {
case 'Polygon':
outCoords = [[]];
for (var i = 0; i < iterations; i++) {
tempOutput = [[]];
poly = geom;
if (i > 0) poly = polygon(outCoords).geometry;
processPolygon(poly, tempOutput);
outCoords = tempOutput.slice(0);
}
outPolys.push(polygon(outCoords, properties));
break;
featureEach(points, function (point) {
var contained = false;
geomEach(polygons, function (polygon) {
if (pointInPolygon(point, polygon)) contained = true;
});
if (contained) {
results.push(point);
}
});
return featureCollection(results);
function normalize(points: any): FeatureCollection {
const features: any[] = [];
const type = points.geometry ? points.geometry.type : points.type;
switch (type) {
case "GeometryCollection":
geomEach(points, (geom) => {
if (geom.type === "Point") { features.push({type: "Feature", properties: {}, geometry: geom}); }
});
return {type: "FeatureCollection", features};
case "FeatureCollection":
points.features = points.features.filter((feature: any) => {
return feature.geometry.type === "Point";
});
return points;
default:
throw new Error("points must be a Point Collection");
}
}