@turf/rectangle-grid 7.0.0 → 7.1.0-alpha.70

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,20 +4,22 @@
4
4
 
5
5
  ## rectangleGrid
6
6
 
7
- Creates a grid of rectangles from a bounding box, [Feature][1] or [FeatureCollection][2].
7
+ Creates a grid of rectangular polygons with width and height consistent in degrees
8
8
 
9
9
  ### Parameters
10
10
 
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 `{}`)
11
+ * `bbox` **[BBox][1]** extent of grid in \[minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
12
+ * `cellWidth` **[number][2]** width of each cell, in units
13
+ * `cellHeight` **[number][2]** height of each cell, in units
14
+ * `options` **[Object][3]** Optional parameters (optional, default `{}`)
15
15
 
16
- * `options.units` **[string][6]** units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
17
- and cellHeight are expressed in. Converted at the southern border. (optional, default `'kilometers'`)
18
- * `options.mask` **[Feature][7]<([Polygon][8] | [MultiPolygon][9])>?** if passed a Polygon or MultiPolygon,
16
+ * `options.units` **Units** the units of the cell width and height value.
17
+ Supports all valid Turf [Units][4].
18
+ If you are looking for rectangles with equal width and height in linear units (e.g. kilometers) this is not the module for you.
19
+ The cellWidth and cellHeight is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees. (optional, default `'kilometers'`)
20
+ * `options.mask` **[Feature][5]<([Polygon][6] | [MultiPolygon][7])>?** if passed a Polygon or MultiPolygon,
19
21
  the grid Points will be created only inside it
20
- * `options.properties` **[Object][5]** passed to each point of the grid (optional, default `{}`)
22
+ * `options.properties` **[Object][3]** passed to each point of the grid (optional, default `{}`)
21
23
 
22
24
  ### Examples
23
25
 
@@ -33,27 +35,23 @@ var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);
33
35
  var addToMap = [rectangleGrid]
