@turf/square-grid
Advanced tools
Comparing version 5.1.5 to 6.0.0
70
index.js
@@ -1,6 +0,6 @@ | ||
import distance from '@turf/distance'; | ||
import intersect from '@turf/intersect'; | ||
import {getType} from '@turf/invariant'; | ||
import {polygon, featureCollection, isObject, isNumber} from '@turf/helpers'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var distance_1 = require("@turf/distance"); | ||
var boolean_intersects_1 = require("@turf/boolean-intersects"); | ||
var helpers_1 = require("@turf/helpers"); | ||
/** | ||
@@ -28,20 +28,12 @@ * Creates a square grid from a bounding box, {@link Feature} or {@link FeatureCollection}. | ||
function squareGrid(bbox, cellSide, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
// var units = options.units; | ||
var properties = options.properties; | ||
var mask = options.mask; | ||
if (options === void 0) { options = {}; } | ||
// Containers | ||
var results = []; | ||
// Input Validation | ||
if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required'); | ||
if (!isNumber(cellSide)) throw new Error('cellSide is invalid'); | ||
if (!bbox) throw new Error('bbox is required'); | ||
if (!Array.isArray(bbox)) throw new Error('bbox must be array'); | ||
if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers'); | ||
if (mask && ['Polygon', 'MultiPolygon'].indexOf(getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon'); | ||
// Input Validation is being handled by Typescript | ||
// if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required'); | ||
// if (!isNumber(cellSide)) throw new Error('cellSide is invalid'); | ||
// if (!bbox) throw new Error('bbox is required'); | ||
// if (!Array.isArray(bbox)) throw new Error('bbox must be array'); | ||
// if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers'); | ||
// if (options.mask && ['Polygon', 'MultiPolygon'].indexOf(getType(options.mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon'); | ||
var west = bbox[0]; | ||
@@ -51,8 +43,6 @@ var south = bbox[1]; | ||
var north = bbox[3]; | ||
var xFraction = cellSide / (distance([west, south], [east, south], options)); | ||
var xFraction = cellSide / (distance_1.default([west, south], [east, south], options)); | ||
var cellWidth = xFraction * (east - west); | ||
var yFraction = cellSide / (distance([west, south], [west, north], options)); | ||
var yFraction = cellSide / (distance_1.default([west, south], [west, north], options)); | ||
var cellHeight = yFraction * (north - south); | ||
// rows & columns | ||
@@ -63,7 +53,5 @@ var bboxWidth = (east - west); | ||
var rows = Math.floor(bboxHeight / cellHeight); | ||
// adjust origin of the grid | ||
var deltaX = (bboxWidth - columns * cellWidth) / 2; | ||
var deltaY = (bboxHeight - rows * cellHeight) / 2; | ||
// iterate over columns & rows | ||
@@ -74,15 +62,16 @@ var currentX = west + deltaX; | ||
for (var row = 0; row < rows; row++) { | ||
var cellPoly = polygon([[ | ||
[currentX, currentY], | ||
[currentX, currentY + cellHeight], | ||
[currentX + cellWidth, currentY + cellHeight], | ||
[currentX + cellWidth, currentY], | ||
[currentX, currentY] | ||
]], properties); | ||
if (mask) { | ||
if (intersect(mask, cellPoly)) results.push(cellPoly); | ||
} else { | ||
var cellPoly = helpers_1.polygon([[ | ||
[currentX, currentY], | ||
[currentX, currentY + cellHeight], | ||
[currentX + cellWidth, currentY + cellHeight], | ||
[currentX + cellWidth, currentY], | ||
[currentX, currentY] | ||
]], options.properties); | ||
if (options.mask) { | ||
if (boolean_intersects_1.default(options.mask, cellPoly)) | ||
results.push(cellPoly); | ||
} | ||
else { | ||
results.push(cellPoly); | ||
} | ||
currentY += cellHeight; | ||
@@ -92,5 +81,4 @@ } | ||
} | ||
return featureCollection(results); | ||
return helpers_1.featureCollection(results); | ||
} | ||
export default squareGrid; | ||
exports.default = squareGrid; |
{ | ||
"name": "@turf/square-grid", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf square-grid module", | ||
"main": "main.js", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
"main": "index", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
"main.es.js" | ||
"index.ts" | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
"prepare": "tsc", | ||
"pretest": "tsc", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
@@ -40,4 +36,4 @@ }, | ||
"@std/esm": "*", | ||
"@turf/bbox-polygon": "^5.1.5", | ||
"@turf/truncate": "^5.1.5", | ||
"@turf/bbox-polygon": "*", | ||
"@turf/truncate": "*", | ||
"benchmark": "*", | ||
@@ -49,13 +45,7 @@ "rollup": "*", | ||
"dependencies": { | ||
"@turf/boolean-contains": "^5.1.5", | ||
"@turf/boolean-overlap": "^5.1.5", | ||
"@turf/distance": "^5.1.5", | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/intersect": "^5.1.5", | ||
"@turf/invariant": "^5.1.5" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/boolean-intersects": "6.x", | ||
"@turf/distance": "6.x", | ||
"@turf/helpers": "6.x", | ||
"@turf/invariant": "6.x" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
11910
5
161
1
+ Added@turf/boolean-intersects@6.x
+ Added@turf/bbox@7.1.0(transitive)
+ Added@turf/boolean-disjoint@6.5.0(transitive)
+ Added@turf/boolean-intersects@6.5.0(transitive)
+ Added@turf/boolean-point-in-polygon@6.5.0(transitive)
+ Added@turf/distance@6.5.0(transitive)
+ Added@turf/helpers@6.5.07.1.0(transitive)
+ Added@turf/invariant@6.5.0(transitive)
+ Added@turf/line-intersect@6.5.0(transitive)
+ Added@turf/line-segment@6.5.0(transitive)
+ Added@turf/meta@6.5.07.1.0(transitive)
+ Added@turf/polygon-to-line@6.5.0(transitive)
+ Added@types/geojson@7946.0.147946.0.8(transitive)
+ Addedgeojson-rbush@3.2.0(transitive)
+ Addedquickselect@2.0.0(transitive)
+ Addedrbush@3.0.1(transitive)
+ Addedtslib@2.7.0(transitive)
- Removed@turf/boolean-contains@^5.1.5
- Removed@turf/boolean-overlap@^5.1.5
- Removed@turf/intersect@^5.1.5
- Removed@turf/bbox@5.1.5(transitive)
- Removed@turf/bearing@5.1.5(transitive)
- Removed@turf/boolean-contains@5.1.5(transitive)
- Removed@turf/boolean-overlap@5.1.5(transitive)
- Removed@turf/boolean-point-in-polygon@5.1.5(transitive)
- Removed@turf/boolean-point-on-line@5.1.5(transitive)
- Removed@turf/clean-coords@5.1.5(transitive)
- Removed@turf/destination@5.1.5(transitive)
- Removed@turf/distance@5.1.5(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/intersect@5.1.6(transitive)
- Removed@turf/invariant@5.2.0(transitive)
- Removed@turf/line-intersect@5.1.5(transitive)
- Removed@turf/line-overlap@5.1.5(transitive)
- Removed@turf/line-segment@5.1.5(transitive)
- Removed@turf/meta@5.2.0(transitive)
- Removed@turf/nearest-point-on-line@5.1.5(transitive)
- Removed@turf/truncate@5.1.5(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddeep-equal@1.1.2(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedgeojson-equality@0.1.6(transitive)
- Removedgeojson-rbush@2.1.0(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis-arguments@1.1.1(transitive)
- Removedis-date-object@1.0.5(transitive)
- Removedis-regex@1.1.4(transitive)
- Removedobject-is@1.1.6(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedquickselect@3.0.0(transitive)
- Removedrbush@4.0.1(transitive)
- Removedregexp.prototype.flags@1.5.2(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedturf-jsts@1.2.3(transitive)
Updated@turf/distance@6.x
Updated@turf/helpers@6.x
Updated@turf/invariant@6.x