@turf/rectangle-grid 6.4.0 → 7.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,21 +4,22 @@
4
4
 
5
5
  ## rectangleGrid
6
6
 
7
- 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).
7
+ Creates a grid of rectangles from a bounding box, [Feature][1] or [FeatureCollection][2].
8
8
 
9
- **Parameters**
9
+ ### Parameters
10
10
 
11
- - `bbox` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order
12
- - `cellWidth` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** of each cell, in units
13
- - `cellHeight` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** of each cell, in units
14
- - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
15
- - `options.units` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
11
+ * `bbox` **[Array][3]<[number][4]>** extent in \[minX, minY, maxX, maxY] order
12
+ * `cellWidth` **[number][4]** of each cell, in units
13
+ * `cellHeight` **[number][4]** of each cell, in units
14
+ * `options` **[Object][5]** Optional parameters (optional, default `{}`)
15
+
16
+ * `options.units` **[string][6]** units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
16
17
  and cellHeight are expressed in. Converted at the southern border. (optional, default `'kilometers'`)
17
- - `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,
18
+ * `options.mask` **[Feature][7]<([Polygon][8] | [MultiPolygon][9])>?** if passed a Polygon or MultiPolygon,
18
19
  the grid Points will be created only inside it
19
- - `options.properties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** passed to each point of the grid (optional, default `{}`)
20
+ * `options.properties` **[Object][5]** passed to each point of the grid (optional, default `{}`)
20
21
 
21
- **Examples**
22
+ ### Examples
22
23
 
23
24
  ```javascript
24
25
  var bbox = [-95, 30 ,-85, 40];
@@ -32,7 +33,27 @@ var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);
32
33
  var addToMap = [rectangleGrid]
33
34
  ```
34
35
 
