@turf/buffer 7.1.0 → 7.2.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.
@@ -15,23 +15,17 @@ function buffer(geojson, radius, options) {
15
15
  options = options || {};
16
16
  var units = options.units || "kilometers";
17
17
  var steps = options.steps || 8;
18
- if (!geojson)
19
- throw new Error("geojson is required");
20
- if (typeof options !== "object")
21
- throw new Error("options must be an object");
22
- if (typeof steps !== "number")
23
- throw new Error("steps must be an number");
24
- if (radius === void 0)
25
- throw new Error("radius is required");
26
- if (steps <= 0)
27
- throw new Error("steps must be greater than 0");
18
+ if (!geojson) throw new Error("geojson is required");
19
+ if (typeof options !== "object") throw new Error("options must be an object");
20
+ if (typeof steps !== "number") throw new Error("steps must be an number");
21
+ if (radius === void 0) throw new Error("radius is required");
22
+ if (steps <= 0) throw new Error("steps must be greater than 0");
28
23
  var results = [];
29
24
  switch (geojson.type) {
30
25
  case "GeometryCollection":
31
26
  _meta.geomEach.call(void 0, geojson, function(geometry) {
32
27
  var buffered = bufferFeature(geometry, radius, units, steps);
33
- if (buffered)
34
- results.push(buffered);
28
+ if (buffered) results.push(buffered);
35
29
  });
36
30
  return _helpers.featureCollection.call(void 0, results);
37
31
  case "FeatureCollection":
@@ -39,8 +33,7 @@ function buffer(geojson, radius, options) {
39
33
  var multiBuffered = bufferFeature(feature2, radius, units, steps);
40
34
  if (multiBuffered) {
41
35
  _meta.featureEach.call(void 0, multiBuffered, function(buffered) {
42
- if (buffered)
43
- results.push(buffered);
36
+ if (buffered) results.push(buffered);
44
37
  });
45
38
  }
46
39
  });
@@ -55,8 +48,7 @@ function bufferFeature(geojson, radius, units, steps) {
55
48
  var results = [];
56
49
  _meta.geomEach.call(void 0, geojson, function(geometry2) {
57
50
  var buffered2 = bufferFeature(geometry2, radius, units, steps);
58
- if (buffered2)
59
- results.push(buffered2);
51
+ if (buffered2) results.push(buffered2);
60
52
  });
61
53
  return _helpers.featureCollection.call(void 0, results);
62
54
  }
@@ -71,8 +63,7 @@ function bufferFeature(geojson, radius, units, steps) {
71
63
  var buffered = BufferOp.bufferOp(geom, distance, steps);
72
64
  var writer = new GeoJSONWriter();
73
65
  buffered = writer.write(buffered);
74
- if (coordsIsNaN(buffered.coordinates))
75
- return void 0;
66
+ if (coordsIsNaN(buffered.coordinates)) return void 0;
76
67
  var result = {
77
68
  type: buffered.type,
78
69
  coordinates: unprojectCoords(buffered.coordinates, projection)
@@ -80,20 +71,17 @@ function bufferFeature(geojson, radius, units, steps) {
80
71
  return _helpers.feature.call(void 0, result, properties);
81
72
  }
82
73
  function coordsIsNaN(coords) {
83
- if (Array.isArray(coords[0]))
84
- return coordsIsNaN(coords[0]);
74
+ if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]);
85
75
  return isNaN(coords[0]);
86
76
  }
87
77
  function projectCoords(coords, proj) {
88
- if (typeof coords[0] !== "object")
89
- return proj(coords);
78
+ if (typeof coords[0] !== "object") return proj(coords);
90
79
  return coords.map(function(coord) {
91
80
  return projectCoords(coord, proj);
92
81
  });
93
82
  }
94
83
  function unprojectCoords(coords, proj) {
95
- if (typeof coords[0] !== "object")
96
- return proj.invert(coords);
84
+ if (typeof coords[0] !== "object") return proj.invert(coords);
97
85
  return coords.map(function(coord) {
98
86
  return unprojectCoords(coord, proj);
99
87
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.js"],"names":["feature","geometry","buffered"],"mappings":";AAAA,SAAS,cAAc;AACvB,OAAO,UAAU;AACjB,SAAS,UAAU,mBAAmB;AACtC,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,EAAE,UAAU,eAAe,cAAc,IAAI;AAyBnD,SAAS,OAAO,SAAS,QAAQ,SAAS;AAExC,YAAU,WAAW,CAAC;AAGtB,MAAI,QAAQ,QAAQ,SAAS;AAC7B,MAAI,QAAQ,QAAQ,SAAS;AAG7B,MA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GA,IAAO,sBAAQ","sourcesContent":["import { center } from \"@turf/center\";\nimport jsts from \"@turf/jsts\";\nimport { geomEach, featureEach } from \"@turf/meta\";\nimport { geoAzimuthalEquidistant } from \"d3-geo\";\nimport {\n feature,\n featureCollection,\n radiansToLength,\n lengthToRadians,\n earthRadius,\n} from \"@turf/helpers\";\n\nconst { BufferOp, GeoJSONReader, GeoJSONWriter } = jsts;\n\n/**\n * Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees.\n *\n * When using a negative radius, the resulting geometry may be invalid if\n * it's too small compared to the radius magnitude. If the input is a\n * FeatureCollection, only valid members will be returned in the output\n * FeatureCollection - i.e., the output collection may have fewer members than\n * the input, or even be empty.\n *\n * @name buffer\n * @param {FeatureCollection|Geometry|Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer (negative values are allowed)\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=\"kilometers\"] any of the options supported by turf units\n * @param {number} [options.steps=8] number of steps\n * @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} buffered features\n * @example\n * var point = turf.point([-90.548630, 14.616599]);\n * var buffered = turf.buffer(point, 500, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [point, buffered]\n */\nfunction buffer(geojson, radius, options) {\n // Optional params\n options = options || {};\n\n // use user supplied options or default values\n var units = options.units || \"kilometers\";\n var steps = options.steps || 8;\n\n // validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (typeof options !== \"object\") throw new Error(\"options must be an object\");\n if (typeof steps !== \"number\") throw new Error(\"steps must be an number\");\n\n // Allow negative buffers (\"erosion\") or zero-sized buffers (\"repair geometry\")\n if (radius === undefined) throw new Error(\"radius is required\");\n if (steps <= 0) throw new Error(\"steps must be greater than 0\");\n\n var results = [];\n switch (geojson.type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n case \"FeatureCollection\":\n featureEach(geojson, function (feature) {\n var multiBuffered = bufferFeature(feature, radius, units, steps);\n if (multiBuffered) {\n featureEach(multiBuffered, function (buffered) {\n if (buffered) results.push(buffered);\n });\n }\n });\n return featureCollection(results);\n }\n return bufferFeature(geojson, radius, units, steps);\n}\n\n/**\n * Buffer single Feature/Geometry\n *\n * @private\n * @param {Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer\n * @param {string} [units='kilometers'] any of the options supported by turf units\n * @param {number} [steps=8] number of steps\n * @returns {Feature<Polygon|MultiPolygon>} buffered feature\n */\nfunction bufferFeature(geojson, radius, units, steps) {\n var properties = geojson.properties || {};\n var geometry = geojson.type === \"Feature\" ? geojson.geometry : geojson;\n\n // Geometry Types faster than jsts\n if (geometry.type === \"GeometryCollection\") {\n var results = [];\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n }\n\n // Project GeoJSON to Azimuthal Equidistant projection (convert to Meters)\n var projection = defineProjection(geometry);\n var projected = {\n type: geometry.type,\n coordinates: projectCoords(geometry.coordinates, projection),\n };\n\n // JSTS buffer operation\n var reader = new GeoJSONReader();\n var geom = reader.read(projected);\n var distance = radiansToLength(lengthToRadians(radius, units), \"meters\");\n var buffered = BufferOp.bufferOp(geom, distance, steps);\n var writer = new GeoJSONWriter();\n buffered = writer.write(buffered);\n\n // Detect if empty geometries\n if (coordsIsNaN(buffered.coordinates)) return undefined;\n\n // Unproject coordinates (convert to Degrees)\n var result = {\n type: buffered.type,\n coordinates: unprojectCoords(buffered.coordinates, projection),\n };\n\n return feature(result, properties);\n}\n\n/**\n * Coordinates isNaN\n *\n * @private\n * @param {Array<any>} coords GeoJSON Coordinates\n * @returns {boolean} if NaN exists\n */\nfunction coordsIsNaN(coords) {\n if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]);\n return isNaN(coords[0]);\n}\n\n/**\n * Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} projected coordinates\n */\nfunction projectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj(coords);\n return coords.map(function (coord) {\n return projectCoords(coord, proj);\n });\n}\n\n/**\n * Un-Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to un-project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} un-projected coordinates\n */\nfunction unprojectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj.invert(coords);\n return coords.map(function (coord) {\n return unprojectCoords(coord, proj);\n });\n}\n\n/**\n * Define Azimuthal Equidistant projection\n *\n * @private\n * @param {Geometry|Feature<any>} geojson Base projection on center of GeoJSON\n * @returns {GeoProjection} D3 Geo Azimuthal Equidistant Projection\n */\nfunction defineProjection(geojson) {\n var coords = center(geojson).geometry.coordinates;\n var rotation = [-coords[0], -coords[1]];\n return geoAzimuthalEquidistant().rotate(rotation).scale(earthRadius);\n}\n\nexport { buffer };\nexport default buffer;\n"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-buffer/dist/cjs/index.cjs","../../index.js"],"names":["feature","geometry","buffered"],"mappings":"AAAA;ACAA,sCAAuB;AACvB,8EAAiB;AACjB,kCAAsC;AACtC,+BAAwC;AACxC;AACE;AACA;AACA;AACA;AACA;AAAA,wCACK;AAEP,IAAM,EAAE,QAAA,EAAU,aAAA,EAAe,cAAc,EAAA,EAAI,cAAA;AAyBnD,SAAS,MAAA,CAAO,OAAA,EAAS,MAAA,EAAQ,OAAA,EAAS;AAExC,EAAA,QAAA,EAAU,QAAA,GAAW,CAAC,CAAA;AAGtB,EAAA,IAAI,MAAA,EAAQ,OAAA,CAAQ,MAAA,GAAS,YAAA;AAC7B,EAAA,IAAI,MAAA,EAAQ,OAAA,CAAQ,MAAA,GAAS,CAAA;AAG7B,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,qBAAqB,CA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B,KAAA,EAAO,IAAI,CAAA;AAAA,EACpC,CAAC,CAAA;AACH;AASA,SAAS,gBAAA,CAAiB,OAAA,EAAS;AACjC,EAAA,IAAI,OAAA,EAAS,4BAAA,OAAc,CAAA,CAAE,QAAA,CAAS,WAAA;AACtC,EAAA,IAAI,SAAA,EAAW,CAAC,CAAC,MAAA,CAAO,CAAC,CAAA,EAAG,CAAC,MAAA,CAAO,CAAC,CAAC,CAAA;AACtC,EAAA,OAAO,4CAAA,CAAwB,CAAE,MAAA,CAAO,QAAQ,CAAA,CAAE,KAAA,CAAM,oBAAW,CAAA;AACrE;AAGA,IAAO,oBAAA,EAAQ,MAAA;ADzFf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-buffer/dist/cjs/index.cjs","sourcesContent":[null,"import { center } from \"@turf/center\";\nimport jsts from \"@turf/jsts\";\nimport { geomEach, featureEach } from \"@turf/meta\";\nimport { geoAzimuthalEquidistant } from \"d3-geo\";\nimport {\n feature,\n featureCollection,\n radiansToLength,\n lengthToRadians,\n earthRadius,\n} from \"@turf/helpers\";\n\nconst { BufferOp, GeoJSONReader, GeoJSONWriter } = jsts;\n\n/**\n * Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees.\n *\n * When using a negative radius, the resulting geometry may be invalid if\n * it's too small compared to the radius magnitude. If the input is a\n * FeatureCollection, only valid members will be returned in the output\n * FeatureCollection - i.e., the output collection may have fewer members than\n * the input, or even be empty.\n *\n * @function\n * @param {FeatureCollection|Geometry|Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer (negative values are allowed)\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=\"kilometers\"] any of the options supported by turf units\n * @param {number} [options.steps=8] number of steps\n * @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} buffered features\n * @example\n * var point = turf.point([-90.548630, 14.616599]);\n * var buffered = turf.buffer(point, 500, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [point, buffered]\n */\nfunction buffer(geojson, radius, options) {\n // Optional params\n options = options || {};\n\n // use user supplied options or default values\n var units = options.units || \"kilometers\";\n var steps = options.steps || 8;\n\n // validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (typeof options !== \"object\") throw new Error(\"options must be an object\");\n if (typeof steps !== \"number\") throw new Error(\"steps must be an number\");\n\n // Allow negative buffers (\"erosion\") or zero-sized buffers (\"repair geometry\")\n if (radius === undefined) throw new Error(\"radius is required\");\n if (steps <= 0) throw new Error(\"steps must be greater than 0\");\n\n var results = [];\n switch (geojson.type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n case \"FeatureCollection\":\n featureEach(geojson, function (feature) {\n var multiBuffered = bufferFeature(feature, radius, units, steps);\n if (multiBuffered) {\n featureEach(multiBuffered, function (buffered) {\n if (buffered) results.push(buffered);\n });\n }\n });\n return featureCollection(results);\n }\n return bufferFeature(geojson, radius, units, steps);\n}\n\n/**\n * Buffer single Feature/Geometry\n *\n * @private\n * @param {Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer\n * @param {string} [units='kilometers'] any of the options supported by turf units\n * @param {number} [steps=8] number of steps\n * @returns {Feature<Polygon|MultiPolygon>} buffered feature\n */\nfunction bufferFeature(geojson, radius, units, steps) {\n var properties = geojson.properties || {};\n var geometry = geojson.type === \"Feature\" ? geojson.geometry : geojson;\n\n // Geometry Types faster than jsts\n if (geometry.type === \"GeometryCollection\") {\n var results = [];\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n }\n\n // Project GeoJSON to Azimuthal Equidistant projection (convert to Meters)\n var projection = defineProjection(geometry);\n var projected = {\n type: geometry.type,\n coordinates: projectCoords(geometry.coordinates, projection),\n };\n\n // JSTS buffer operation\n var reader = new GeoJSONReader();\n var geom = reader.read(projected);\n var distance = radiansToLength(lengthToRadians(radius, units), \"meters\");\n var buffered = BufferOp.bufferOp(geom, distance, steps);\n var writer = new GeoJSONWriter();\n buffered = writer.write(buffered);\n\n // Detect if empty geometries\n if (coordsIsNaN(buffered.coordinates)) return undefined;\n\n // Unproject coordinates (convert to Degrees)\n var result = {\n type: buffered.type,\n coordinates: unprojectCoords(buffered.coordinates, projection),\n };\n\n return feature(result, properties);\n}\n\n/**\n * Coordinates isNaN\n *\n * @private\n * @param {Array<any>} coords GeoJSON Coordinates\n * @returns {boolean} if NaN exists\n */\nfunction coordsIsNaN(coords) {\n if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]);\n return isNaN(coords[0]);\n}\n\n/**\n * Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} projected coordinates\n */\nfunction projectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj(coords);\n return coords.map(function (coord) {\n return projectCoords(coord, proj);\n });\n}\n\n/**\n * Un-Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to un-project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} un-projected coordinates\n */\nfunction unprojectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj.invert(coords);\n return coords.map(function (coord) {\n return unprojectCoords(coord, proj);\n });\n}\n\n/**\n * Define Azimuthal Equidistant projection\n *\n * @private\n * @param {Geometry|Feature<any>} geojson Base projection on center of GeoJSON\n * @returns {GeoProjection} D3 Geo Azimuthal Equidistant Projection\n */\nfunction defineProjection(geojson) {\n var coords = center(geojson).geometry.coordinates;\n var rotation = [-coords[0], -coords[1]];\n return geoAzimuthalEquidistant().rotate(rotation).scale(earthRadius);\n}\n\nexport { buffer };\nexport default buffer;\n"]}
package/dist/esm/index.js CHANGED
@@ -15,23 +15,17 @@ function buffer(geojson, radius, options) {
15
15
  options = options || {};
16
16
  var units = options.units || "kilometers";
17
17
  var steps = options.steps || 8;
18
- if (!geojson)
19
- throw new Error("geojson is required");
20
- if (typeof options !== "object")
21
- throw new Error("options must be an object");
22
- if (typeof steps !== "number")
23
- throw new Error("steps must be an number");
24
- if (radius === void 0)
25
- throw new Error("radius is required");
26
- if (steps <= 0)
27
- throw new Error("steps must be greater than 0");
18
+ if (!geojson) throw new Error("geojson is required");
19
+ if (typeof options !== "object") throw new Error("options must be an object");
20
+ if (typeof steps !== "number") throw new Error("steps must be an number");
21
+ if (radius === void 0) throw new Error("radius is required");
22
+ if (steps <= 0) throw new Error("steps must be greater than 0");
28
23
  var results = [];
29
24
  switch (geojson.type) {
30
25
  case "GeometryCollection":
31
26
  geomEach(geojson, function(geometry) {
32
27
  var buffered = bufferFeature(geometry, radius, units, steps);
33
- if (buffered)
34
- results.push(buffered);
28
+ if (buffered) results.push(buffered);
35
29
  });
36
30
  return featureCollection(results);
37
31
  case "FeatureCollection":
@@ -39,8 +33,7 @@ function buffer(geojson, radius, options) {
39
33
  var multiBuffered = bufferFeature(feature2, radius, units, steps);
40
34
  if (multiBuffered) {
41
35
  featureEach(multiBuffered, function(buffered) {
42
- if (buffered)
43
- results.push(buffered);
36
+ if (buffered) results.push(buffered);
44
37
  });
45
38
  }
46
39
  });
@@ -55,8 +48,7 @@ function bufferFeature(geojson, radius, units, steps) {
55
48
  var results = [];
56
49
  geomEach(geojson, function(geometry2) {
57
50
  var buffered2 = bufferFeature(geometry2, radius, units, steps);
58
- if (buffered2)
59
- results.push(buffered2);
51
+ if (buffered2) results.push(buffered2);
60
52
  });
61
53
  return featureCollection(results);
62
54
  }
@@ -71,8 +63,7 @@ function bufferFeature(geojson, radius, units, steps) {
71
63
  var buffered = BufferOp.bufferOp(geom, distance, steps);
72
64
  var writer = new GeoJSONWriter();
73
65
  buffered = writer.write(buffered);
74
- if (coordsIsNaN(buffered.coordinates))
75
- return void 0;
66
+ if (coordsIsNaN(buffered.coordinates)) return void 0;
76
67
  var result = {
77
68
  type: buffered.type,
78
69
  coordinates: unprojectCoords(buffered.coordinates, projection)
@@ -80,20 +71,17 @@ function bufferFeature(geojson, radius, units, steps) {
80
71
  return feature(result, properties);
81
72
  }
82
73
  function coordsIsNaN(coords) {
83
- if (Array.isArray(coords[0]))
84
- return coordsIsNaN(coords[0]);
74
+ if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]);
85
75
  return isNaN(coords[0]);
86
76
  }
87
77
  function projectCoords(coords, proj) {
88
- if (typeof coords[0] !== "object")
89
- return proj(coords);
78
+ if (typeof coords[0] !== "object") return proj(coords);
90
79
  return coords.map(function(coord) {
91
80
  return projectCoords(coord, proj);
92
81
  });
93
82
  }
94
83
  function unprojectCoords(coords, proj) {
95
- if (typeof coords[0] !== "object")
96
- return proj.invert(coords);
84
+ if (typeof coords[0] !== "object") return proj.invert(coords);
97
85
  return coords.map(function(coord) {
98
86
  return unprojectCoords(coord, proj);
99
87
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.js"],"sourcesContent":["import { center } from \"@turf/center\";\nimport jsts from \"@turf/jsts\";\nimport { geomEach, featureEach } from \"@turf/meta\";\nimport { geoAzimuthalEquidistant } from \"d3-geo\";\nimport {\n feature,\n featureCollection,\n radiansToLength,\n lengthToRadians,\n earthRadius,\n} from \"@turf/helpers\";\n\nconst { BufferOp, GeoJSONReader, GeoJSONWriter } = jsts;\n\n/**\n * Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees.\n *\n * When using a negative radius, the resulting geometry may be invalid if\n * it's too small compared to the radius magnitude. If the input is a\n * FeatureCollection, only valid members will be returned in the output\n * FeatureCollection - i.e., the output collection may have fewer members than\n * the input, or even be empty.\n *\n * @name buffer\n * @param {FeatureCollection|Geometry|Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer (negative values are allowed)\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=\"kilometers\"] any of the options supported by turf units\n * @param {number} [options.steps=8] number of steps\n * @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} buffered features\n * @example\n * var point = turf.point([-90.548630, 14.616599]);\n * var buffered = turf.buffer(point, 500, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [point, buffered]\n */\nfunction buffer(geojson, radius, options) {\n // Optional params\n options = options || {};\n\n // use user supplied options or default values\n var units = options.units || \"kilometers\";\n var steps = options.steps || 8;\n\n // validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (typeof options !== \"object\") throw new Error(\"options must be an object\");\n if (typeof steps !== \"number\") throw new Error(\"steps must be an number\");\n\n // Allow negative buffers (\"erosion\") or zero-sized buffers (\"repair geometry\")\n if (radius === undefined) throw new Error(\"radius is required\");\n if (steps <= 0) throw new Error(\"steps must be greater than 0\");\n\n var results = [];\n switch (geojson.type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n case \"FeatureCollection\":\n featureEach(geojson, function (feature) {\n var multiBuffered = bufferFeature(feature, radius, units, steps);\n if (multiBuffered) {\n featureEach(multiBuffered, function (buffered) {\n if (buffered) results.push(buffered);\n });\n }\n });\n return featureCollection(results);\n }\n return bufferFeature(geojson, radius, units, steps);\n}\n\n/**\n * Buffer single Feature/Geometry\n *\n * @private\n * @param {Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer\n * @param {string} [units='kilometers'] any of the options supported by turf units\n * @param {number} [steps=8] number of steps\n * @returns {Feature<Polygon|MultiPolygon>} buffered feature\n */\nfunction bufferFeature(geojson, radius, units, steps) {\n var properties = geojson.properties || {};\n var geometry = geojson.type === \"Feature\" ? geojson.geometry : geojson;\n\n // Geometry Types faster than jsts\n if (geometry.type === \"GeometryCollection\") {\n var results = [];\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n }\n\n // Project GeoJSON to Azimuthal Equidistant projection (convert to Meters)\n var projection = defineProjection(geometry);\n var projected = {\n type: geometry.type,\n coordinates: projectCoords(geometry.coordinates, projection),\n };\n\n // JSTS buffer operation\n var reader = new GeoJSONReader();\n var geom = reader.read(projected);\n var distance = radiansToLength(lengthToRadians(radius, units), \"meters\");\n var buffered = BufferOp.bufferOp(geom, distance, steps);\n var writer = new GeoJSONWriter();\n buffered = writer.write(buffered);\n\n // Detect if empty geometries\n if (coordsIsNaN(buffered.coordinates)) return undefined;\n\n // Unproject coordinates (convert to Degrees)\n var result = {\n type: buffered.type,\n coordinates: unprojectCoords(buffered.coordinates, projection),\n };\n\n return feature(result, properties);\n}\n\n/**\n * Coordinates isNaN\n *\n * @private\n * @param {Array<any>} coords GeoJSON Coordinates\n * @returns {boolean} if NaN exists\n */\nfunction coordsIsNaN(coords) {\n if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]);\n return isNaN(coords[0]);\n}\n\n/**\n * Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} projected coordinates\n */\nfunction projectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj(coords);\n return coords.map(function (coord) {\n return projectCoords(coord, proj);\n });\n}\n\n/**\n * Un-Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to un-project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} un-projected coordinates\n */\nfunction unprojectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj.invert(coords);\n return coords.map(function (coord) {\n return unprojectCoords(coord, proj);\n });\n}\n\n/**\n * Define Azimuthal Equidistant projection\n *\n * @private\n * @param {Geometry|Feature<any>} geojson Base projection on center of GeoJSON\n * @returns {GeoProjection} D3 Geo Azimuthal Equidistant Projection\n */\nfunction defineProjection(geojson) {\n var coords = center(geojson).geometry.coordinates;\n var rotation = [-coords[0], -coords[1]];\n return geoAzimuthalEquidistant().rotate(rotation).scale(earthRadius);\n}\n\nexport { buffer };\nexport default buffer;\n"],"mappings":";AAAA,SAAS,cAA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AAO,KAAK,OAAO,MAAM;AAC5D,SAAO,OAAO,IAAI,SAAU,OAAO;AACjC,WAAO,gBAAgB,OAAO,IAAI;AAAA,EACpC,CAAC;AACH;AASA,SAAS,iBAAiB,SAAS;AACjC,MAAI,SAAS,OAAO,OAAO,EAAE,SAAS;AACtC,MAAI,WAAW,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtC,SAAO,wBAAwB,EAAE,OAAO,QAAQ,EAAE,MAAM,WAAW;AACrE;AAGA,IAAO,sBAAQ;","names":["feature","geometry","buffered"]}
1
+ {"version":3,"sources":["../../index.js"],"sourcesContent":["import { center } from \"@turf/center\";\nimport jsts from \"@turf/jsts\";\nimport { geomEach, featureEach } from \"@turf/meta\";\nimport { geoAzimuthalEquidistant } from \"d3-geo\";\nimport {\n feature,\n featureCollection,\n radiansToLength,\n lengthToRadians,\n earthRadius,\n} from \"@turf/helpers\";\n\nconst { BufferOp, GeoJSONReader, GeoJSONWriter } = jsts;\n\n/**\n * Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees.\n *\n * When using a negative radius, the resulting geometry may be invalid if\n * it's too small compared to the radius magnitude. If the input is a\n * FeatureCollection, only valid members will be returned in the output\n * FeatureCollection - i.e., the output collection may have fewer members than\n * the input, or even be empty.\n *\n * @function\n * @param {FeatureCollection|Geometry|Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer (negative values are allowed)\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=\"kilometers\"] any of the options supported by turf units\n * @param {number} [options.steps=8] number of steps\n * @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} buffered features\n * @example\n * var point = turf.point([-90.548630, 14.616599]);\n * var buffered = turf.buffer(point, 500, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [point, buffered]\n */\nfunction buffer(geojson, radius, options) {\n // Optional params\n options = options || {};\n\n // use user supplied options or default values\n var units = options.units || \"kilometers\";\n var steps = options.steps || 8;\n\n // validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (typeof options !== \"object\") throw new Error(\"options must be an object\");\n if (typeof steps !== \"number\") throw new Error(\"steps must be an number\");\n\n // Allow negative buffers (\"erosion\") or zero-sized buffers (\"repair geometry\")\n if (radius === undefined) throw new Error(\"radius is required\");\n if (steps <= 0) throw new Error(\"steps must be greater than 0\");\n\n var results = [];\n switch (geojson.type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n case \"FeatureCollection\":\n featureEach(geojson, function (feature) {\n var multiBuffered = bufferFeature(feature, radius, units, steps);\n if (multiBuffered) {\n featureEach(multiBuffered, function (buffered) {\n if (buffered) results.push(buffered);\n });\n }\n });\n return featureCollection(results);\n }\n return bufferFeature(geojson, radius, units, steps);\n}\n\n/**\n * Buffer single Feature/Geometry\n *\n * @private\n * @param {Feature<any>} geojson input to be buffered\n * @param {number} radius distance to draw the buffer\n * @param {string} [units='kilometers'] any of the options supported by turf units\n * @param {number} [steps=8] number of steps\n * @returns {Feature<Polygon|MultiPolygon>} buffered feature\n */\nfunction bufferFeature(geojson, radius, units, steps) {\n var properties = geojson.properties || {};\n var geometry = geojson.type === \"Feature\" ? geojson.geometry : geojson;\n\n // Geometry Types faster than jsts\n if (geometry.type === \"GeometryCollection\") {\n var results = [];\n geomEach(geojson, function (geometry) {\n var buffered = bufferFeature(geometry, radius, units, steps);\n if (buffered) results.push(buffered);\n });\n return featureCollection(results);\n }\n\n // Project GeoJSON to Azimuthal Equidistant projection (convert to Meters)\n var projection = defineProjection(geometry);\n var projected = {\n type: geometry.type,\n coordinates: projectCoords(geometry.coordinates, projection),\n };\n\n // JSTS buffer operation\n var reader = new GeoJSONReader();\n var geom = reader.read(projected);\n var distance = radiansToLength(lengthToRadians(radius, units), \"meters\");\n var buffered = BufferOp.bufferOp(geom, distance, steps);\n var writer = new GeoJSONWriter();\n buffered = writer.write(buffered);\n\n // Detect if empty geometries\n if (coordsIsNaN(buffered.coordinates)) return undefined;\n\n // Unproject coordinates (convert to Degrees)\n var result = {\n type: buffered.type,\n coordinates: unprojectCoords(buffered.coordinates, projection),\n };\n\n return feature(result, properties);\n}\n\n/**\n * Coordinates isNaN\n *\n * @private\n * @param {Array<any>} coords GeoJSON Coordinates\n * @returns {boolean} if NaN exists\n */\nfunction coordsIsNaN(coords) {\n if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]);\n return isNaN(coords[0]);\n}\n\n/**\n * Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} projected coordinates\n */\nfunction projectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj(coords);\n return coords.map(function (coord) {\n return projectCoords(coord, proj);\n });\n}\n\n/**\n * Un-Project coordinates to projection\n *\n * @private\n * @param {Array<any>} coords to un-project\n * @param {GeoProjection} proj D3 Geo Projection\n * @returns {Array<any>} un-projected coordinates\n */\nfunction unprojectCoords(coords, proj) {\n if (typeof coords[0] !== \"object\") return proj.invert(coords);\n return coords.map(function (coord) {\n return unprojectCoords(coord, proj);\n });\n}\n\n/**\n * Define Azimuthal Equidistant projection\n *\n * @private\n * @param {Geometry|Feature<any>} geojson Base projection on center of GeoJSON\n * @returns {GeoProjection} D3 Geo Azimuthal Equidistant Projection\n */\nfunction defineProjection(geojson) {\n var coords = center(geojson).geometry.coordinates;\n var rotation = [-coords[0], -coords[1]];\n return geoAzimuthalEquidistant().rotate(rotation).scale(earthRadius);\n}\n\nexport { buffer };\nexport default buffer;\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,OAAO,UAAU;AACjB,SAAS,UAAU,mBAAmB;AACtC,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,EAAE,UAAU,eAAe,cAAc,IAAI;AAyBnD,SAAS,OAAO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AC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtC,SAAO,wBAAwB,EAAE,OAAO,QAAQ,EAAE,MAAM,WAAW;AACrE;AAGA,IAAO,sBAAQ;","names":["feature","geometry","buffered"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/buffer",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "turf buffer module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -60,26 +60,26 @@
60
60
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
61
61
  },
62
62
  "devDependencies": {
63
- "@turf/truncate": "^7.1.0",
63
+ "@turf/truncate": "^7.2.0",
64
64
  "@types/benchmark": "^2.1.5",
65
- "@types/tape": "^4.2.32",
65
+ "@types/tape": "^4.13.4",
66
66
  "benchmark": "^2.1.4",
67
67
  "load-json-file": "^7.0.1",
68
68
  "npm-run-all": "^4.1.5",
69
- "tape": "^5.7.2",
70
- "tsup": "^8.0.1",
71
- "tsx": "^4.6.2",
69
+ "tape": "^5.9.0",
70
+ "tsup": "^8.3.5",
71
+ "tsx": "^4.19.2",
72
72
  "write-json-file": "^5.0.0"
73
73
  },
74
74
  "dependencies": {
75
- "@turf/bbox": "^7.1.0",
76
- "@turf/center": "^7.1.0",
77
- "@turf/helpers": "^7.1.0",
75
+ "@turf/bbox": "^7.2.0",
76
+ "@turf/center": "^7.2.0",
77
+ "@turf/helpers": "^7.2.0",
78
78
  "@turf/jsts": "^2.7.1",
79
- "@turf/meta": "^7.1.0",
80
- "@turf/projection": "^7.1.0",
79
+ "@turf/meta": "^7.2.0",
80
+ "@turf/projection": "^7.2.0",
81
81
  "@types/geojson": "^7946.0.10",
82
82
  "d3-geo": "1.7.1"
83
83
  },
84
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
84
+ "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
85
85
  }