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

To help you get started, we’ve selected a few @turf/bbox 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 WorldBank-Transport / ram-backend / test / utils / data.js View on Github external
import { getOSRMProfileDefaultSpeedSettings, renderProfileFile } from '../../app/utils/osrm-profile';

function readJSONSync (file) {
  return JSON.parse(fs.readFileSync(file, 'utf8'));
}

const FILE_PROFILE = path.join(__dirname, 'data-sergipe/profile.lua');
const FILE_ORIGINS = path.join(__dirname, 'data-sergipe/villages.geojson');
const FILE_ADMIN = path.join(__dirname, 'data-sergipe/admin-boundaries.geojson');
const FILE_ROAD_NETWORK = path.join(__dirname, 'data-sergipe/road-network.osm');
const FILE_POI = path.join(__dirname, 'data-sergipe/poi-townhalls.geojson');
const FILE_RESULTS_CSV = path.join(__dirname, 'data-sergipe/results-p2000-s2000.csv');
const FILE_RESULTS_JSON = path.join(__dirname, 'data-sergipe/results-p2000-s2000.json');
const FILE_RESULTS_GEOJSON = path.join(__dirname, 'data-sergipe/results-p2000-s2000.geojson');

const ADMIN_AREAS_BBOX = bbox(readJSONSync(FILE_ADMIN));

const FILE_ROAD_NETWORK_SIZE = fs.statSync(FILE_ROAD_NETWORK).size;

// Parse admin areas.
let adminAreas = readJSONSync(FILE_ADMIN);
adminAreas = _(adminAreas.features)
  .filter(o => !!o.properties.name && o.geometry.type !== 'Point')
  .sortBy(o => _.kebabCase(o.properties.name))
  .map(o => {
    return {
      name: o.properties.name,
      type: o.properties.type || 'Admin Area',
      geometry: JSON.stringify(o.geometry.coordinates)
    };
  })
  .value();
github Vizzuality / trase / frontend / scripts / components / tool / map.component.js View on Github external
interactive: !isFilteredOut,
          color,
          weight
        });
        layer.disabled = !layer.feature.properties.hasFlows;
      }

      if (isLinked) {
        linkedPolygons.push(layer.feature);
      }
    });

    if (forceDefaultMapView === true) {
      this.setMapView(defaultMapView);
    } else if (linkedPolygons.length) {
      const bbox = turf_bbox({ type: 'FeatureCollection', features: linkedPolygons });
      // we use L's _getBoundsCenterZoom internal method + setView as fitBounds does not support a minZoom option
      const bounds = L.latLngBounds([[bbox[1], bbox[0]], [bbox[3], bbox[2]]]);
      const boundsCenterZoom = this.map._getBoundsCenterZoom(bounds);
      if (defaultMapView) {
        boundsCenterZoom.zoom = Math.max(boundsCenterZoom.zoom, defaultMapView.zoom);
      }
      this._setMapViewDebounced(boundsCenterZoom.center, boundsCenterZoom.zoom);
    }
  }
github GoogleCloudPlatform / bigquery-geo-viz / src / app / map / map.component.ts View on Github external
updateFeatures() {
    if (!this.map) return;

    this._features = GeoJSONService.rowsToGeoJSON(this._rows, this._geoColumn);

    // Note which types of geometry are being shown.
    this._activeGeometryTypes.clear();
    this._features.forEach((feature) => {
      this._activeGeometryTypes.add(feature.geometry['type']);
    });

    // Fit viewport bounds to the data.
    const [minX, minY, maxX, maxY] = bbox({type: 'FeatureCollection', features: this._features});
    const bounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(minY, minX),
      new google.maps.LatLng(maxY, maxX)
    );
    if (!bounds.isEmpty()) { this.map.fitBounds(bounds); }
  }
