How to use the @turf/turf.bboxPolygon function in @turf/turf

To help you get started, we’ve selected a few @turf/turf 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 DoFabien / OsmGo / src / services / osmApi.service.ts View on Github external
getDataFromBbox(bbox: BBox, useOverpassApi: boolean = false) {
        let featureBbox = bboxPolygon(bbox);
        for (let i = 0; i < featureBbox.geometry.coordinates[0].length; i++) {
            featureBbox.geometry.coordinates[0][i][0] = featureBbox.geometry.coordinates[0][i][0];
            featureBbox.geometry.coordinates[0][i][1] = featureBbox.geometry.coordinates[0][i][1];
        }
        let bboxArea = area(featureBbox);

        if (useOverpassApi || bboxArea > 100000) { // si la surface est > 10000m² => overpass api
            let urlOverpassApi = 'https://overpass-api.de/api/interpreter';

            return this.httpClient.post(urlOverpassApi, this.getUrlOverpassApi(bbox), { responseType: 'text' })
                .map((res) => {
                    let newDataJson = this.xmlOsmToFormatedGeojson(res);
                    // Il y a eu une erreur lors de la conversion => exemple, timeOut et code 200
                    if (newDataJson.error) {
                        throw ErrorObservable.create(newDataJson.error);
                    }
github farmOS / farmOS-client / src / utils / geometry.js View on Github external
export function isNearby(location, shape, radius) {
  const multiTypes = ['GeometryCollection', 'MultiPoint', 'MultiLineString', 'MultiPolygon'];
  // Convert the Well-Known Text to a GeoJSON geometry, if it isn't already.
  const geoJSON = typeof shape === 'string'
    ? parse(shape)
    : shape;
  // If it's a multipart geometry, get the bounding box, converted to geoJSON,
  // otherwise just use the geometry as is.
  const bboxGeoJSON = multiTypes.includes(geoJSON.type)
    ? bboxPolygon(bbox(geoJSON)).geometry
    : geoJSON;

  // If the location is inside the shape, we can return true early.
  if (booleanContains(bboxGeoJSON, { type: 'Point', coordinates: location })) {
    return true;
  }
  // Otherwise, we'll create a circle around the point, using the radius
  // provided, and check to see if that crosses the shape.
  const radiusAroundLocation = circle(location, radius, { units: 'meters' });
  if (bboxGeoJSON.type === 'Polygon') {
    return booleanOverlap(radiusAroundLocation, bboxGeoJSON);
  }
  if (bboxGeoJSON.type === 'LineString') {
    return booleanCrosses(radiusAroundLocation, bboxGeoJSON);
  }
  if (bboxGeoJSON.type === 'Point') {
github sharedstreets / mobility-metrics / src / cli.js View on Github external
return new Promise(async (resolve, reject) => {
    const envelope = turf.bboxPolygon(config.boundary).geometry;

    // get graph
    const graphOpts = {
      source: "osm/planet-181224",
      tileHierarchy: 6
    };
    var graph = new shst.Graph(envelope, graphOpts);
    await graph.buildGraph();

    await summarize(
      startDay,
      endDay,
      reportDay,
      shst,
      graph,
      publicPath,
github sharedstreets / mobility-metrics / bench.js View on Github external
async function bench() {
  config.zones.features = config.zones.features.map(zone => {
    zone.properties.keys = {};
    cover.indexes(zone.geometry, zs).forEach(key => {
      zone.properties.keys[key] = 1;
    });
    return zone;
  });

  const envelope = turf.bboxPolygon(config.boundary).geometry;
  const graphOpts = {
    source: "osm/planet-181224",
    tileHierarchy: 6
  };
  var graph = new shst.Graph(envelope, graphOpts);
  await graph.buildGraph();

  const trips = fs
    .readFileSync("./example/data/Spuun/trips.json")
    .toString()
    .split("\n")
    .filter(l => {
      return l.length;
    })
    .map(JSON.parse);
github osmlab / osmlint / validators / unclosedWays / map.js View on Github external
module.exports = function(tileLayers, tile, writeData, done) {
  var layer = tileLayers.osm.osm;
  var bbox = turf.bbox(layer);
  var bboxLineString = turf.bboxPolygon(bbox);
  bboxLineString.geometry.type = 'LineString';
  bboxLineString.geometry.coordinates = bboxLineString.geometry.coordinates[0];
  var buffer = turf.buffer(bboxLineString, 0.0005, {
    units: 'miles'
  });
  var result = layer.features.filter(function(val) {
    val.properties._osmlint = 'unclosedways';
    var valueType =
      preserveType.area[val.properties.area] ||
      preserveType.building[val.properties.building] ||
      preserveType.landuse[val.properties.landuse] ||
      preserveType.aeroway[val.properties.aeroway] ||
      preserveType.leisure[val.properties.leisure] ||
      preserveType.natural[val.properties.natural] ||
      preserveType.man_made[val.properties.man_made];
github osmlab / osmlint / validators / missingTurnLinks / map.js View on Github external
module.exports = function(tileLayers, tile, writeData, done) {
  var layer = tileLayers.osm.osm;
  var bboxes = [];
  var bboxLayer = turf.bboxPolygon(turf.bbox(layer));
  bboxLayer.geometry.type = 'LineString';
  bboxLayer.geometry.coordinates = bboxLayer.geometry.coordinates[0];
  var bufferLayer = turf.buffer(bboxLayer, 0.01, 'miles');
  var highways = {};
  var preserveType = {
    'motorway': true,
    'trunk': true,
    'primary': true,
    'secondary': true,
    'tertiary': true
  };

  var roadSegments = {};
  var osmlint = 'missingturnlinks';
  for (var i = 0; i < layer.features.length; i++) {
    var val = layer.features[i];
github osmlab / osmlint / validators / islandsHighways / map.js View on Github external
module.exports = function(tileLayers, tile, writeData, done) {
  var layer = tileLayers.osm.osm;
  var bboxLayer = turf.bboxPolygon(turf.bbox(layer));
  bboxLayer.geometry.type = 'LineString';
  bboxLayer.geometry.coordinates = bboxLayer.geometry.coordinates[0];
  var bufferLayer = turf.buffer(bboxLayer, 0.01, {
    units: 'miles'
  });
  var highways = {};
  var bboxes = [];
  var majorRoads = {
    motorway: true,
    trunk: true,
    primary: true,
    secondary: true,
    tertiary: true,
    motorway_link: true,
    trunk_link: true,
    primary_link: true,
github hotosm / tasking-manager / frontend / src / components / projectCreate / setTaskSizes.js View on Github external
const xmin = x * step - AXIS_OFFSET;
  const ymin = y * step - AXIS_OFFSET;
  const xmax = (x + 1) * step - AXIS_OFFSET;
  const ymax = (y + 1) * step - AXIS_OFFSET;

  const minlnglat = meters2degress(xmin, ymin);
  const maxlnglat = meters2degress(xmax, ymax);

  const properties = {
    x: x,
    y: y,
    zoom: zoomLevel,
    isSquare: true,
  };
  const bbox = [minlnglat[0], minlnglat[1], maxlnglat[0], maxlnglat[1]];
  const poly = turf.bboxPolygon(bbox);

  return turf.multiPolygon([poly.geometry.coordinates], properties);
};
github osmlab / osmlint / validators / impossibleOneWays / map.js View on Github external
module.exports = function(tileLayers, tile, writeData, done) {
  var layer = tileLayers.osm.osm;
  var bboxes = [];
  var bboxLayer = turf.bboxPolygon(turf.bbox(layer));
  bboxLayer.geometry.type = 'LineString';
  bboxLayer.geometry.coordinates = bboxLayer.geometry.coordinates[0];
  var bufferLayer = turf.buffer(bboxLayer, 0.01, {
    units: 'miles'
  });
  var highways = {};
  var majorRoads = {
    motorway: true,
    trunk: true,
    primary: true,
    secondary: true,
    tertiary: true,
    motorway_link: true,
    trunk_link: true,
    primary_link: true,
    secondary_link: true,
github DenisCarriere / geocoder-geojson / utils / index.ts View on Github external
export function confidenceScore(bbox: BBox): number {
  if (!bbox) { return 0 }
  let result = 0
  const poly = turf.bboxPolygon(bbox)
  const sw = turf.point(poly.geometry.coordinates[0][0])
  const ne = turf.point(poly.geometry.coordinates[0][2])
  const distance = turf.distance(sw, ne, 'kilometers')
  scoreMatrix.map(step => {
    const [score, maximum] = step
    if (distance < maximum) { result = score }
    if (distance >= 25) { result = 1 }
  })
  return result
}