How to use the @turf/buffer function in @turf/buffer

To help you get started, we’ve selected a few @turf/buffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapseed / platform / src / base / static / utils / geo.js View on Github external
const getBufferFeature = (placeGeometry, bufferOptions) => {
  try {
    return buffer(placeGeometry, bufferOptions.distance, {
      units: bufferOptions.units,
    });
  } catch (e) {
    // eslint-disable-next-line no-console
    console.error(e);
    Mixpanel.track("Error", {
      message: "unable to perform getBufferFeature",
      error: e,
    });

    return null;
  }
};
github geomoose / gm3 / src / gm3 / jsts.js View on Github external
export function bufferAndUnion(features, meters) {
    let geometry = null;

    for(let i = 0, ii = features.length; i < ii; i++) {
        // buffer the geometry.
        const g = turf_buffer(features[i], meters, {units: 'meters'});

        // if the output geometry is still null, then set the
        //  first member to the new geometry
        if(geometry === null) {
            geometry = g;
        // otherwise buffer it.
        } else {
            geometry = turf_union(geometry, g);
        }
    }

    return geometry.geometry;
}
github uber / nebula.gl / modules / main / src / lib / deck-renderer / deck-drawer.js View on Github external
polygon: selPolygon,
        lineColor: POLYGON_LINE_COLOR,
        fillColor: POLYGON_FILL_COLOR
      });
    } else if (this.usePolygon && this.landPoints.length) {
      data.push({
        polygon: this.landPoints,
        lineColor: POLYGON_LINE_COLOR,
        fillColor: POLYGON_FILL_COLOR
      });

      // Hack: use a polygon to hide the outside, because pickObjects()
      // does not support polygons
      if (this.landPoints.length >= 3) {
        const landPointsPoly = polygon([[...this.landPoints, this.landPoints[0]]]);
        const bigBuffer = turfBuffer(point(this.landPoints[0]), EXPANSION_KM);
        let bigPolygon;
        try {
          // turfDifference throws an exception if the polygon
          // intersects with itself
          bigPolygon = turfDifference(bigBuffer, landPointsPoly);
          dataPick.push({
            polygon: bigPolygon.geometry.coordinates,
            fillColor: [0, 0, 0, 1]
          });
          this.validPolygon = true;
        } catch (e) {
          // invalid selection polygon
          this.validPolygon = false;
        }
      }
    }
github Turfjs / turf / packages / turf-kernel_density / index.js View on Github external
featureEach(output, current => {
        let
            area = buffer(current, sr),
            ptsWithin = pointsWithinPolygon(output, area);
        // the initial value of -1 is on purpose to disregard the point itself.
        current.properties.kernelDensity = featureReduce(ptsWithin, prev => prev + 1, -1);
    });
    return output;
github benjamintd / benmaps.fr / src / components / Map.js View on Github external
moveTo(location, zoom) {
    if (!location) return;
    if (location.bbox) {
      // We have a bbox to fit to
      const distance = turfDistance(
        [location.bbox[0], location.bbox[1]],
        [location.bbox[2], location.bbox[3]]
      );
      const buffered = turfBuffer(
        turfBboxPolygon(location.bbox),
        distance / 2,
        "kilometers"
      );
      const bbox = turfBbox(buffered);
      try {
        this.map.fitBounds(bbox, { linear: true });
      } catch (e) {
        this.map.fitBounds(location.bbox, { linear: true });
      }
    } else {
      // We just have a point
      this.map.easeTo({
        center: location.geometry.coordinates,
        zoom: zoom || 16
      });
github sharedstreets / sharedstreets-js / src / tile_index.ts View on Github external
if(searchType === TileType.GEOMETRY)
            tilePaths.addType(TileType.GEOMETRY);
        else if(searchType === TileType.INTERSECTION)
            tilePaths.addType(TileType.INTERSECTION);
        else 
            throw "invalid search type must be GEOMETRY or INTERSECTION"

        if(additionalTypes) {
            for(var type of additionalTypes) {
                tilePaths.addType(type);
            }
        }

        await this.indexTilesByPathGroup(tilePaths);

        var bufferedPoint:turfHelpers.Feature = buffer(point, searchRadius, {'units':'meters'});
        var data:turfHelpers.FeatureCollection 
        
        if(searchType === TileType.GEOMETRY)
            data = this.geometryIndex.search(bufferedPoint);
        else if(searchType === TileType.INTERSECTION)
            data = this.intersectionIndex.search(bufferedPoint);

        return data;
    
    }
github uber / nebula.gl / modules / main / src / lib / deck-renderer / deck-drawer.js View on Github external
_makeStartPointHighlight(center: [number, number]): number[] {
    const buffer = turfBuffer(point(center), POLYGON_THRESHOLD / 4.0);
    return turfBboxPolygon(turfBbox(buffer)).geometry.coordinates;
  }
github geomoose / gm3 / src / gm3 / jsts.js View on Github external
export function buffer(feature, meters) {
    return turf_buffer(feature, meters, {units: 'meters'}).geometry;
}
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.js View on Github external
static addBuffer(geometry, radius = 0, projection = 'EPSG:3857') {
    if (radius === 0) {
      return geometry;
    }
    const geoJsonFormat = new OlFormatGeoJSON({
      dataProjection: 'EPSG:4326',
      featureProjection: projection
    });
    const geoJson = geometry instanceof OlFeature
      ? geoJsonFormat.writeFeatureObject(geometry)
      : geoJsonFormat.writeGeometryObject(geometry);
    const buffered = buffer(geoJson, radius, {
      units: 'meters'
    });
    if (geometry instanceof OlFeature) {
      return geoJsonFormat.readFeature(buffered);
    } else {
      return geoJsonFormat.readGeometry(buffered.geometry);
    }
  }

@turf/buffer

turf buffer module

MIT
Latest version published 2 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/buffer functions