Socket
Socket
Sign inDemoInstall

@turf/square-grid

Package Overview
Dependencies
Maintainers
4
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/square-grid - npm Package Compare versions

Comparing version 5.1.5 to 6.0.0

index.ts

70

index.js

@@ -1,6 +0,6 @@

import distance from '@turf/distance';
import intersect from '@turf/intersect';
import {getType} from '@turf/invariant';
import {polygon, featureCollection, isObject, isNumber} from '@turf/helpers';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var distance_1 = require("@turf/distance");
var boolean_intersects_1 = require("@turf/boolean-intersects");
var helpers_1 = require("@turf/helpers");
/**

@@ -28,20 +28,12 @@ * Creates a square grid from a bounding box, {@link Feature} or {@link FeatureCollection}.

function squareGrid(bbox, cellSide, options) {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
// var units = options.units;
var properties = options.properties;
var mask = options.mask;
if (options === void 0) { options = {}; }
// Containers
var results = [];
// Input Validation
if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required');
if (!isNumber(cellSide)) throw new Error('cellSide is invalid');
if (!bbox) throw new Error('bbox is required');
if (!Array.isArray(bbox)) throw new Error('bbox must be array');
if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers');
if (mask && ['Polygon', 'MultiPolygon'].indexOf(getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon');
// Input Validation is being handled by Typescript
// if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required');
// if (!isNumber(cellSide)) throw new Error('cellSide is invalid');
// if (!bbox) throw new Error('bbox is required');
// if (!Array.isArray(bbox)) throw new Error('bbox must be array');
// if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers');
// if (options.mask && ['Polygon', 'MultiPolygon'].indexOf(getType(options.mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon');
var west = bbox[0];

@@ -51,8 +43,6 @@ var south = bbox[1];

var north = bbox[3];
var xFraction = cellSide / (distance([west, south], [east, south], options));
var xFraction = cellSide / (distance_1.default([west, south], [east, south], options));
var cellWidth = xFraction * (east - west);
var yFraction = cellSide / (distance([west, south], [west, north], options));
var yFraction = cellSide / (distance_1.default([west, south], [west, north], options));
var cellHeight = yFraction * (north - south);
// rows & columns

@@ -63,7 +53,5 @@ var bboxWidth = (east - west);

var rows = Math.floor(bboxHeight / cellHeight);
// adjust origin of the grid
var deltaX = (bboxWidth - columns * cellWidth) / 2;
var deltaY = (bboxHeight - rows * cellHeight) / 2;
// iterate over columns & rows

@@ -74,15 +62,16 @@ var currentX = west + deltaX;

for (var row = 0; row < rows; row++) {
var cellPoly = polygon([[
[currentX, currentY],
[currentX, currentY + cellHeight],
[currentX + cellWidth, currentY + cellHeight],
[currentX + cellWidth, currentY],
[currentX, currentY]
]], properties);
if (mask) {
if (intersect(mask, cellPoly)) results.push(cellPoly);
} else {
var cellPoly = helpers_1.polygon([[
[currentX, currentY],
[currentX, currentY + cellHeight],
[currentX + cellWidth, currentY + cellHeight],
[currentX + cellWidth, currentY],
[currentX, currentY]
]], options.properties);
if (options.mask) {
if (boolean_intersects_1.default(options.mask, cellPoly))
results.push(cellPoly);
}
else {
results.push(cellPoly);
}
currentY += cellHeight;

@@ -92,5 +81,4 @@ }

}
return featureCollection(results);
return helpers_1.featureCollection(results);
}
export default squareGrid;
exports.default = squareGrid;
{
"name": "@turf/square-grid",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf square-grid module",
"main": "main.js",
"module": "main.es.js",
"types": "index.d.ts",
"main": "index",
"files": [
"index.js",
"index.d.ts",
"main.js",
"main.es.js"
"index.ts"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js",
"bench": "node -r @std/esm bench.js",
"prepare": "tsc",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"

@@ -40,4 +36,4 @@ },

"@std/esm": "*",
"@turf/bbox-polygon": "^5.1.5",
"@turf/truncate": "^5.1.5",
"@turf/bbox-polygon": "*",
"@turf/truncate": "*",
"benchmark": "*",

@@ -49,13 +45,7 @@ "rollup": "*",

"dependencies": {
"@turf/boolean-contains": "^5.1.5",
"@turf/boolean-overlap": "^5.1.5",
"@turf/distance": "^5.1.5",
"@turf/helpers": "^5.1.5",
"@turf/intersect": "^5.1.5",
"@turf/invariant": "^5.1.5"
},
"@std/esm": {
"esm": "js",
"cjs": true
"@turf/boolean-intersects": "6.x",
"@turf/distance": "6.x",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc