How to use @turf/bbox-clip - 7 common examples

To help you get started, we’ve selected a few @turf/bbox-clip 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 openstreetmap / iD / modules / services / vector_tile.js View on Github external
var layer = vectorTile.layers[layerID];
        if (layer) {
            for (var i = 0; i < layer.length; i++) {
                var feature = layer.feature(i).toGeoJSON(tile.xyz[0], tile.xyz[1], tile.xyz[2]);
                var geometry = feature.geometry;

                // Treat all Polygons as MultiPolygons
                if (geometry.type === 'Polygon') {
                    geometry.type = 'MultiPolygon';
                    geometry.coordinates = [geometry.coordinates];
                }

                // Clip to tile bounds
                if (geometry.type === 'MultiPolygon') {
                    var isClipped = false;
                    var featureClip = turf_bboxClip(feature, tile.extent.rectangle());
                    if (!deepEqual(feature.geometry, featureClip.geometry)) {
                        // feature = featureClip;
                        isClipped = true;
                    }
                    if (!feature.geometry.coordinates.length) continue;   // not actually on this tile
                    if (!feature.geometry.coordinates[0].length) continue;   // not actually on this tile
                }

                // Generate some unique IDs and add some metadata
                var featurehash = utilHashcode(stringify(feature));
                var propertyhash = utilHashcode(stringify(feature.properties || {}));
                feature.__layerID__ = layerID.replace(/[^_a-zA-Z0-9\-]/g, '_');
                feature.__featurehash__ = featurehash;
                feature.__propertyhash__ = propertyhash;
                features.push(feature);
github kepta / idly / packages / idly-gl / src / helpers / helpers.ts View on Github external
.map(tile => {
      const tilePolygon = bboxPolygon(mercator.bbox(tile.x, tile.y, tile.z));
      const tileInsideBbox = bboxClip(tilePolygon, viewportBbox);

      const fractionVisible =
        area(tileInsideBbox) / area(bboxPolygon(viewportBbox));

      return { fractionVisible, tile };
    })
    .sort((a, b) => b.fractionVisible - a.fractionVisible)
github kepta / idly / packages / idly-gl / src / helpers / helpers.ts View on Github external
.map(tile => {
      const tilePolygon = bboxPolygon(mercator.bbox(tile.x, tile.y, tile.z));
      const tileInsideBbox = bboxClip(tilePolygon, viewportBbox);

      const fractionVisible =
        area(tileInsideBbox) / area(bboxPolygon(viewportBbox));

      return { fractionVisible, tile };
    })
    .sort((a, b) => b.fractionVisible - a.fractionVisible)
github kepta / idly / packages / idly-worker / src / misc / filterXYZ.ts View on Github external
return xyzs.filter(tile => {
    const secPoly = bboxPolygon(mercator.bbox(tile.x, tile.y, tile.z));
    const inter = bboxClip(secPoly, bbox);
    return area(inter) / area(secPoly) >= ratio;
  });
}
github omnisci / mapd-charting / src / charts / geo-choropleth-chart.js View on Github external
const data = geoJson(layerIndex).data.map(feature =>
        turfBboxClip(feature, [
          _chart.lonMin(),
          _chart.latMin(),
          _chart.lonMax(),
          _chart.latMax()
        ])
      )

@turf/bbox-clip

turf bbox-clip module

MIT
Latest version published 2 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/bbox-clip functions