@turf/concave
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -33,16 +33,15 @@ import distance from "@turf/distance"; | ||
*/ | ||
function concave(points, options) { | ||
if (options === void 0) { options = {}; } | ||
var maxEdge = options.maxEdge || Infinity; | ||
var cleaned = removeDuplicates(points); | ||
var tinPolys = tin(cleaned); | ||
function concave(points, options = {}) { | ||
const maxEdge = options.maxEdge || Infinity; | ||
const cleaned = removeDuplicates(points); | ||
const tinPolys = tin(cleaned); | ||
// calculate length of all edges and area of all triangles | ||
// and remove triangles that fail the max length test | ||
tinPolys.features = tinPolys.features.filter(function (triangle) { | ||
var pt1 = triangle.geometry.coordinates[0][0]; | ||
var pt2 = triangle.geometry.coordinates[0][1]; | ||
var pt3 = triangle.geometry.coordinates[0][2]; | ||
var dist1 = distance(pt1, pt2, options); | ||
var dist2 = distance(pt2, pt3, options); | ||
var dist3 = distance(pt1, pt3, options); | ||
tinPolys.features = tinPolys.features.filter((triangle) => { | ||
const pt1 = triangle.geometry.coordinates[0][0]; | ||
const pt2 = triangle.geometry.coordinates[0][1]; | ||
const pt3 = triangle.geometry.coordinates[0][2]; | ||
const dist1 = distance(pt1, pt2, options); | ||
const dist2 = distance(pt2, pt3, options); | ||
const dist3 = distance(pt1, pt3, options); | ||
return dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge; | ||
@@ -54,3 +53,3 @@ }); | ||
// merge the adjacent triangles | ||
var dissolved = dissolve(tinPolys); | ||
const dissolved = dissolve(tinPolys); | ||
// geojson-dissolve always returns a MultiPolygon | ||
@@ -71,9 +70,9 @@ if (dissolved.coordinates.length === 1) { | ||
function removeDuplicates(points) { | ||
var cleaned = []; | ||
var existing = {}; | ||
featureEach(points, function (pt) { | ||
const cleaned = []; | ||
const existing = {}; | ||
featureEach(points, (pt) => { | ||
if (!pt.geometry) { | ||
return; | ||
} | ||
var key = pt.geometry.coordinates.join("-"); | ||
const key = pt.geometry.coordinates.join("-"); | ||
if (!Object.prototype.hasOwnProperty.call(existing, key)) { | ||
@@ -80,0 +79,0 @@ cleaned.push(pt); |
@@ -17,4 +17,3 @@ import clone from "@turf/clone"; | ||
*/ | ||
function dissolve(geojson, options) { | ||
if (options === void 0) { options = {}; } | ||
function dissolve(geojson, options = {}) { | ||
// Optional parameters | ||
@@ -25,3 +24,3 @@ options = options || {}; | ||
} | ||
var mutate = options.mutate; | ||
const mutate = options.mutate; | ||
// Validation | ||
@@ -40,3 +39,3 @@ if (getType(geojson) !== "FeatureCollection") { | ||
// Assert homogenity | ||
var type = getHomogenousType(geojson); | ||
const type = getHomogenousType(geojson); | ||
if (!type) { | ||
@@ -46,3 +45,3 @@ throw new Error("geojson must be homogenous"); | ||
// Data => Typescript hack | ||
var data = geojson; | ||
const data = geojson; | ||
switch (type) { | ||
@@ -65,7 +64,7 @@ case "LineString": | ||
function getHomogenousType(geojson) { | ||
var types = {}; | ||
flattenEach(geojson, function (feature) { | ||
const types = {}; | ||
flattenEach(geojson, (feature) => { | ||
types[feature.geometry.type] = true; | ||
}); | ||
var keys = Object.keys(types); | ||
const keys = Object.keys(types); | ||
if (keys.length === 1) { | ||
@@ -72,0 +71,0 @@ return keys[0]; |
@@ -14,4 +14,3 @@ import clone from "@turf/clone"; | ||
*/ | ||
function lineDissolve(geojson, options) { | ||
if (options === void 0) { options = {}; } | ||
function lineDissolve(geojson, options = {}) { | ||
// Optional parameters | ||
@@ -22,3 +21,3 @@ options = options || {}; | ||
} | ||
var mutate = options.mutate; | ||
const mutate = options.mutate; | ||
// Validation | ||
@@ -35,7 +34,7 @@ if (getType(geojson) !== "FeatureCollection") { | ||
} | ||
var result = []; | ||
var lastLine = lineReduce(geojson, function (previousLine, currentLine) { | ||
const result = []; | ||
const lastLine = lineReduce(geojson, (previousLine, currentLine) => { | ||
// Attempt to merge this LineString with the other LineStrings, updating | ||
// the reference as it is merged with others and grows. | ||
var merged = mergeLineStrings(previousLine, currentLine); | ||
const merged = mergeLineStrings(previousLine, currentLine); | ||
// Accumulate the merged LineString | ||
@@ -65,3 +64,3 @@ if (merged) { | ||
else { | ||
return multiLineString(result.map(function (line) { | ||
return multiLineString(result.map((line) => { | ||
return line.coordinates; | ||
@@ -84,10 +83,10 @@ })); | ||
function mergeLineStrings(a, b) { | ||
var coords1 = a.geometry.coordinates; | ||
var coords2 = b.geometry.coordinates; | ||
var s1 = coordId(coords1[0]); | ||
var e1 = coordId(coords1[coords1.length - 1]); | ||
var s2 = coordId(coords2[0]); | ||
var e2 = coordId(coords2[coords2.length - 1]); | ||
const coords1 = a.geometry.coordinates; | ||
const coords2 = b.geometry.coordinates; | ||
const s1 = coordId(coords1[0]); | ||
const e1 = coordId(coords1[coords1.length - 1]); | ||
const s2 = coordId(coords2[0]); | ||
const e2 = coordId(coords2[coords2.length - 1]); | ||
// TODO: handle case where more than one of these is true! | ||
var coords; | ||
let coords; | ||
if (s1 === e2) { | ||
@@ -94,0 +93,0 @@ coords = coords2.concat(coords1.slice(1)); |
@@ -15,4 +15,3 @@ import clone from "@turf/clone"; | ||
*/ | ||
export default function polygonDissolve(geojson, options) { | ||
if (options === void 0) { options = {}; } | ||
export default function polygonDissolve(geojson, options = {}) { | ||
// Validation | ||
@@ -30,9 +29,9 @@ if (getType(geojson) !== "FeatureCollection") { | ||
} | ||
var geoms = []; | ||
flattenEach(geojson, function (feature) { | ||
const geoms = []; | ||
flattenEach(geojson, (feature) => { | ||
geoms.push(feature.geometry); | ||
}); | ||
var topo = topology({ geoms: geometryCollection(geoms).geometry }); | ||
var merged = merge(topo, topo.objects.geoms.geometries); | ||
const topo = topology({ geoms: geometryCollection(geoms).geometry }); | ||
const merged = merge(topo, topo.objects.geoms.geometries); | ||
return merged; | ||
} |
@@ -1,2 +0,3 @@ | ||
import { Feature, FeatureCollection, MultiPolygon, Point, Polygon, Units } from "@turf/helpers"; | ||
import { Feature, FeatureCollection, MultiPolygon, Point, Polygon } from "geojson"; | ||
import { Units } from "@turf/helpers"; | ||
/** | ||
@@ -3,0 +4,0 @@ * Takes a set of {@link Point|points} and returns a concave hull Polygon or MultiPolygon. |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var distance_1 = __importDefault(require("@turf/distance")); | ||
var helpers_1 = require("@turf/helpers"); | ||
var meta_1 = require("@turf/meta"); | ||
var tin_1 = __importDefault(require("@turf/tin")); | ||
var turf_dissolve_1 = __importDefault(require("./lib/turf-dissolve")); | ||
const tslib_1 = require("tslib"); | ||
const distance_1 = tslib_1.__importDefault(require("@turf/distance")); | ||
const helpers_1 = require("@turf/helpers"); | ||
const meta_1 = require("@turf/meta"); | ||
const tin_1 = tslib_1.__importDefault(require("@turf/tin")); | ||
const turf_dissolve_1 = tslib_1.__importDefault(require("./lib/turf-dissolve")); | ||
/** | ||
@@ -38,16 +36,15 @@ * Takes a set of {@link Point|points} and returns a concave hull Polygon or MultiPolygon. | ||
*/ | ||
function concave(points, options) { | ||
if (options === void 0) { options = {}; } | ||
var maxEdge = options.maxEdge || Infinity; | ||
var cleaned = removeDuplicates(points); | ||
var tinPolys = tin_1.default(cleaned); | ||
function concave(points, options = {}) { | ||
const maxEdge = options.maxEdge || Infinity; | ||
const cleaned = removeDuplicates(points); | ||
const tinPolys = tin_1.default(cleaned); | ||
// calculate length of all edges and area of all triangles | ||
// and remove triangles that fail the max length test | ||
tinPolys.features = tinPolys.features.filter(function (triangle) { | ||
var pt1 = triangle.geometry.coordinates[0][0]; | ||
var pt2 = triangle.geometry.coordinates[0][1]; | ||
var pt3 = triangle.geometry.coordinates[0][2]; | ||
var dist1 = distance_1.default(pt1, pt2, options); | ||
var dist2 = distance_1.default(pt2, pt3, options); | ||
var dist3 = distance_1.default(pt1, pt3, options); | ||
tinPolys.features = tinPolys.features.filter((triangle) => { | ||
const pt1 = triangle.geometry.coordinates[0][0]; | ||
const pt2 = triangle.geometry.coordinates[0][1]; | ||
const pt3 = triangle.geometry.coordinates[0][2]; | ||
const dist1 = distance_1.default(pt1, pt2, options); | ||
const dist2 = distance_1.default(pt2, pt3, options); | ||
const dist3 = distance_1.default(pt1, pt3, options); | ||
return dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge; | ||
@@ -59,3 +56,3 @@ }); | ||
// merge the adjacent triangles | ||
var dissolved = turf_dissolve_1.default(tinPolys); | ||
const dissolved = turf_dissolve_1.default(tinPolys); | ||
// geojson-dissolve always returns a MultiPolygon | ||
@@ -76,9 +73,9 @@ if (dissolved.coordinates.length === 1) { | ||
function removeDuplicates(points) { | ||
var cleaned = []; | ||
var existing = {}; | ||
meta_1.featureEach(points, function (pt) { | ||
const cleaned = []; | ||
const existing = {}; | ||
meta_1.featureEach(points, (pt) => { | ||
if (!pt.geometry) { | ||
return; | ||
} | ||
var key = pt.geometry.coordinates.join("-"); | ||
const key = pt.geometry.coordinates.join("-"); | ||
if (!Object.prototype.hasOwnProperty.call(existing, key)) { | ||
@@ -85,0 +82,0 @@ cleaned.push(pt); |
@@ -1,2 +0,2 @@ | ||
import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "@turf/helpers"; | ||
import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "geojson"; | ||
/** | ||
@@ -3,0 +3,0 @@ * Transform function: attempts to dissolve geojson objects where possible |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var clone_1 = __importDefault(require("@turf/clone")); | ||
var helpers_1 = require("@turf/helpers"); | ||
var invariant_1 = require("@turf/invariant"); | ||
var meta_1 = require("@turf/meta"); | ||
var turf_line_dissolve_1 = __importDefault(require("./turf-line-dissolve")); | ||
var turf_polygon_dissolve_1 = __importDefault(require("./turf-polygon-dissolve")); | ||
const tslib_1 = require("tslib"); | ||
const clone_1 = tslib_1.__importDefault(require("@turf/clone")); | ||
const helpers_1 = require("@turf/helpers"); | ||
const invariant_1 = require("@turf/invariant"); | ||
const meta_1 = require("@turf/meta"); | ||
const turf_line_dissolve_1 = tslib_1.__importDefault(require("./turf-line-dissolve")); | ||
const turf_polygon_dissolve_1 = tslib_1.__importDefault(require("./turf-polygon-dissolve")); | ||
/** | ||
@@ -22,4 +20,3 @@ * Transform function: attempts to dissolve geojson objects where possible | ||
*/ | ||
function dissolve(geojson, options) { | ||
if (options === void 0) { options = {}; } | ||
function dissolve(geojson, options = {}) { | ||
// Optional parameters | ||
@@ -30,3 +27,3 @@ options = options || {}; | ||
} | ||
var mutate = options.mutate; | ||
const mutate = options.mutate; | ||
// Validation | ||
@@ -45,3 +42,3 @@ if (invariant_1.getType(geojson) !== "FeatureCollection") { | ||
// Assert homogenity | ||
var type = getHomogenousType(geojson); | ||
const type = getHomogenousType(geojson); | ||
if (!type) { | ||
@@ -51,3 +48,3 @@ throw new Error("geojson must be homogenous"); | ||
// Data => Typescript hack | ||
var data = geojson; | ||
const data = geojson; | ||
switch (type) { | ||
@@ -70,7 +67,7 @@ case "LineString": | ||
function getHomogenousType(geojson) { | ||
var types = {}; | ||
meta_1.flattenEach(geojson, function (feature) { | ||
const types = {}; | ||
meta_1.flattenEach(geojson, (feature) => { | ||
types[feature.geometry.type] = true; | ||
}); | ||
var keys = Object.keys(types); | ||
const keys = Object.keys(types); | ||
if (keys.length === 1) { | ||
@@ -77,0 +74,0 @@ return keys[0]; |
@@ -1,2 +0,2 @@ | ||
import { Feature, FeatureCollection, LineString, MultiLineString } from "@turf/helpers"; | ||
import { Feature, FeatureCollection, LineString, MultiLineString } from "geojson"; | ||
/** | ||
@@ -3,0 +3,0 @@ * Merges all connected (non-forking, non-junctioning) line strings into single lineStrings. |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var clone_1 = __importDefault(require("@turf/clone")); | ||
var helpers_1 = require("@turf/helpers"); | ||
var invariant_1 = require("@turf/invariant"); | ||
var meta_1 = require("@turf/meta"); | ||
const tslib_1 = require("tslib"); | ||
const clone_1 = tslib_1.__importDefault(require("@turf/clone")); | ||
const helpers_1 = require("@turf/helpers"); | ||
const invariant_1 = require("@turf/invariant"); | ||
const meta_1 = require("@turf/meta"); | ||
/** | ||
@@ -19,4 +17,3 @@ * Merges all connected (non-forking, non-junctioning) line strings into single lineStrings. | ||
*/ | ||
function lineDissolve(geojson, options) { | ||
if (options === void 0) { options = {}; } | ||
function lineDissolve(geojson, options = {}) { | ||
// Optional parameters | ||
@@ -27,3 +24,3 @@ options = options || {}; | ||
} | ||
var mutate = options.mutate; | ||
const mutate = options.mutate; | ||
// Validation | ||
@@ -40,7 +37,7 @@ if (invariant_1.getType(geojson) !== "FeatureCollection") { | ||
} | ||
var result = []; | ||
var lastLine = meta_1.lineReduce(geojson, function (previousLine, currentLine) { | ||
const result = []; | ||
const lastLine = meta_1.lineReduce(geojson, (previousLine, currentLine) => { | ||
// Attempt to merge this LineString with the other LineStrings, updating | ||
// the reference as it is merged with others and grows. | ||
var merged = mergeLineStrings(previousLine, currentLine); | ||
const merged = mergeLineStrings(previousLine, currentLine); | ||
// Accumulate the merged LineString | ||
@@ -70,3 +67,3 @@ if (merged) { | ||
else { | ||
return helpers_1.multiLineString(result.map(function (line) { | ||
return helpers_1.multiLineString(result.map((line) => { | ||
return line.coordinates; | ||
@@ -89,10 +86,10 @@ })); | ||
function mergeLineStrings(a, b) { | ||
var coords1 = a.geometry.coordinates; | ||
var coords2 = b.geometry.coordinates; | ||
var s1 = coordId(coords1[0]); | ||
var e1 = coordId(coords1[coords1.length - 1]); | ||
var s2 = coordId(coords2[0]); | ||
var e2 = coordId(coords2[coords2.length - 1]); | ||
const coords1 = a.geometry.coordinates; | ||
const coords2 = b.geometry.coordinates; | ||
const s1 = coordId(coords1[0]); | ||
const e1 = coordId(coords1[coords1.length - 1]); | ||
const s2 = coordId(coords2[0]); | ||
const e2 = coordId(coords2[coords2.length - 1]); | ||
// TODO: handle case where more than one of these is true! | ||
var coords; | ||
let coords; | ||
if (s1 === e2) { | ||
@@ -99,0 +96,0 @@ coords = coords2.concat(coords1.slice(1)); |
@@ -1,2 +0,2 @@ | ||
import { Feature, FeatureCollection, MultiPolygon, Polygon } from "@turf/helpers"; | ||
import { Feature, FeatureCollection, MultiPolygon, Polygon } from "geojson"; | ||
/** | ||
@@ -3,0 +3,0 @@ * Dissolves all overlapping (Multi)Polygon |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var clone_1 = __importDefault(require("@turf/clone")); | ||
var helpers_1 = require("@turf/helpers"); | ||
var invariant_1 = require("@turf/invariant"); | ||
var meta_1 = require("@turf/meta"); | ||
var topojson_client_1 = require("topojson-client"); | ||
var topojson_server_1 = require("topojson-server"); | ||
const tslib_1 = require("tslib"); | ||
const clone_1 = tslib_1.__importDefault(require("@turf/clone")); | ||
const helpers_1 = require("@turf/helpers"); | ||
const invariant_1 = require("@turf/invariant"); | ||
const meta_1 = require("@turf/meta"); | ||
const topojson_client_1 = require("topojson-client"); | ||
const topojson_server_1 = require("topojson-server"); | ||
/** | ||
@@ -20,4 +18,3 @@ * Dissolves all overlapping (Multi)Polygon | ||
*/ | ||
function polygonDissolve(geojson, options) { | ||
if (options === void 0) { options = {}; } | ||
function polygonDissolve(geojson, options = {}) { | ||
// Validation | ||
@@ -35,10 +32,10 @@ if (invariant_1.getType(geojson) !== "FeatureCollection") { | ||
} | ||
var geoms = []; | ||
meta_1.flattenEach(geojson, function (feature) { | ||
const geoms = []; | ||
meta_1.flattenEach(geojson, (feature) => { | ||
geoms.push(feature.geometry); | ||
}); | ||
var topo = topojson_server_1.topology({ geoms: helpers_1.geometryCollection(geoms).geometry }); | ||
var merged = topojson_client_1.merge(topo, topo.objects.geoms.geometries); | ||
const topo = topojson_server_1.topology({ geoms: helpers_1.geometryCollection(geoms).geometry }); | ||
const merged = topojson_client_1.merge(topo, topo.objects.geoms.geometries); | ||
return merged; | ||
} | ||
exports.default = polygonDissolve; |
{ | ||
"name": "@turf/concave", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf concave module", | ||
@@ -73,12 +73,13 @@ "author": "Turf Authors", | ||
"dependencies": { | ||
"@turf/clone": "^6.5.0", | ||
"@turf/distance": "^6.5.0", | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/invariant": "^6.5.0", | ||
"@turf/meta": "^6.5.0", | ||
"@turf/tin": "^6.5.0", | ||
"@turf/clone": "^7.0.0-alpha.0", | ||
"@turf/distance": "^7.0.0-alpha.0", | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/invariant": "^7.0.0-alpha.0", | ||
"@turf/meta": "^7.0.0-alpha.0", | ||
"@turf/tin": "^7.0.0-alpha.0", | ||
"topojson-client": "3.x", | ||
"topojson-server": "3.x" | ||
"topojson-server": "3.x", | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -10,11 +10,13 @@ # @turf/concave | ||
**Parameters** | ||
### Parameters | ||
- `points` **[FeatureCollection][3]<[Point][4]>** input points | ||
- `options` **[Object][5]** Optional parameters (optional, default `{}`) | ||
- `options.maxEdge` **[number][6]** the length (in 'units') of an edge necessary for part of the hull to become concave. (optional, default `Infinity`) | ||
- `options.units` **[string][7]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`) | ||
* `points` **[FeatureCollection][3]<[Point][4]>** input points | ||
* `options` **[Object][5]** Optional parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.maxEdge` **[number][6]** the length (in 'units') of an edge necessary for part of the | ||
hull to become concave. (optional, default `Infinity`) | ||
* `options.units` **[string][7]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`) | ||
### Examples | ||
```javascript | ||
@@ -37,3 +39,3 @@ var points = turf.featureCollection([ | ||
Returns **([Feature][8]<([Polygon][9] \| [MultiPolygon][10])> | null)** a concave hull (null value is returned if unable to compute hull) | ||
Returns **([Feature][8]<([Polygon][9] | [MultiPolygon][10])> | null)** a concave hull (null value is returned if unable to compute hull) | ||
@@ -40,0 +42,0 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.2 |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
84
30691
9
670
1
+ Addedtslib@^2.3.0
+ Added@turf/clone@7.2.0(transitive)
+ Added@turf/distance@7.2.0(transitive)
+ Added@turf/helpers@7.2.0(transitive)
+ Added@turf/invariant@7.2.0(transitive)
+ Added@turf/meta@7.2.0(transitive)
+ Added@turf/tin@7.2.0(transitive)
+ Added@types/geojson@7946.0.16(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/clone@6.5.0(transitive)
- Removed@turf/distance@6.5.0(transitive)
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/invariant@6.5.0(transitive)
- Removed@turf/meta@6.5.0(transitive)
- Removed@turf/tin@6.5.0(transitive)
Updated@turf/clone@^7.0.0-alpha.0
Updated@turf/helpers@^7.0.0-alpha.0
Updated@turf/meta@^7.0.0-alpha.0
Updated@turf/tin@^7.0.0-alpha.0