@turf/transform-scale 6.5.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 +8 -7
- package/dist/es/index.js +7 -3
- package/dist/js/index.js +7 -3
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).
|
|
8
8
|
If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
### Parameters
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- `options.origin` **([string][4] \| [Coord][5])** Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) (optional, default `'centroid'`)
|
|
16
|
-
- `options.mutate` **[boolean][6]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`)
|
|
12
|
+
* `geojson` **[GeoJSON][1]** GeoJSON to be scaled
|
|
13
|
+
* `factor` **[number][2]** of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.
|
|
14
|
+
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
|
|
17
15
|
|
|
18
|
-
**
|
|
16
|
+
* `options.origin` **([string][4] | [Coord][5])** Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) (optional, default `'centroid'`)
|
|
17
|
+
* `options.mutate` **[boolean][6]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`)
|
|
18
|
+
|
|
19
|
+
### Examples
|
|
19
20
|
|
|
20
21
|
```javascript
|
|
21
22
|
var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
|
package/dist/es/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { getType, getCoords, getCoord } from '@turf/invariant';
|
|
|
15
15
|
*
|
|
16
16
|
* @name transformScale
|
|
17
17
|
* @param {GeoJSON} geojson GeoJSON to be scaled
|
|
18
|
-
* @param {number} factor of scaling, positive
|
|
18
|
+
* @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.
|
|
19
19
|
* @param {Object} [options={}] Optional parameters
|
|
20
20
|
* @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
|
|
21
21
|
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
@@ -37,7 +37,7 @@ function transformScale(geojson, factor, options) {
|
|
|
37
37
|
|
|
38
38
|
// Input validation
|
|
39
39
|
if (!geojson) throw new Error("geojson required");
|
|
40
|
-
if (typeof factor !== "number" || factor
|
|
40
|
+
if (typeof factor !== "number" || factor <= 0)
|
|
41
41
|
throw new Error("invalid factor");
|
|
42
42
|
var originIsPoint = Array.isArray(origin) || typeof origin === "object";
|
|
43
43
|
|
|
@@ -83,6 +83,8 @@ function scale(feature, factor, origin) {
|
|
|
83
83
|
if (coord.length === 3) coord[2] *= factor;
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
+
delete feature.bbox;
|
|
87
|
+
|
|
86
88
|
return feature;
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -103,7 +105,9 @@ function defineOrigin(geojson, origin) {
|
|
|
103
105
|
return getCoord(origin);
|
|
104
106
|
|
|
105
107
|
// Define BBox
|
|
106
|
-
var bbox = geojson.bbox
|
|
108
|
+
var bbox = geojson.bbox
|
|
109
|
+
? geojson.bbox
|
|
110
|
+
: turfBBox(geojson, { recalculate: true });
|
|
107
111
|
var west = bbox[0];
|
|
108
112
|
var south = bbox[1];
|
|
109
113
|
var east = bbox[2];
|
package/dist/js/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var rhumbDestination__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDestinat
|
|
|
27
27
|
*
|
|
28
28
|
* @name transformScale
|
|
29
29
|
* @param {GeoJSON} geojson GeoJSON to be scaled
|
|
30
|
-
* @param {number} factor of scaling, positive
|
|
30
|
+
* @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.
|
|
31
31
|
* @param {Object} [options={}] Optional parameters
|
|
32
32
|
* @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
|
|
33
33
|
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
@@ -49,7 +49,7 @@ function transformScale(geojson, factor, options) {
|
|
|
49
49
|
|
|
50
50
|
// Input validation
|
|
51
51
|
if (!geojson) throw new Error("geojson required");
|
|
52
|
-
if (typeof factor !== "number" || factor
|
|
52
|
+
if (typeof factor !== "number" || factor <= 0)
|
|
53
53
|
throw new Error("invalid factor");
|
|
54
54
|
var originIsPoint = Array.isArray(origin) || typeof origin === "object";
|
|
55
55
|
|
|
@@ -95,6 +95,8 @@ function scale(feature, factor, origin) {
|
|
|
95
95
|
if (coord.length === 3) coord[2] *= factor;
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
delete feature.bbox;
|
|
99
|
+
|
|
98
100
|
return feature;
|
|
99
101
|
}
|
|
100
102
|
|
|
@@ -115,7 +117,9 @@ function defineOrigin(geojson, origin) {
|
|
|
115
117
|
return invariant.getCoord(origin);
|
|
116
118
|
|
|
117
119
|
// Define BBox
|
|
118
|
-
var bbox = geojson.bbox
|
|
120
|
+
var bbox = geojson.bbox
|
|
121
|
+
? geojson.bbox
|
|
122
|
+
: turfBBox__default['default'](geojson, { recalculate: true });
|
|
119
123
|
var west = bbox[0];
|
|
120
124
|
var south = bbox[1];
|
|
121
125
|
var east = bbox[2];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/transform-scale",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf transform-scale module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"docs": "node ../../scripts/generate-readmes",
|
|
52
52
|
"test": "npm-run-all test:*",
|
|
53
53
|
"test:tape": "node -r esm test.js",
|
|
54
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
54
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@turf/bbox-polygon": "^
|
|
58
|
-
"@turf/hex-grid": "^
|
|
59
|
-
"@turf/truncate": "^
|
|
57
|
+
"@turf/bbox-polygon": "^7.0.0-alpha.0",
|
|
58
|
+
"@turf/hex-grid": "^7.0.0-alpha.0",
|
|
59
|
+
"@turf/truncate": "^7.0.0-alpha.0",
|
|
60
60
|
"benchmark": "*",
|
|
61
61
|
"load-json-file": "*",
|
|
62
62
|
"npm-run-all": "*",
|
|
@@ -65,16 +65,16 @@
|
|
|
65
65
|
"write-json-file": "*"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@turf/bbox": "^
|
|
69
|
-
"@turf/center": "^
|
|
70
|
-
"@turf/centroid": "^
|
|
71
|
-
"@turf/clone": "^
|
|
72
|
-
"@turf/helpers": "^
|
|
73
|
-
"@turf/invariant": "^
|
|
74
|
-
"@turf/meta": "^
|
|
75
|
-
"@turf/rhumb-bearing": "^
|
|
76
|
-
"@turf/rhumb-destination": "^
|
|
77
|
-
"@turf/rhumb-distance": "^
|
|
68
|
+
"@turf/bbox": "^7.0.0-alpha.0",
|
|
69
|
+
"@turf/center": "^7.0.0-alpha.0",
|
|
70
|
+
"@turf/centroid": "^7.0.0-alpha.0",
|
|
71
|
+
"@turf/clone": "^7.0.0-alpha.0",
|
|
72
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
73
|
+
"@turf/invariant": "^7.0.0-alpha.0",
|
|
74
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
75
|
+
"@turf/rhumb-bearing": "^7.0.0-alpha.0",
|
|
76
|
+
"@turf/rhumb-destination": "^7.0.0-alpha.0",
|
|
77
|
+
"@turf/rhumb-distance": "^7.0.0-alpha.0"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
80
80
|
}
|