How to use the turf.extent function in turf

To help you get started, we’ve selected a few 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 aaronpdennis / congress-maps / process.js View on Github external
// collect bounding boxes for the districts
  var bounds = turf.extent(d);
  districtBboxes[state + number] = bounds;

  // and for the states
  if (stateBboxes[state]) {
    stateBboxes[state].features.push(turf.bboxPolygon(bounds));
  } else {
    stateBboxes[state] = { type: 'FeatureCollection', features: [] };
    stateBboxes[state].features.push(turf.bboxPolygon(bounds));
  }
});

// get the bounding boxes of all of the bounding boxes for each state
for (var s in stateBboxes) {
  stateBboxes[s] = turf.extent(stateBboxes[s]);
}

// write out data for the next steps
console.log('writing data...');

fs.writeFileSync('./data/map.geojson', JSON.stringify(mapData));

fs.writeFileSync('./example/states.js', 'var states = ' + JSON.stringify(stateCodes, null, 2));

var bboxes = {};
for (var b in districtBboxes) { bboxes[b] = districtBboxes[b] };
for (var b in stateBboxes) { bboxes[b] = stateBboxes[b] };
fs.writeFileSync('./example/bboxes.js', 'var bboxes = ' + JSON.stringify(bboxes, null, 2));

console.log('finished processing, ready for tiling');
github aaronpdennis / congress-maps / process.js View on Github external
// add metadata to the label
  pt.properties = d.properties;
  pt.properties.title_short = state + ' ' + (number == "00" ? "At Large" : parseInt(number));
  pt.properties.title_long = state_name + '’s ' + (number == "00" ? "At Large" : ordinal(parseInt(number))) + ' Congressional District';

  // add a type property to distinguish between labels and boundaries
  pt.group = 'label';
  d.group = 'boundary';

  // add both the label point and congressional district to the mapData feature collection
  mapData.features.push(pt);
  mapData.features.push(d);

  // collect bounding boxes for the districts
  var bounds = turf.extent(d);
  districtBboxes[state + number] = bounds;

  // and for the states
  if (stateBboxes[state]) {
    stateBboxes[state].features.push(turf.bboxPolygon(bounds));
  } else {
    stateBboxes[state] = { type: 'FeatureCollection', features: [] };
    stateBboxes[state].features.push(turf.bboxPolygon(bounds));
  }
});
github mapbox / osm-sidewalker / sidewalker.js View on Github external
segmented.features.forEach(function (seg) {
        if (turf.lineDistance(seg, 'miles') <= 150/5280) return;
        
        // Get bisectors fo this segment, and match it against 
        // each road. 
        var bisectors = buildBisectors(seg);
        var isMatched = false;

        var bisectBox = turf.extent(turf.featurecollection(bisectors));
        var maybeCollides = roadIndex.search(bisectBox);

        maybeCollides.forEach(function (maybe) {
          var road = roads[maybe[4].road_id];
        
          if (isMatched || road.properties.layer !== footways[f].properties.layer) return;

          var matched = 0;
          bisectors.forEach(function (bisector) {
            if (gju.lineStringsIntersect(bisector.geometry, road.geometry)) matched++;
          });
          if (matched / bisectors.length > 0.7) {
            isMatched = true;
            seg.properties['_osm_way_id'] = footways[f].properties._osm_way_id;
            seg.properties['proposed:footway'] = 'sidewalk';
            seg.properties['proposed:associatedStreet'] = road.properties.name;
github hotosm / osm-analytics / app / components / Stats / searchFeatures.js View on Github external
function getRegionTiles(region, zoom) {
  const regionBounds = extent(region)
  var tiles = []
  // get all tiles for the regions bbox
  var tileBounds = merc.xyz(regionBounds, zoom)
  for (let x=tileBounds.minX; x<=tileBounds.maxX; x++) {
    for (let y=tileBounds.minY; y<=tileBounds.maxY; y++) {
      tiles.push({
        x,
        y,
        zoom,
        hash: x+'/'+y+'/'+zoom
      })
    }
  }
  // drop tiles that are actually outside the region

  tiles = tiles.filter(tile => {
github funkeinteraktiv / cogran / lib / methods / attribute-weighting-advanced.js View on Github external
intersects.forEach((d,i) => {
    const At = Turf.area(feature);
    const Ast = Turf.area(d);
    const Qt = feature.properties[options.weight];
    const Qst = (Ast / At) * Qt;

    const attributeValue = parseFloat(sourceFeatures[i].properties[options.attr]);

    // wenn komplett im source feature,
    const sb = Turf.extent(sourceFeatures[i]);
    let isInside = true;
    if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
    if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };

    if(isInside) {
      if(!isNaN(attributeValue)) {
        result += Ps;
      }
      return;
    }


    if(!isNaN(attributeValue)) {
      result += (Qst / sourceFeatures[i].properties["Qs"]) * attributeValue;
    }
  });
github funkeinteraktiv / cogran / lib / methods / areal-weighting-relative.js View on Github external
intersects.forEach((d,i) => {
    const Ps = parseFloat(sourceFeatures[i].properties[attributeName]);
    //if(isNaN(Ps)) { return; }

    // wenn komplett im source feature,
    const sb = Turf.extent(sourceFeatures[i]);
    let isInside = true;
    if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
    if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };

    if(isInside) {
      result += Ps;
      return;
    }

    const As = Turf.area(feature);
    const Ast = Turf.area(d);
    result += (Ast * Ps) / As;
  });
github hotosm / osm-analytics / app / components / Stats / searchFeatures.js View on Github external
function getRegionZoom(region) {
  const maxZoom = 13 // todo: setting "maxZoom"
  const tileLimit = 12 // todo: setting "tileLimit"
  const regionBounds = extent(region)
  for (let z=maxZoom; z>0; z--) {
    let tileBounds = merc.xyz(regionBounds, z)
    let tilesNum = (1 + tileBounds.maxX - tileBounds.minX) * (1 + tileBounds.maxY - tileBounds.minY)
    if (tilesNum <= tileLimit) {
      return z
    }
  }
  return 0
}
github funkeinteraktiv / cogran / lib / methods / attribute-weighting-relative.js View on Github external
intersects.forEach((d,i) => {
    const At = Turf.area(feature);
    const Ast = Turf.area(d);
    const Qt = feature.properties[options.weight];
    const Qst = (Ast / At) * Qt;

    const attributeValue = parseFloat(sourceFeatures[i].properties[options.attr]);

    // wenn komplett im source feature,
    const sb = Turf.extent(sourceFeatures[i]);
    let isInside = true;

    if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
    if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };

    if(isInside) {
      if(!isNaN(attributeValue)) {
        result += Ps;
      }
      return;
    }


    if(!isNaN(attributeValue)) {
      result += (Qst / sourceFeatures[i].properties["Qs"]) * attributeValue;
    }
github funkeinteraktiv / cogran / lib / methods / areal-weighting-advanced.js View on Github external
intersects.forEach((d,i) => {
    const Ps = parseFloat(sourceFeatures[i].properties[attributeName]);
    //if(isNaN(Ps)) { return; }

    // wenn komplett im source feature,
    const sb = Turf.extent(sourceFeatures[i]);
    let isInside = true;
    if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
    if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };

    if(isInside) {
      result += Ps;
      return;
    }

    const As = Turf.area(feature);
    const Ast = Turf.area(d);
    result += (Ast * Ps) / As;
  });
github mapbox / osm-sidewalker / sidewalker.js View on Github external
function findProbablyIntersects(footway, roadIndex, roads) {
  var extent = turf.extent(footway);

  var colliding = roadIndex.search(extent);
  var fc = [];


  for (var i = 0; i < colliding.length; i++) {
    fc.push(roads[colliding[i][4].road_id])
  }

  return turf.featurecollection(fc);
}