34
36
  ```
35
37
 
36
- Returns **[FeatureCollection][10]<[Polygon][8]>** a grid of polygons
38
+ Returns **[FeatureCollection][8]<[Polygon][6]>** a grid of polygons
37
39
 
38
- [1]: https://tools.ietf.org/html/rfc7946#section-3.2
40
+ [1]: https://tools.ietf.org/html/rfc7946#section-5
39
41
 
40
- [2]: https://tools.ietf.org/html/rfc7946#section-3.3
42
+ [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
41
43
 
42
- [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
44
+ [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
43
45
 
44
- [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
46
+ [4]: https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md
45
47
 
46
- [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
48
+ [5]: https://tools.ietf.org/html/rfc7946#section-3.2
47
49
 
48
- [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
50
+ [6]: https://tools.ietf.org/html/rfc7946#section-3.1.6
49
51
 
50
- [7]: https://tools.ietf.org/html/rfc7946#section-3.2
52
+ [7]: https://tools.ietf.org/html/rfc7946#section-3.1.7
51
53
 
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
54
+ [8]: https://tools.ietf.org/html/rfc7946#section-3.3
57
55
 
58
56
  <!-- 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. -->
59
57
 
@@ -1,7 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
5
2
  var _booleanintersects = require('@turf/boolean-intersects');
6
3
 
7
4
 
@@ -51,7 +48,6 @@ function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
51
48
  }
52
49
  return _helpers.featureCollection.call(void 0, results);
53
50
  }
54
- __name(rectangleGrid, "rectangleGrid");
55
51
  var turf_rectangle_grid_default = rectangleGrid;
56
52
 
57
53
 
@@ -1 +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;AA5DS;AA+DT,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"]}
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAAA,SAAS,qBAAqB,iBAAiB;AAS/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA4BP,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 rectangular polygons with width and height consistent in degrees\n *\n * @name rectangleGrid\n * @param {BBox} bbox extent of grid in [minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.\n * @param {number} cellWidth width of each cell, in units\n * @param {number} cellHeight height of each cell, in units\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] the units of the cell width and height value.\n * Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md Units}.\n * If you are looking for rectangles with equal width and height in linear units (e.g. kilometers) this is not the module for you.\n * The cellWidth and cellHeight is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees.\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"]}
@@ -2,15 +2,17 @@ import { GeoJsonProperties, BBox, Feature, Polygon, MultiPolygon, FeatureCollect
2
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
+ * Creates a grid of rectangular polygons with width and height consistent in degrees
6
6
  *
7
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
8
+ * @param {BBox} bbox extent of grid in [minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
9
+ * @param {number} cellWidth width of each cell, in units
10
+ * @param {number} cellHeight height of each cell, in units
11
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.
12
+ * @param {Units} [options.units='kilometers'] the units of the cell width and height value.
13
+ * Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md Units}.
14
+ * If you are looking for rectangles with equal width and height in linear units (e.g. kilometers) this is not the module for you.
15
+ * The cellWidth and cellHeight is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees.
14
16
  * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
15
17
  * the grid Points will be created only inside it
16
18
  * @param {Object} [options.properties={}] passed to each point of the grid
@@ -2,15 +2,17 @@ import { GeoJsonProperties, BBox, Feature, Polygon, MultiPolygon, FeatureCollect
2
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
+ * Creates a grid of rectangular polygons with width and height consistent in degrees
6
6
  *
7
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
8
+ * @param {BBox} bbox extent of grid in [minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
9
+ * @param {number} cellWidth width of each cell, in units
10
+ * @param {number} cellHeight height of each cell, in units
11
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.
12
+ * @param {Units} [options.units='kilometers'] the units of the cell width and height value.
13
+ * Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md Units}.
14
+ * If you are looking for rectangles with equal width and height in linear units (e.g. kilometers) this is not the module for you.
15
+ * The cellWidth and cellHeight is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees.
14
16
  * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
15
17
  * the grid Points will be created only inside it
16
18
  * @param {Object} [options.properties={}] passed to each point of the grid
package/dist/esm/index.js CHANGED
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // index.ts
5
2
  import { booleanIntersects as intersect } from "@turf/boolean-intersects";
6
3
  import {
@@ -51,7 +48,6 @@ function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
51
48
  }
52
49
  return featureCollection(results);
53
50
  }
54
- __name(rectangleGrid, "rectangleGrid");
55
51
  var turf_rectangle_grid_default = rectangleGrid;
56
52
  export {
57
53
  turf_rectangle_grid_default as default,
@@ -1 +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;AA5DS;AA+DT,IAAO,8BAAQ;","names":[]}
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 rectangular polygons with width and height consistent in degrees\n *\n * @name rectangleGrid\n * @param {BBox} bbox extent of grid in [minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.\n * @param {number} cellWidth width of each cell, in units\n * @param {number} cellHeight height of each cell, in units\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] the units of the cell width and height value.\n * Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md Units}.\n * If you are looking for rectangles with equal width and height in linear units (e.g. kilometers) this is not the module for you.\n * The cellWidth and cellHeight is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees.\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;AA4BP,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",
3
+ "version": "7.1.0-alpha.70+948cdafaf",
4
4
  "description": "turf rectangle-grid module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -55,8 +55,8 @@
55
55
  "test:tape": "tsx test.ts"
56
56
  },
57
57
  "devDependencies": {
58
- "@turf/bbox-polygon": "^7.0.0",
59
- "@turf/truncate": "^7.0.0",
58
+ "@turf/bbox-polygon": "^7.1.0-alpha.70+948cdafaf",
59
+ "@turf/truncate": "^7.1.0-alpha.70+948cdafaf",
60
60
  "@types/benchmark": "^2.1.5",
61
61
  "@types/tape": "^4.2.32",
62
62
  "benchmark": "^2.1.4",
@@ -69,10 +69,11 @@
69
69
  "write-json-file": "^5.0.0"
70
70
  },
71
71
  "dependencies": {
72
- "@turf/boolean-intersects": "^7.0.0",
73
- "@turf/distance": "^7.0.0",
74
- "@turf/helpers": "^7.0.0",
72
+ "@turf/boolean-intersects": "^7.1.0-alpha.70+948cdafaf",
73
+ "@turf/distance": "^7.1.0-alpha.70+948cdafaf",
74
+ "@turf/helpers": "^7.1.0-alpha.70+948cdafaf",
75
+ "@types/geojson": "^7946.0.10",
75
76
  "tslib": "^2.6.2"
76
77
  },
77
- "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
78
+ "gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067"
78
79
  }