github keplergl / kepler.gl / src / layers / geojson-layer / geojson-utils.js View on Github external
export function getGeojsonBounds(features = []) {
  // 70 ms for 10,000 polygons
  // here we only pick couple
  const maxCount = 10000;
  const samples =
    features.length > maxCount ? getSampleData(features, maxCount) : features;

  const nonEmpty = samples.filter(
    d =>
      d && d.geometry && d.geometry.coordinates && d.geometry.coordinates.length
  );

  try {
    return bbox({
      type: 'FeatureCollection',
      features: nonEmpty
    });
  } catch (e) {
    return null;
  }
}
github Turfjs / turf / packages / turf-buffer / index.js View on Github external
var properties = geojson.properties || {};
    var geometry = (geojson.type === 'Feature') ? geojson.geometry : geojson;

    // Geometry Types faster than jsts
    if (geometry.type === 'GeometryCollection') {
        var results = [];
        geomEach(geojson, function (geometry) {
            var buffered = bufferFeature(geometry, radius, units, steps);
            if (buffered) results.push(buffered);
        });
        return featureCollection(results);
    }

    // Project GeoJSON to Transverse Mercator projection (convert to Meters)
    var projected;
    var bbox = turfBbox(geojson);
    var needsTransverseMercator = bbox[1] > 50 && bbox[3] > 50;

    if (needsTransverseMercator) {
        projected = {
            type: geometry.type,
            coordinates: projectCoords(geometry.coordinates, defineProjection(geometry))
        };
    } else {
        projected = toMercator(geometry);
    }

    // JSTS buffer operation
    var reader = new GeoJSONReader();
    var geom = reader.read(projected);
    var distance = radiansToLength(lengthToRadians(radius, units), 'meters');
    var buffered = BufferOp.bufferOp(geom, distance);
github Turfjs / turf / packages / turf-isobands / index.js View on Github external
function rescaleContours(contours, matrix, points) {

    // get dimensions (on the map) of the original grid
    var gridBbox = bbox(points); // [ minX, minY, maxX, maxY ]
    var originalWidth = gridBbox[2] - gridBbox[0];
    var originalHeigth = gridBbox[3] - gridBbox[1];

    // get origin, which is the first point of the last row on the rectangular data on the map
    var x0 = gridBbox[0];
    var y0 = gridBbox[1];
    // get number of cells per side
    var matrixWidth = matrix[0].length - 1;
    var matrixHeight = matrix.length - 1;
    // calculate the scaling factor between matrix and rectangular grid on the map
    var scaleX = originalWidth / matrixWidth;
    var scaleY = originalHeigth / matrixHeight;

    var resize = function (point) {
        point[0] = point[0] * scaleX + x0;
        point[1] = point[1] * scaleY + y0;
github mapbox / osmcha-frontend / src / components / filters / location.js View on Github external
this.map.addLayer({
        id: 'geometry',
        type: 'fill',
        source: 'feature',
        paint: {
          'fill-color': '#088',
          'fill-opacity': 0.6
        }
      });
    }
    this.setState({ geometry: data });
    this.props.onChange(
      this.props.name,
      fromJS([{ label: data, value: data }])
    );
    const geom_bbox = bbox(data);
    this.map.fitBounds([geom_bbox.slice(0, 2), geom_bbox.slice(2)], {
      padding: 20
    });
  }
github etalab / adresse.data.gouv.fr / components / bases-locales / editor / edit-bal / contour-commune-map.js View on Github external
fitBounds = () => {
    const {data} = this.props
    const bbox = computeBbox(data)

    this.map.fitBounds(bbox, {
      padding: 30,
      linear: true,
      duration: 0
    })
  }
github Turfjs / turf / packages / turf-boolean-contains / index.ts View on Github external
export function isLineInPoly(polygon: Polygon, linestring: LineString) {
    let output = false;
    let i = 0;

    const polyBbox = calcBbox(polygon);
    const lineBbox = calcBbox(linestring);
    if (!doBBoxOverlap(polyBbox, lineBbox)) {
        return false;
    }
    for (i; i < linestring.coordinates.length - 1; i++) {
        const midPoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
        if (booleanPointInPolygon({type: "Point", coordinates: midPoint}, polygon, { ignoreBoundary: true })) {
            output = true;
            break;
        }
    }
    return output;
}

@turf/bbox

turf bbox module

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/bbox functions