35
- 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
36
+ Returns **[FeatureCollection][10]<[Polygon][8]>** a grid of polygons
37
+
38
+ [1]: https://tools.ietf.org/html/rfc7946#section-3.2
39
+
40
+ [2]: https://tools.ietf.org/html/rfc7946#section-3.3
41
+
42
+ [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
43
+
44
+ [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
45
+
46
+ [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
47
+
48
+ [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
49
+
50
+ [7]: https://tools.ietf.org/html/rfc7946#section-3.2
51
+
52
+ [8]: https://tools.ietf.org/html/rfc7946#section-3.1.6
53
+
54
+ [9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
55
+
56
+ [10]: https://tools.ietf.org/html/rfc7946#section-3.3
36
57
 
37
58
  <!-- This file is automatically generated. Please don't edit it directly:
38
59
  if you find an error, edit the source file (likely index.js), and re-run
package/dist/es/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import intersect from "@turf/boolean-intersects";
2
- import distance from "@turf/distance";
3
- import { featureCollection, polygon, } from "@turf/helpers";
2
+ import { convertLength, featureCollection, polygon, } from "@turf/helpers";
4
3
  /**
5
4
  * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
6
5
  *
@@ -26,32 +25,28 @@ import { featureCollection, polygon, } from "@turf/helpers";
26
25
  * //addToMap
27
26
  * var addToMap = [rectangleGrid]
28
27
  */
29
- function rectangleGrid(bbox, cellWidth, cellHeight, options) {
30
- if (options === void 0) { options = {}; }
28
+ function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
31
29
  // Containers
32
- var results = [];
33
- var west = bbox[0];
34
- var south = bbox[1];
35
- var east = bbox[2];
36
- var north = bbox[3];
37
- var xFraction = cellWidth / distance([west, south], [east, south], options);
38
- var cellWidthDeg = xFraction * (east - west);
39
- var yFraction = cellHeight / distance([west, south], [west, north], options);
40
- var cellHeightDeg = yFraction * (north - south);
41
- // rows & columns
42
- var bboxWidth = east - west;
43
- var bboxHeight = north - south;
44
- var columns = Math.floor(bboxWidth / cellWidthDeg);
45
- var rows = Math.floor(bboxHeight / cellHeightDeg);
30
+ const results = [];
31
+ const west = bbox[0];
32
+ const south = bbox[1];
33
+ const east = bbox[2];
34
+ const north = bbox[3];
35
+ const bboxWidth = east - west;
36
+ const cellWidthDeg = convertLength(cellWidth, options.units, "degrees");
37
+ const bboxHeight = north - south;
38
+ const cellHeightDeg = convertLength(cellHeight, options.units, "degrees");
39
+ const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);
40
+ const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);
46
41
  // if the grid does not fill the bbox perfectly, center it.
47
- var deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
48
- var deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
42
+ const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
43
+ const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
49
44
  // iterate over columns & rows
50
- var currentX = west + deltaX;
51
- for (var column = 0; column < columns; column++) {
52
- var currentY = south + deltaY;
53
- for (var row = 0; row < rows; row++) {
54
- var cellPoly = polygon([
45
+ let currentX = west + deltaX;
46
+ for (let column = 0; column < columns; column++) {
47
+ let currentY = south + deltaY;
48
+ for (let row = 0; row < rows; row++) {
49
+ const cellPoly = polygon([
55
50
  [
56
51
  [currentX, currentY],
57
52
  [currentX, currentY + cellHeightDeg],
@@ -1,4 +1,5 @@
1
- import { BBox, Feature, FeatureCollection, MultiPolygon, Polygon, Properties, Units } from "@turf/helpers";
1
+ import { BBox, Feature, FeatureCollection, MultiPolygon, Polygon, GeoJsonProperties } from "geojson";
2
+ import { Units } from "@turf/helpers";
2
3
  /**
3
4
  * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
4
5
  *
@@ -24,7 +25,7 @@ import { BBox, Feature, FeatureCollection, MultiPolygon, Polygon, Properties, Un
24
25
  * //addToMap
25
26
  * var addToMap = [rectangleGrid]
26
27
  */
27
- declare function rectangleGrid<P = Properties>(bbox: BBox, cellWidth: number, cellHeight: number, options?: {
28
+ declare function rectangleGrid<P = GeoJsonProperties>(bbox: BBox, cellWidth: number, cellHeight: number, options?: {
28
29
  units?: Units;
29
30
  properties?: P;
30
31
  mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon;
package/dist/js/index.js CHANGED
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var boolean_intersects_1 = __importDefault(require("@turf/boolean-intersects"));
7
- var distance_1 = __importDefault(require("@turf/distance"));
8
- var helpers_1 = require("@turf/helpers");
3
+ const tslib_1 = require("tslib");
4
+ const boolean_intersects_1 = tslib_1.__importDefault(require("@turf/boolean-intersects"));
5
+ const helpers_1 = require("@turf/helpers");
9
6
  /**
10
7
  * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
11
8
  *
@@ -31,32 +28,28 @@ var helpers_1 = require("@turf/helpers");
31
28
  * //addToMap
32
29
  * var addToMap = [rectangleGrid]
33
30
  */
34
- function rectangleGrid(bbox, cellWidth, cellHeight, options) {
35
- if (options === void 0) { options = {}; }
31
+ function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
36
32
  // Containers
37
- var results = [];
38
- var west = bbox[0];
39
- var south = bbox[1];
40
- var east = bbox[2];
41
- var north = bbox[3];
42
- var xFraction = cellWidth / distance_1.default([west, south], [east, south], options);
43
- var cellWidthDeg = xFraction * (east - west);
44
- var yFraction = cellHeight / distance_1.default([west, south], [west, north], options);
45
- var cellHeightDeg = yFraction * (north - south);
46
- // rows & columns
47
- var bboxWidth = east - west;
48
- var bboxHeight = north - south;
49
- var columns = Math.floor(bboxWidth / cellWidthDeg);
50
- var rows = Math.floor(bboxHeight / cellHeightDeg);
33
+ const results = [];
34
+ const west = bbox[0];
35
+ const south = bbox[1];
36
+ const east = bbox[2];
37
+ const north = bbox[3];
38
+ const bboxWidth = east - west;
39
+ const cellWidthDeg = helpers_1.convertLength(cellWidth, options.units, "degrees");
40
+ const bboxHeight = north - south;
41
+ const cellHeightDeg = helpers_1.convertLength(cellHeight, options.units, "degrees");
42
+ const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);
43
+ const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);
51
44
  // if the grid does not fill the bbox perfectly, center it.
52
- var deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
53
- var deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
45
+ const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
46
+ const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
54
47
  // iterate over columns & rows
55
- var currentX = west + deltaX;
56
- for (var column = 0; column < columns; column++) {
57
- var currentY = south + deltaY;
58
- for (var row = 0; row < rows; row++) {
59
- var cellPoly = helpers_1.polygon([
48
+ let currentX = west + deltaX;
49
+ for (let column = 0; column < columns; column++) {
50
+ let currentY = south + deltaY;
51
+ for (let row = 0; row < rows; row++) {
52
+ const cellPoly = helpers_1.polygon([
60
53
  [
61
54
  [currentX, currentY],
62
55
  [currentX, currentY + cellHeightDeg],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/rectangle-grid",
3
- "version": "6.4.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf rectangle-grid module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -16,6 +16,7 @@
16
16
  "type": "git",
17
17
  "url": "git://github.com/Turfjs/turf.git"
18
18
  },
19
+ "funding": "https://opencollective.com/turf",
19
20
  "publishConfig": {
20
21
  "access": "public"
21
22
  },
@@ -49,8 +50,8 @@
49
50
  "test:tape": "ts-node -r esm test.js"
50
51
  },
51
52
  "devDependencies": {
52
- "@turf/bbox-polygon": "^6.4.0",
53
- "@turf/truncate": "^6.4.0",
53
+ "@turf/bbox-polygon": "^7.0.0-alpha.0",
54
+ "@turf/truncate": "^7.0.0-alpha.0",
54
55
  "benchmark": "*",
55
56
  "load-json-file": "*",
56
57
  "npm-run-all": "*",
@@ -61,9 +62,10 @@
61
62
  "write-json-file": "*"
62
63
  },
63
64
  "dependencies": {
64
- "@turf/boolean-intersects": "^6.4.0",
65
- "@turf/distance": "^6.4.0",
66
- "@turf/helpers": "^6.4.0"
65
+ "@turf/boolean-intersects": "^7.0.0-alpha.0",
66
+ "@turf/distance": "^7.0.0-alpha.0",
67
+ "@turf/helpers": "^7.0.0-alpha.0",
68
+ "tslib": "^2.3.0"
67
69
  },
68
- "gitHead": "1e62773cfc88c627cca8effcb5c14cfb65a905ac"
70
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
69
71
  }