How to use the @turf/invariant.collectionOf function in @turf/invariant

To help you get started, we’ve selected a few @turf/invariant examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Turfjs / turf / packages / turf-dissolve / index.js View on Github external
function dissolve(featureCollection, options) {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');
    var propertyName = options.propertyName;

    // Input validation
    collectionOf(featureCollection, 'Polygon', 'dissolve');

    // Main
    var fc = clone(featureCollection);
    var features = fc.features;

    var originalIndexOfItemsRemoved = [];

    features.forEach(function (f, i) {
        f.properties.origIndexPosition = i;
    });
    var tree = rbush();
    tree.load(fc);

    for (var i in features) {
        var polygon = features[i];
github Turfjs / turf / packages / turf-isolines / lib / grid-to-matrix.js View on Github external
export default function gridToMatrix(grid, options) {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');
    var zProperty = options.zProperty || 'elevation';
    var flip = options.flip;
    var flags = options.flags;

    // validation
    collectionOf(grid, 'Point', 'input must contain Points');

    var pointsMatrix = sortPointsByLatLng(grid, flip);

    var matrix = [];
    // create property matrix from sorted points
    // looping order matters here
    for (var r = 0; r < pointsMatrix.length; r++) {
        var pointRow = pointsMatrix[r];
        var row = [];
        for (var c = 0; c < pointRow.length; c++) {
            var point = pointRow[c];
            // Check if zProperty exist
            if (point.properties[zProperty]) row.push(point.properties[zProperty]);
            else row.push(0);
            // add flags
            if (flags === true) point.properties.matrixPosition = [r, c];
github Turfjs / turf / packages / turf-isobands / index.js View on Github external
function isobands(pointGrid, breaks, options) {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');
    var zProperty = options.zProperty || 'elevation';
    var commonProperties = options.commonProperties || {};
    var breaksProperties = options.breaksProperties || [];

    // Validation
    collectionOf(pointGrid, 'Point', 'Input must contain Points');
    if (!breaks) throw new Error('breaks is required');
    if (!Array.isArray(breaks)) throw new Error('breaks is not an Array');
    if (!isObject(commonProperties)) throw new Error('commonProperties is not an Object');
    if (!Array.isArray(breaksProperties)) throw new Error('breaksProperties is not an Array');

    // Isoband methods
    var matrix = gridToMatrix(pointGrid, {zProperty: zProperty, flip: true});
    var contours = createContourLines(matrix, breaks, zProperty);
    contours = rescaleContours(contours, matrix, pointGrid);

    var multipolygons = contours.map(function (contour, index) {
        if (breaksProperties[index] && !isObject(breaksProperties[index])) {
            throw new Error('Each mappedProperty is required to be an Object');
        }
        // collect all properties
        var contourProperties = objectAssign(
github Turfjs / turf / packages / turf-isolines / index.js View on Github external
function isolines(pointGrid, breaks, options) {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');
    var zProperty = options.zProperty || 'elevation';
    var commonProperties = options.commonProperties || {};
    var breaksProperties = options.breaksProperties || [];

    // Input validation
    collectionOf(pointGrid, 'Point', 'Input must contain Points');
    if (!breaks) throw new Error('breaks is required');
    if (!Array.isArray(breaks)) throw new Error('breaks must be an Array');
    if (!isObject(commonProperties)) throw new Error('commonProperties must be an Object');
    if (!Array.isArray(breaksProperties)) throw new Error('breaksProperties must be an Array');

    // Isoline methods
    var matrix = gridToMatrix(pointGrid, {zProperty: zProperty, flip: true});
    var createdIsoLines = createIsoLines(matrix, breaks, zProperty, commonProperties, breaksProperties);
    var scaledIsolines = rescaleIsolines(createdIsoLines, matrix, pointGrid);

    return featureCollection(scaledIsolines);
}
github Turfjs / turf / packages / turf-interpolate / index.js View on Github external
function interpolate(points, cellSize, options) {
    // Optional parameters
    options = options || {};
    if (typeof options !== 'object') throw new Error('options is invalid');
    var gridType = options.gridType;
    var property = options.property;
    var units = options.units;
    var weight = options.weight;

    // validation
    if (!points) throw new Error('points is required');
    collectionOf(points, 'Point', 'input must contain Points');
    if (!cellSize) throw new Error('cellSize is required');
    if (weight !== undefined && typeof weight !== 'number') throw new Error('weight must be a number');

    // default values
    property = property || 'elevation';
    gridType = gridType || 'square';
    weight = weight || 1;

    var box = bbox(points);
    var grid;
    switch (gridType) {
    case 'point':
    case 'points':
        grid = poinGrid(box, cellSize, {units: units, bboxIsMask: true});
        break;
    case 'square':
github Turfjs / turf / packages / turf-voronoi / index.js View on Github external
function voronoi(points, options) {
    // Optional params
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');
    var bbox = options.bbox || [-180, -85, 180, 85];

    // Input Validation
    if (!points) throw new Error('points is required');
    if (!Array.isArray(bbox)) throw new Error('bbox is invalid');
    collectionOf(points, 'Point', 'points');

    // Main
    return featureCollection(
        d3voronoi.voronoi()
            .x(function (feature) { return feature.geometry.coordinates[0]; })
            .y(function (feature) { return feature.geometry.coordinates[1]; })
            .extent([[bbox[0], bbox[1]], [bbox[2], bbox[3]]])
            .polygons(points.features)
            .map(coordsToPolygon)
    );
}

@turf/invariant

Lightweight utility for input validation and data extraction in Turf.js. Ensures GeoJSON inputs are in the correct format and extracts specific components like coordinates or geometries.

MIT
Latest version published 20 days ago

Package Health Score

93 / 100
Full package analysis