@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 +32 -11
- package/dist/es/index.js +20 -25
- package/dist/js/index.d.ts +3 -2
- package/dist/js/index.js +22 -29
- package/package.json +9 -7
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]
|
|
7
|
+
Creates a grid of rectangles from a bounding box, [Feature][1] or [FeatureCollection][2].
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
+
* `options.properties` **[Object][5]** passed to each point of the grid (optional, default `{}`)
|
|
20
21
|
|
|
21
|
-
|
|
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]
|
|
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
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
48
|
-
|
|
42
|
+
const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
|
|
43
|
+
const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
|
|
49
44
|
// iterate over columns & rows
|
|
50
|
-
|
|
51
|
-
for (
|
|
52
|
-
|
|
53
|
-
for (
|
|
54
|
-
|
|
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],
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BBox, Feature, FeatureCollection, MultiPolygon, Polygon,
|
|
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 =
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
53
|
-
|
|
45
|
+
const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
|
|
46
|
+
const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
|
|
54
47
|
// iterate over columns & rows
|
|
55
|
-
|
|
56
|
-
for (
|
|
57
|
-
|
|
58
|
-
for (
|
|
59
|
-
|
|
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": "
|
|
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": "^
|
|
53
|
-
"@turf/truncate": "^
|
|
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": "^
|
|
65
|
-
"@turf/distance": "^
|
|
66
|
-
"@turf/helpers": "^
|
|
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": "
|
|
70
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
69
71
|
}
|