@turf/buffer 7.2.0 → 7.3.1

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## buffer
6
6
 
7
- Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees.
7
+ Calculates a buffer for input features for a given radius.
8
8
 
9
9
  When using a negative radius, the resulting geometry may be invalid if
10
10
  it's too small compared to the radius magnitude. If the input is a
@@ -18,7 +18,7 @@ the input, or even be empty.
18
18
  * `radius` **[number][4]** distance to draw the buffer (negative values are allowed)
19
19
  * `options` **[Object][5]** Optional parameters (optional, default `{}`)
20
20
 
21
- * `options.units` **[string][6]** any of the options supported by turf units (optional, default `"kilometers"`)
21
+ * `options.units` **Units** Supports all valid Turf [Units][6]. (optional, default `"kilometers"`)
22
22
  * `options.steps` **[number][4]** number of steps (optional, default `8`)
23
23
 
24
24
  ### Examples
@@ -43,7 +43,7 @@ Returns **([FeatureCollection][1] | [Feature][3]<([Polygon][7] | [MultiPolygon][
43
43
 
44
44
  [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
45
45
 
46
- [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
46
+ [6]: https://turfjs.org/docs/api/types/Units
47
47
 
48
48
  [7]: https://tools.ietf.org/html/rfc7946#section-3.1.6
49
49
 
@@ -91,9 +91,9 @@ function defineProjection(geojson) {
91
91
  var rotation = [-coords[0], -coords[1]];
92
92
  return _d3geo.geoAzimuthalEquidistant.call(void 0, ).rotate(rotation).scale(_helpers.earthRadius);
93
93
  }
94
- var turf_buffer_default = buffer;
94
+ var index_default = buffer;
95
95
 
96
96
 
97
97
 
98
- exports.buffer = buffer; exports.default = turf_buffer_default;
98
+ exports.buffer = buffer; exports.default = index_default;
99
99
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/turf/turf/packages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aAAA,CAAc,MAAA,EAAQ,IAAA,EAAM;AACnC,EAAA,GAAA,CAAI,OAAO,MAAA,CAAO,CAAC,EAAA,IAAM,QAAA,EAAU,OAAO,IAAA,CAAK,MAAM,CAAA;AACrD,EAAA,OAAO,MAAA,CAAO,GAAA,CAAI,QAAA,CAAU,KAAA,EAAO;AACjC,IAAA,OAAO,aAAA,CAAc,KAAA,EAAO,IAAI,CAAA;AAAA,EAClC,CAAC,CAAA;AACH;AAUA,SAAS,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM;AACrC,EAAA,GAAA,CAAI,OAAO,MAAA,CAAO,CAAC,EAAA,IAAM,QAAA,EAAU,OAAO,IAAA,CAAK,MAAA,CAAO,MAAM,CAAA;AAC5D,EAAA,OAAO,MAAA,CAAO,GAAA,CAAI,QAAA,CAAU,KAAA,EAAO;AACjC,IAAA,OAAO,eAAA,CAAgB,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"]}
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,CAAA;AACnD,EAAA,GAAA,CAAI,OAAO,QAAA,IAAY,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,2BAA2B,CAAA;AAC5E,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,yBAAyB,CAAA;AAGxE,EAAA,GAAA,CAAI,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AAO,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,cAAA,EAAQ,MAAA;ADzFf;AACE;AACA;AACF,yDAAC","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.\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 {Units} [options.units=\"kilometers\"] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units 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 {Units} [units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units 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
@@ -91,9 +91,9 @@ function defineProjection(geojson) {
91
91
  var rotation = [-coords[0], -coords[1]];
92
92
  return geoAzimuthalEquidistant().rotate(rotation).scale(earthRadius);
93
93
  }
94
- var turf_buffer_default = buffer;
94
+ var index_default = buffer;
95
95
  export {
96
96
  buffer,
97
- turf_buffer_default as default
97
+ index_default as default
98
98
  };
99
99
  //# sourceMappingURL=index.js.map
@@ -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 * @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,SAAS,QAAQ,SAAS;AAExC,YAAU,WAAW,CAAC;AAGtB,MAAI,QAAQ,QAAQ,SAAS;AAC7B,MAAI,QAAQ,QAAQ,SAAS;AAG7B,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,OAAO,YAAY,SAAU,OAAM,IAAI,MAAM,2BAA2B;AAC5E,MAAI,OAAO,UAAU,SAAU,OAAM,IAAI,MAAM,yBAAyB;AAGxE,MAAI,WAAW,OAAW,OAAM,IAAI,MAAM,oBAAoB;AAC9D,MAAI,SAAS,EAAG,OAAM,IAAI,MAAM,8BAA8B;A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tD,MAAI,SAAS,IAAI,cAAc;AAC/B,aAAW,OAAO,MAAM,QAAQ;AAGhC,MAAI,YAAY,SAAS,WAAW,EAAG,QAAO;AAG9C,MAAI,SAAS;AAAA,IACX,MAAM,SAAS;AAAA,IACf,aAAa,gBAAgB,SAAS,aAAa,UAAU;AAAA,EAC/D;AAEA,SAAO,QAAQ,QAAQ,UAAU;AACnC;AASA,SAAS,YAAY,QAAQ;AAC3B,MAAI,MAAM,QAAQ,OAAO,CAAC,CAAC,EAAG,QAAO,YAAY,OAAO,CAAC,CAAC;AAC1D,SAAO,MAAM,OAAO,CAAC,CAAC;AACxB;AAUA,SAAS,cAAc,QAAQ,MAAM;AACnC,MAAI,OAAO,OAAO,CAAC,MAAM,SAAU,QAAO,KAAK,MAAM;AACrD,SAAO,OAAO,IAAI,SAAU,OAAO;AACjC,WAAO,cAAc,OAAO,IAAI;AAAA,EAClC,CAAC;AACH;AAUA,SAAS,gBAAgB,QAAQ,MAAM;AACrC,MAAI,OAAO,OAAO,CAAC,MAAM,SAAU,QAAO,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.\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 {Units} [options.units=\"kilometers\"] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units 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 {Units} [units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units 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,SAAS,QAAQ,SAAS;AAExC,YAAU,WAAW,CAAC;AAGtB,MAAI,QAAQ,QAAQ,SAAS;AAC7B,MAAI,QAAQ,QAAQ,SAAS;AAG7B,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,OAAO,YAAY,SAAU,OAAM,IAAI,MAAM,2BAA2B;AAC5E,MAAI,OAAO,UAAU,SAAU,OAAM,IAAI,MAAM,yBAAyB;AAGxE,MAAI,WAAW,OAAW,OAAM,IAAI,MAAM,oBAAoB;AAC9D,MAAI,SAAS,EAAG,OAAM,IAAI,MAAM,8BAA8B;AAE9D,MAAI,UAAU,CAAC;AACf,UAAQ,QAAQ,MAAM;AAAA,IACpB,KAAK;AACH,eAAS,SAAS,SAAU,UAAU;AACpC,YAAI,WAAW,cAAc,UAAU,QAAQ,OAAO,KAAK;AAC3D,YAAI,SAAU,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AAgB,SAAS,aAAa,UAAU;AAAA,EAC/D;AAEA,SAAO,QAAQ,QAAQ,UAAU;AACnC;AASA,SAAS,YAAY,QAAQ;AAC3B,MAAI,MAAM,QAAQ,OAAO,CAAC,CAAC,EAAG,QAAO,YAAY,OAAO,CAAC,CAAC;AAC1D,SAAO,MAAM,OAAO,CAAC,CAAC;AACxB;AAUA,SAAS,cAAc,QAAQ,MAAM;AACnC,MAAI,OAAO,OAAO,CAAC,MAAM,SAAU,QAAO,KAAK,MAAM;AACrD,SAAO,OAAO,IAAI,SAAU,OAAO;AACjC,WAAO,cAAc,OAAO,IAAI;AAAA,EAClC,CAAC;AACH;AAUA,SAAS,gBAAgB,QAAQ,MAAM;AACrC,MAAI,OAAO,OAAO,CAAC,MAAM,SAAU,QAAO,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,gBAAQ;","names":["feature","geometry","buffered"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/buffer",
3
- "version": "7.2.0",
4
- "description": "turf buffer module",
3
+ "version": "7.3.1",
4
+ "description": "Creates a buffer around a GeoJSON feature.",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
7
7
  "Tom MacWright <@tmcw>",
@@ -55,31 +55,30 @@
55
55
  "bench": "tsx bench.ts",
56
56
  "build": "tsup --config ../../tsup.config.ts",
57
57
  "docs": "tsx ../../scripts/generate-readmes.ts",
58
- "test": "npm-run-all --npm-path npm test:*",
58
+ "test": "pnpm run /test:.*/",
59
59
  "test:tape": "tsx test.ts",
60
60
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
61
61
  },
62
62
  "devDependencies": {
63
- "@turf/truncate": "^7.2.0",
63
+ "@turf/truncate": "7.3.1",
64
64
  "@types/benchmark": "^2.1.5",
65
- "@types/tape": "^4.13.4",
65
+ "@types/tape": "^5.8.1",
66
66
  "benchmark": "^2.1.4",
67
67
  "load-json-file": "^7.0.1",
68
- "npm-run-all": "^4.1.5",
69
68
  "tape": "^5.9.0",
70
- "tsup": "^8.3.5",
71
- "tsx": "^4.19.2",
72
- "write-json-file": "^5.0.0"
69
+ "tsup": "^8.4.0",
70
+ "tsx": "^4.19.4",
71
+ "write-json-file": "^6.0.0"
73
72
  },
74
73
  "dependencies": {
75
- "@turf/bbox": "^7.2.0",
76
- "@turf/center": "^7.2.0",
77
- "@turf/helpers": "^7.2.0",
74
+ "@turf/bbox": "7.3.1",
75
+ "@turf/center": "7.3.1",
76
+ "@turf/helpers": "7.3.1",
78
77
  "@turf/jsts": "^2.7.1",
79
- "@turf/meta": "^7.2.0",
80
- "@turf/projection": "^7.2.0",
78
+ "@turf/meta": "7.3.1",
79
+ "@turf/projection": "7.3.1",
81
80
  "@types/geojson": "^7946.0.10",
82
81
  "d3-geo": "1.7.1"
83
82
  },
84
- "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
83
+ "gitHead": "b7f1b4eafb760431e03955499d8eac9489438219"
85
84
  }