@turf/rectangle-grid 7.0.0-alpha.2 → 7.1.0-alpha.7

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
@@ -55,26 +55,21 @@ Returns **[FeatureCollection][10]<[Polygon][8]>** a grid of polygons
55
55
 
56
56
  [10]: https://tools.ietf.org/html/rfc7946#section-3.3
57
57
 
58
- <!-- This file is automatically generated. Please don't edit it directly:
59
- if you find an error, edit the source file (likely index.js), and re-run
60
- ./scripts/generate-readmes in the turf project. -->
58
+ <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
61
59
 
62
60
  ---
63
61
 
64
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
65
- module collection dedicated to geographic algorithms. It is maintained in the
66
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
67
- PRs and issues.
62
+ This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
68
63
 
69
64
  ### Installation
70
65
 
71
- Install this module individually:
66
+ Install this single module individually:
72
67
 
73
68
  ```sh
74
69
  $ npm install @turf/rectangle-grid
75
70
  ```
76
71
 
77
- Or install the Turf module that includes it as a function:
72
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
78
73
 
79
74
  ```sh
80
75
  $ npm install @turf/turf
@@ -0,0 +1,56 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
+ var _booleanintersects = require('@turf/boolean-intersects');
3
+
4
+
5
+
6
+
7
+ var _helpers = require('@turf/helpers');
8
+ function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
9
+ const results = [];
10
+ const west = bbox[0];
11
+ const south = bbox[1];
12
+ const east = bbox[2];
13
+ const north = bbox[3];
14
+ const bboxWidth = east - west;
15
+ const cellWidthDeg = _helpers.convertLength.call(void 0, cellWidth, options.units, "degrees");
16
+ const bboxHeight = north - south;
17
+ const cellHeightDeg = _helpers.convertLength.call(void 0, cellHeight, options.units, "degrees");
18
+ const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);
19
+ const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);
20
+ const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
21
+ const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
22
+ let currentX = west + deltaX;
23
+ for (let column = 0; column < columns; column++) {
24
+ let currentY = south + deltaY;
25
+ for (let row = 0; row < rows; row++) {
26
+ const cellPoly = _helpers.polygon.call(void 0,
27
+ [
28
+ [
29
+ [currentX, currentY],
30
+ [currentX, currentY + cellHeightDeg],
31
+ [currentX + cellWidthDeg, currentY + cellHeightDeg],
32
+ [currentX + cellWidthDeg, currentY],
33
+ [currentX, currentY]
34
+ ]
35
+ ],
36
+ options.properties
37
+ );
38
+ if (options.mask) {
39
+ if (_booleanintersects.booleanIntersects.call(void 0, options.mask, cellPoly)) {
40
+ results.push(cellPoly);
41
+ }
42
+ } else {
43
+ results.push(cellPoly);
44
+ }
45
+ currentY += cellHeightDeg;
46
+ }
47
+ currentX += cellWidthDeg;
48
+ }
49
+ return _helpers.featureCollection.call(void 0, results);
50
+ }
51
+ var turf_rectangle_grid_default = rectangleGrid;
52
+
53
+
54
+
55
+ exports.default = turf_rectangle_grid_default; exports.rectangleGrid = rectangleGrid;
56
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAAA,SAAS,qBAAqB,iBAAiB;AAS/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA0BP,SAAS,cACP,MACA,WACA,YACA,UAII,CAAC,GAC0B;AAE/B,QAAM,UAAU,CAAC;AACjB,QAAM,OAAO,KAAK,CAAC;AACnB,QAAM,QAAQ,KAAK,CAAC;AACpB,QAAM,OAAO,KAAK,CAAC;AACnB,QAAM,QAAQ,KAAK,CAAC;AAEpB,QAAM,YAAY,OAAO;AACzB,QAAM,eAAe,cAAc,WAAW,QAAQ,OAAO,SAAS;AAEtE,QAAM,aAAa,QAAQ;AAC3B,QAAM,gBAAgB,cAAc,YAAY,QAAQ,OAAO,SAAS;AAExE,QAAM,UAAU,KAAK,MAAM,KAAK,IAAI,SAAS,IAAI,YAAY;AAC7D,QAAM,OAAO,KAAK,MAAM,KAAK,IAAI,UAAU,IAAI,aAAa;AAG5D,QAAM,UAAU,YAAY,UAAU,gBAAgB;AACtD,QAAM,UAAU,aAAa,OAAO,iBAAiB;AAGrD,MAAI,WAAW,OAAO;AACtB,WAAS,SAAS,GAAG,SAAS,SAAS,UAAU;AAC/C,QAAI,WAAW,QAAQ;AACvB,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,YAAM,WAAW;AAAA,QACf;AAAA,UACE;AAAA,YACE,CAAC,UAAU,QAAQ;AAAA,YACnB,CAAC,UAAU,WAAW,aAAa;AAAA,YACnC,CAAC,WAAW,cAAc,WAAW,aAAa;AAAA,YAClD,CAAC,WAAW,cAAc,QAAQ;AAAA,YAClC,CAAC,UAAU,QAAQ;AAAA,UACrB;AAAA,QACF;AAAA,QACA,QAAQ;AAAA,MACV;AACA,UAAI,QAAQ,MAAM;AAChB,YAAI,UAAU,QAAQ,MAAM,QAAQ,GAAG;AACrC,kBAAQ,KAAK,QAAQ;AAAA,QACvB;AAAA,MACF,OAAO;AACL,gBAAQ,KAAK,QAAQ;AAAA,MACvB;AAEA,kBAAY;AAAA,IACd;AACA,gBAAY;AAAA,EACd;AACA,SAAO,kBAAkB,OAAO;AAClC;AAGA,IAAO,8BAAQ","sourcesContent":["import { booleanIntersects as intersect } from \"@turf/boolean-intersects\";\nimport {\n BBox,\n Feature,\n FeatureCollection,\n MultiPolygon,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport {\n convertLength,\n featureCollection,\n polygon,\n Units,\n} from \"@turf/helpers\";\n/**\n * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.\n *\n * @name rectangleGrid\n * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order\n * @param {number} cellWidth of each cell, in units\n * @param {number} cellHeight of each cell, in units\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] units (\"degrees\", \"radians\", \"miles\", \"kilometers\") that the given cellWidth\n * and cellHeight are expressed in. Converted at the southern border.\n * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,\n * the grid Points will be created only inside it\n * @param {Object} [options.properties={}] passed to each point of the grid\n * @returns {FeatureCollection<Polygon>} a grid of polygons\n * @example\n * var bbox = [-95, 30 ,-85, 40];\n * var cellWidth = 50;\n * var cellHeight = 20;\n * var options = {units: 'miles'};\n *\n * var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);\n *\n * //addToMap\n * var addToMap = [rectangleGrid]\n */\nfunction rectangleGrid<P extends GeoJsonProperties = GeoJsonProperties>(\n bbox: BBox,\n cellWidth: number,\n cellHeight: number,\n options: {\n units?: Units;\n properties?: P;\n mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon;\n } = {}\n): FeatureCollection<Polygon, P> {\n // Containers\n const results = [];\n const west = bbox[0];\n const south = bbox[1];\n const east = bbox[2];\n const north = bbox[3];\n\n const bboxWidth = east - west;\n const cellWidthDeg = convertLength(cellWidth, options.units, \"degrees\");\n\n const bboxHeight = north - south;\n const cellHeightDeg = convertLength(cellHeight, options.units, \"degrees\");\n\n const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);\n const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);\n\n // if the grid does not fill the bbox perfectly, center it.\n const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;\n const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;\n\n // iterate over columns & rows\n let currentX = west + deltaX;\n for (let column = 0; column < columns; column++) {\n let currentY = south + deltaY;\n for (let row = 0; row < rows; row++) {\n const cellPoly = polygon(\n [\n [\n [currentX, currentY],\n [currentX, currentY + cellHeightDeg],\n [currentX + cellWidthDeg, currentY + cellHeightDeg],\n [currentX + cellWidthDeg, currentY],\n [currentX, currentY],\n ],\n ],\n options.properties\n );\n if (options.mask) {\n if (intersect(options.mask, cellPoly)) {\n results.push(cellPoly);\n }\n } else {\n results.push(cellPoly);\n }\n\n currentY += cellHeightDeg;\n }\n currentX += cellWidthDeg;\n }\n return featureCollection(results);\n}\n\nexport { rectangleGrid };\nexport default rectangleGrid;\n"]}
@@ -0,0 +1,35 @@
1
+ import { GeoJsonProperties, BBox, Feature, Polygon, MultiPolygon, FeatureCollection } from 'geojson';
2
+ import { Units } from '@turf/helpers';
3
+
4
+ /**
5
+ * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
6
+ *
7
+ * @name rectangleGrid
8
+ * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
9
+ * @param {number} cellWidth of each cell, in units
10
+ * @param {number} cellHeight of each cell, in units
11
+ * @param {Object} [options={}] Optional parameters
12
+ * @param {string} [options.units='kilometers'] units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
13
+ * and cellHeight are expressed in. Converted at the southern border.
14
+ * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
15
+ * the grid Points will be created only inside it
16
+ * @param {Object} [options.properties={}] passed to each point of the grid
17
+ * @returns {FeatureCollection<Polygon>} a grid of polygons
18
+ * @example
19
+ * var bbox = [-95, 30 ,-85, 40];
20
+ * var cellWidth = 50;
21
+ * var cellHeight = 20;
22
+ * var options = {units: 'miles'};
23
+ *
24
+ * var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);
25
+ *
26
+ * //addToMap
27
+ * var addToMap = [rectangleGrid]
28
+ */
29
+ declare function rectangleGrid<P extends GeoJsonProperties = GeoJsonProperties>(bbox: BBox, cellWidth: number, cellHeight: number, options?: {
30
+ units?: Units;
31
+ properties?: P;
32
+ mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon;
33
+ }): FeatureCollection<Polygon, P>;
34
+
35
+ export { rectangleGrid as default, rectangleGrid };
@@ -1,5 +1,6 @@
1
- import { BBox, Feature, FeatureCollection, MultiPolygon, Polygon, GeoJsonProperties } from "geojson";
2
- import { Units } from "@turf/helpers";
1
+ import { GeoJsonProperties, BBox, Feature, Polygon, MultiPolygon, FeatureCollection } from 'geojson';
2
+ import { Units } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
5
6
  *
@@ -25,9 +26,10 @@ import { Units } from "@turf/helpers";
25
26
  * //addToMap
26
27
  * var addToMap = [rectangleGrid]
27
28
  */
28
- declare function rectangleGrid<P = GeoJsonProperties>(bbox: BBox, cellWidth: number, cellHeight: number, options?: {
29
+ declare function rectangleGrid<P extends GeoJsonProperties = GeoJsonProperties>(bbox: BBox, cellWidth: number, cellHeight: number, options?: {
29
30
  units?: Units;
30
31
  properties?: P;
31
32
  mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon;
32
33
  }): FeatureCollection<Polygon, P>;
33
- export default rectangleGrid;
34
+
35
+ export { rectangleGrid as default, rectangleGrid };
@@ -0,0 +1,56 @@
1
+ // index.ts
2
+ import { booleanIntersects as intersect } from "@turf/boolean-intersects";
3
+ import {
4
+ convertLength,
5
+ featureCollection,
6
+ polygon
7
+ } from "@turf/helpers";
8
+ function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
9
+ const results = [];
10
+ const west = bbox[0];
11
+ const south = bbox[1];
12
+ const east = bbox[2];
13
+ const north = bbox[3];
14
+ const bboxWidth = east - west;
15
+ const cellWidthDeg = convertLength(cellWidth, options.units, "degrees");
16
+ const bboxHeight = north - south;
17
+ const cellHeightDeg = convertLength(cellHeight, options.units, "degrees");
18
+ const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);
19
+ const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);
20
+ const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
21
+ const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
22
+ let currentX = west + deltaX;
23
+ for (let column = 0; column < columns; column++) {
24
+ let currentY = south + deltaY;
25
+ for (let row = 0; row < rows; row++) {
26
+ const cellPoly = polygon(
27
+ [
28
+ [
29
+ [currentX, currentY],
30
+ [currentX, currentY + cellHeightDeg],
31
+ [currentX + cellWidthDeg, currentY + cellHeightDeg],
32
+ [currentX + cellWidthDeg, currentY],
33
+ [currentX, currentY]
34
+ ]
35
+ ],
36
+ options.properties
37
+ );
38
+ if (options.mask) {
39
+ if (intersect(options.mask, cellPoly)) {
40
+ results.push(cellPoly);
41
+ }
42
+ } else {
43
+ results.push(cellPoly);
44
+ }
45
+ currentY += cellHeightDeg;
46
+ }
47
+ currentX += cellWidthDeg;
48
+ }
49
+ return featureCollection(results);
50
+ }
51
+ var turf_rectangle_grid_default = rectangleGrid;
52
+ export {
53
+ turf_rectangle_grid_default as default,
54
+ rectangleGrid
55
+ };
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { booleanIntersects as intersect } from \"@turf/boolean-intersects\";\nimport {\n BBox,\n Feature,\n FeatureCollection,\n MultiPolygon,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport {\n convertLength,\n featureCollection,\n polygon,\n Units,\n} from \"@turf/helpers\";\n/**\n * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.\n *\n * @name rectangleGrid\n * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order\n * @param {number} cellWidth of each cell, in units\n * @param {number} cellHeight of each cell, in units\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] units (\"degrees\", \"radians\", \"miles\", \"kilometers\") that the given cellWidth\n * and cellHeight are expressed in. Converted at the southern border.\n * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,\n * the grid Points will be created only inside it\n * @param {Object} [options.properties={}] passed to each point of the grid\n * @returns {FeatureCollection<Polygon>} a grid of polygons\n * @example\n * var bbox = [-95, 30 ,-85, 40];\n * var cellWidth = 50;\n * var cellHeight = 20;\n * var options = {units: 'miles'};\n *\n * var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);\n *\n * //addToMap\n * var addToMap = [rectangleGrid]\n */\nfunction rectangleGrid<P extends GeoJsonProperties = GeoJsonProperties>(\n bbox: BBox,\n cellWidth: number,\n cellHeight: number,\n options: {\n units?: Units;\n properties?: P;\n mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon;\n } = {}\n): FeatureCollection<Polygon, P> {\n // Containers\n const results = [];\n const west = bbox[0];\n const south = bbox[1];\n const east = bbox[2];\n const north = bbox[3];\n\n const bboxWidth = east - west;\n const cellWidthDeg = convertLength(cellWidth, options.units, \"degrees\");\n\n const bboxHeight = north - south;\n const cellHeightDeg = convertLength(cellHeight, options.units, \"degrees\");\n\n const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);\n const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);\n\n // if the grid does not fill the bbox perfectly, center it.\n const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;\n const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;\n\n // iterate over columns & rows\n let currentX = west + deltaX;\n for (let column = 0; column < columns; column++) {\n let currentY = south + deltaY;\n for (let row = 0; row < rows; row++) {\n const cellPoly = polygon(\n [\n [\n [currentX, currentY],\n [currentX, currentY + cellHeightDeg],\n [currentX + cellWidthDeg, currentY + cellHeightDeg],\n [currentX + cellWidthDeg, currentY],\n [currentX, currentY],\n ],\n ],\n options.properties\n );\n if (options.mask) {\n if (intersect(options.mask, cellPoly)) {\n results.push(cellPoly);\n }\n } else {\n results.push(cellPoly);\n }\n\n currentY += cellHeightDeg;\n }\n currentX += cellWidthDeg;\n }\n return featureCollection(results);\n}\n\nexport { rectangleGrid };\nexport default rectangleGrid;\n"],"mappings":";AAAA,SAAS,qBAAqB,iBAAiB;AAS/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA0BP,SAAS,cACP,MACA,WACA,YACA,UAII,CAAC,GAC0B;AAE/B,QAAM,UAAU,CAAC;AACjB,QAAM,OAAO,KAAK,CAAC;AACnB,QAAM,QAAQ,KAAK,CAAC;AACpB,QAAM,OAAO,KAAK,CAAC;AACnB,QAAM,QAAQ,KAAK,CAAC;AAEpB,QAAM,YAAY,OAAO;AACzB,QAAM,eAAe,cAAc,WAAW,QAAQ,OAAO,SAAS;AAEtE,QAAM,aAAa,QAAQ;AAC3B,QAAM,gBAAgB,cAAc,YAAY,QAAQ,OAAO,SAAS;AAExE,QAAM,UAAU,KAAK,MAAM,KAAK,IAAI,SAAS,IAAI,YAAY;AAC7D,QAAM,OAAO,KAAK,MAAM,KAAK,IAAI,UAAU,IAAI,aAAa;AAG5D,QAAM,UAAU,YAAY,UAAU,gBAAgB;AACtD,QAAM,UAAU,aAAa,OAAO,iBAAiB;AAGrD,MAAI,WAAW,OAAO;AACtB,WAAS,SAAS,GAAG,SAAS,SAAS,UAAU;AAC/C,QAAI,WAAW,QAAQ;AACvB,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,YAAM,WAAW;AAAA,QACf;AAAA,UACE;AAAA,YACE,CAAC,UAAU,QAAQ;AAAA,YACnB,CAAC,UAAU,WAAW,aAAa;AAAA,YACnC,CAAC,WAAW,cAAc,WAAW,aAAa;AAAA,YAClD,CAAC,WAAW,cAAc,QAAQ;AAAA,YAClC,CAAC,UAAU,QAAQ;AAAA,UACrB;AAAA,QACF;AAAA,QACA,QAAQ;AAAA,MACV;AACA,UAAI,QAAQ,MAAM;AAChB,YAAI,UAAU,QAAQ,MAAM,QAAQ,GAAG;AACrC,kBAAQ,KAAK,QAAQ;AAAA,QACvB;AAAA,MACF,OAAO;AACL,gBAAQ,KAAK,QAAQ;AAAA,MACvB;AAEA,kBAAY;AAAA,IACd;AACA,gBAAY;AAAA,EACd;AACA,SAAO,kBAAkB,OAAO;AAClC;AAGA,IAAO,8BAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/rectangle-grid",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.1.0-alpha.7+0ce6ecca0",
4
4
  "description": "turf rectangle-grid module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -26,47 +26,53 @@
26
26
  "regular",
27
27
  "cartesian"
28
28
  ],
29
- "main": "dist/js/index.js",
30
- "module": "dist/es/index.js",
29
+ "type": "module",
30
+ "main": "dist/cjs/index.cjs",
31
+ "module": "dist/esm/index.js",
32
+ "types": "dist/esm/index.d.ts",
31
33
  "exports": {
32
34
  "./package.json": "./package.json",
33
35
  ".": {
34
- "types": "./dist/js/index.d.ts",
35
- "import": "./dist/es/index.js",
36
- "require": "./dist/js/index.js"
36
+ "import": {
37
+ "types": "./dist/esm/index.d.ts",
38
+ "default": "./dist/esm/index.js"
39
+ },
40
+ "require": {
41
+ "types": "./dist/cjs/index.d.cts",
42
+ "default": "./dist/cjs/index.cjs"
43
+ }
37
44
  }
38
45
  },
39
- "types": "dist/js/index.d.ts",
40
46
  "sideEffects": false,
41
47
  "files": [
42
48
  "dist"
43
49
  ],
44
50
  "scripts": {
45
- "bench": "tsx bench.js",
46
- "build": "npm-run-all build:*",
47
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
48
- "build:js": "tsc",
49
- "docs": "tsx ../../scripts/generate-readmes",
50
- "test": "npm-run-all test:*",
51
- "test:tape": "tsx test.js"
51
+ "bench": "tsx bench.ts",
52
+ "build": "tsup --config ../../tsup.config.ts",
53
+ "docs": "tsx ../../scripts/generate-readmes.ts",
54
+ "test": "npm-run-all --npm-path npm test:*",
55
+ "test:tape": "tsx test.ts"
52
56
  },
53
57
  "devDependencies": {
54
- "@turf/bbox-polygon": "^7.0.0-alpha.2",
55
- "@turf/truncate": "^7.0.0-alpha.2",
56
- "benchmark": "*",
57
- "load-json-file": "*",
58
- "npm-run-all": "*",
59
- "rollup": "*",
60
- "tape": "*",
61
- "tsx": "*",
62
- "typescript": "*",
63
- "write-json-file": "*"
58
+ "@turf/bbox-polygon": "^7.1.0-alpha.7+0ce6ecca0",
59
+ "@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0",
60
+ "@types/benchmark": "^2.1.5",
61
+ "@types/tape": "^4.2.32",
62
+ "benchmark": "^2.1.4",
63
+ "load-json-file": "^7.0.1",
64
+ "npm-run-all": "^4.1.5",
65
+ "tape": "^5.7.2",
66
+ "tsup": "^8.0.1",
67
+ "tsx": "^4.6.2",
68
+ "typescript": "^5.2.2",
69
+ "write-json-file": "^5.0.0"
64
70
  },
65
71
  "dependencies": {
66
- "@turf/boolean-intersects": "^7.0.0-alpha.2",
67
- "@turf/distance": "^7.0.0-alpha.2",
68
- "@turf/helpers": "^7.0.0-alpha.2",
69
- "tslib": "^2.3.0"
72
+ "@turf/boolean-intersects": "^7.1.0-alpha.7+0ce6ecca0",
73
+ "@turf/distance": "^7.1.0-alpha.7+0ce6ecca0",
74
+ "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
75
+ "tslib": "^2.6.2"
70
76
  },
71
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
77
+ "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
72
78
  }
package/dist/es/index.js DELETED
@@ -1,72 +0,0 @@
1
- import intersect from "@turf/boolean-intersects";
2
- import { convertLength, featureCollection, polygon, } from "@turf/helpers";
3
- /**
4
- * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
5
- *
6
- * @name rectangleGrid
7
- * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
8
- * @param {number} cellWidth of each cell, in units
9
- * @param {number} cellHeight of each cell, in units
10
- * @param {Object} [options={}] Optional parameters
11
- * @param {string} [options.units='kilometers'] units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
12
- * and cellHeight are expressed in. Converted at the southern border.
13
- * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
14
- * the grid Points will be created only inside it
15
- * @param {Object} [options.properties={}] passed to each point of the grid
16
- * @returns {FeatureCollection<Polygon>} a grid of polygons
17
- * @example
18
- * var bbox = [-95, 30 ,-85, 40];
19
- * var cellWidth = 50;
20
- * var cellHeight = 20;
21
- * var options = {units: 'miles'};
22
- *
23
- * var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);
24
- *
25
- * //addToMap
26
- * var addToMap = [rectangleGrid]
27
- */
28
- function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
29
- // Containers
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);
41
- // if the grid does not fill the bbox perfectly, center it.
42
- const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
43
- const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
44
- // iterate over columns & rows
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([
50
- [
51
- [currentX, currentY],
52
- [currentX, currentY + cellHeightDeg],
53
- [currentX + cellWidthDeg, currentY + cellHeightDeg],
54
- [currentX + cellWidthDeg, currentY],
55
- [currentX, currentY],
56
- ],
57
- ], options.properties);
58
- if (options.mask) {
59
- if (intersect(options.mask, cellPoly)) {
60
- results.push(cellPoly);
61
- }
62
- }
63
- else {
64
- results.push(cellPoly);
65
- }
66
- currentY += cellHeightDeg;
67
- }
68
- currentX += cellWidthDeg;
69
- }
70
- return featureCollection(results);
71
- }
72
- export default rectangleGrid;
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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");
6
- /**
7
- * Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
8
- *
9
- * @name rectangleGrid
10
- * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
11
- * @param {number} cellWidth of each cell, in units
12
- * @param {number} cellHeight of each cell, in units
13
- * @param {Object} [options={}] Optional parameters
14
- * @param {string} [options.units='kilometers'] units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
15
- * and cellHeight are expressed in. Converted at the southern border.
16
- * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
17
- * the grid Points will be created only inside it
18
- * @param {Object} [options.properties={}] passed to each point of the grid
19
- * @returns {FeatureCollection<Polygon>} a grid of polygons
20
- * @example
21
- * var bbox = [-95, 30 ,-85, 40];
22
- * var cellWidth = 50;
23
- * var cellHeight = 20;
24
- * var options = {units: 'miles'};
25
- *
26
- * var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);
27
- *
28
- * //addToMap
29
- * var addToMap = [rectangleGrid]
30
- */
31
- function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
32
- // Containers
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);
44
- // if the grid does not fill the bbox perfectly, center it.
45
- const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
46
- const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
47
- // iterate over columns & rows
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([
53
- [
54
- [currentX, currentY],
55
- [currentX, currentY + cellHeightDeg],
56
- [currentX + cellWidthDeg, currentY + cellHeightDeg],
57
- [currentX + cellWidthDeg, currentY],
58
- [currentX, currentY],
59
- ],
60
- ], options.properties);
61
- if (options.mask) {
62
- if (boolean_intersects_1.default(options.mask, cellPoly)) {
63
- results.push(cellPoly);
64
- }
65
- }
66
- else {
67
- results.push(cellPoly);
68
- }
69
- currentY += cellHeightDeg;
70
- }
71
- currentX += cellWidthDeg;
72
- }
73
- return helpers_1.featureCollection(results);
74
- }
75
- exports.default = rectangleGrid;