Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/rectangle-grid

Package Overview
Dependencies
Maintainers
7
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/rectangle-grid - npm Package Compare versions

Comparing version 6.5.0 to 7.0.0-alpha.0

45

dist/es/index.js
import intersect from "@turf/boolean-intersects";
import distance from "@turf/distance";
import { featureCollection, polygon, } from "@turf/helpers";
import { convertLength, featureCollection, polygon, } from "@turf/helpers";
/**

@@ -29,28 +28,24 @@ * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.

*/
function rectangleGrid(bbox, cellWidth, cellHeight, options) {
if (options === void 0) { options = {}; }
function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
// Containers
var results = [];
var west = bbox[0];
var south = bbox[1];
var east = bbox[2];
var north = bbox[3];
var xFraction = cellWidth / distance([west, south], [east, south], options);
var cellWidthDeg = xFraction * (east - west);
var yFraction = cellHeight / distance([west, south], [west, north], options);
var cellHeightDeg = yFraction * (north - south);
// rows & columns
var bboxWidth = east - west;
var bboxHeight = north - south;
var columns = Math.floor(bboxWidth / cellWidthDeg);
var rows = Math.floor(bboxHeight / cellHeightDeg);
const results = [];
const west = bbox[0];
const south = bbox[1];
const east = bbox[2];
const north = bbox[3];
const bboxWidth = east - west;
const cellWidthDeg = convertLength(cellWidth, options.units, "degrees");
const bboxHeight = north - south;
const cellHeightDeg = convertLength(cellHeight, options.units, "degrees");
const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);
const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);
// if the grid does not fill the bbox perfectly, center it.
var deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
var deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
// iterate over columns & rows
var currentX = west + deltaX;
for (var column = 0; column < columns; column++) {
var currentY = south + deltaY;
for (var row = 0; row < rows; row++) {
var cellPoly = polygon([
let currentX = west + deltaX;
for (let column = 0; column < columns; column++) {
let currentY = south + deltaY;
for (let row = 0; row < rows; row++) {
const cellPoly = polygon([
[

@@ -57,0 +52,0 @@ [currentX, currentY],

@@ -1,2 +0,3 @@

import { BBox, Feature, FeatureCollection, MultiPolygon, Polygon, Properties, Units } from "@turf/helpers";
import { BBox, Feature, FeatureCollection, MultiPolygon, Polygon, GeoJsonProperties } from "geojson";
import { Units } from "@turf/helpers";
/**

@@ -27,3 +28,3 @@ * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.

*/
declare function rectangleGrid<P = Properties>(bbox: BBox, cellWidth: number, cellHeight: number, options?: {
declare function rectangleGrid<P = GeoJsonProperties>(bbox: BBox, cellWidth: number, cellHeight: number, options?: {
units?: Units;

@@ -30,0 +31,0 @@ properties?: P;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var boolean_intersects_1 = __importDefault(require("@turf/boolean-intersects"));
var distance_1 = __importDefault(require("@turf/distance"));
var helpers_1 = require("@turf/helpers");
const tslib_1 = require("tslib");
const boolean_intersects_1 = tslib_1.__importDefault(require("@turf/boolean-intersects"));
const helpers_1 = require("@turf/helpers");
/**

@@ -34,28 +31,24 @@ * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.

*/
function rectangleGrid(bbox, cellWidth, cellHeight, options) {
if (options === void 0) { options = {}; }
function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
// Containers
var results = [];
var west = bbox[0];
var south = bbox[1];
var east = bbox[2];
var north = bbox[3];
var xFraction = cellWidth / distance_1.default([west, south], [east, south], options);
var cellWidthDeg = xFraction * (east - west);
var yFraction = cellHeight / distance_1.default([west, south], [west, north], options);
var cellHeightDeg = yFraction * (north - south);
// rows & columns
var bboxWidth = east - west;
var bboxHeight = north - south;
var columns = Math.floor(bboxWidth / cellWidthDeg);
var rows = Math.floor(bboxHeight / cellHeightDeg);
const results = [];
const west = bbox[0];
const south = bbox[1];
const east = bbox[2];
const north = bbox[3];
const bboxWidth = east - west;
const cellWidthDeg = helpers_1.convertLength(cellWidth, options.units, "degrees");
const bboxHeight = north - south;
const cellHeightDeg = helpers_1.convertLength(cellHeight, options.units, "degrees");
const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);
const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);
// if the grid does not fill the bbox perfectly, center it.
var deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
var deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
// iterate over columns & rows
var currentX = west + deltaX;
for (var column = 0; column < columns; column++) {
var currentY = south + deltaY;
for (var row = 0; row < rows; row++) {
var cellPoly = helpers_1.polygon([
let currentX = west + deltaX;
for (let column = 0; column < columns; column++) {
let currentY = south + deltaY;
for (let row = 0; row < rows; row++) {
const cellPoly = helpers_1.polygon([
[

@@ -62,0 +55,0 @@ [currentX, currentY],

{
"name": "@turf/rectangle-grid",
"version": "6.5.0",
"version": "7.0.0-alpha.0",
"description": "turf rectangle-grid module",

@@ -53,4 +53,4 @@ "author": "Turf Authors",

"devDependencies": {
"@turf/bbox-polygon": "^6.5.0",
"@turf/truncate": "^6.5.0",
"@turf/bbox-polygon": "^7.0.0-alpha.0",
"@turf/truncate": "^7.0.0-alpha.0",
"benchmark": "*",

@@ -66,7 +66,8 @@ "load-json-file": "*",

"dependencies": {
"@turf/boolean-intersects": "^6.5.0",
"@turf/distance": "^6.5.0",
"@turf/helpers": "^6.5.0"
"@turf/boolean-intersects": "^7.0.0-alpha.0",
"@turf/distance": "^7.0.0-alpha.0",
"@turf/helpers": "^7.0.0-alpha.0",
"tslib": "^2.3.0"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
}

@@ -7,17 +7,18 @@ # @turf/rectangle-grid

Creates a grid of rectangles from a bounding box, [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) or [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3).
Creates a grid of rectangles from a bounding box, [Feature][1] or [FeatureCollection][2].
**Parameters**
### Parameters
- `bbox` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order
- `cellWidth` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** of each cell, in units
- `cellHeight` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** of each cell, in units
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.units` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
* `bbox` **[Array][3]<[number][4]>** extent in \[minX, minY, maxX, maxY] order
* `cellWidth` **[number][4]** of each cell, in units
* `cellHeight` **[number][4]** of each cell, in units
* `options` **[Object][5]** Optional parameters (optional, default `{}`)
* `options.units` **[string][6]** units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
and cellHeight are expressed in. Converted at the southern border. (optional, default `'kilometers'`)
- `options.mask` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>?** if passed a Polygon or MultiPolygon,
* `options.mask` **[Feature][7]<([Polygon][8] | [MultiPolygon][9])>?** if passed a Polygon or MultiPolygon,
the grid Points will be created only inside it
- `options.properties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** passed to each point of the grid (optional, default `{}`)
* `options.properties` **[Object][5]** passed to each point of the grid (optional, default `{}`)
**Examples**
### Examples

@@ -36,4 +37,24 @@ ```javascript

Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)&lt;[Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6)>** a grid of polygons
Returns **[FeatureCollection][10]<[Polygon][8]>** a grid of polygons
[1]: https://tools.ietf.org/html/rfc7946#section-3.2
[2]: https://tools.ietf.org/html/rfc7946#section-3.3
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[7]: https://tools.ietf.org/html/rfc7946#section-3.2
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.6
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
[10]: https://tools.ietf.org/html/rfc7946#section-3.3
<!-- This file is automatically generated. Please don't edit it directly:

@@ -40,0 +61,0 @@ if you find an error, edit the source file (likely index.js), and re-run

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