CenterCampStreetPlanner.prototype.getAllStreets = function() {
    var features = [];
    features.push(this.get66Road());
    features.push(this.getARoad());
    features.push(this.getCenterCampPlazaCenterline());
    features.push(this.getRodRoad());
    return turf.featureCollection(features);
}
ToiletParser.prototype.points = function(layoutParser) {
    var polygons = this.polygons(layoutParser);
    var points = polygons.features.map(function(rect){
        var point = turf.centroid(rect);
        point.properties['ref'] = 'toilet';
        return point;
    });
    return turf.featureCollection(points);
}
Ejemplo n.º 3
0
  ,function(geoResults){

    var fc = turf.featureCollection(geoResults);
    var filename = "projects-" + targetPrjs.join("_") + "-" + timestamp + ".geojson";
    var output = path.join(__dirname,'output',filename)
    fs.writeFile(output, JSON.stringify(fc), function(){
      console.log("done!")
    });

  }
exports.fence = function(jsonFile) {
  var cityBearing  = jsonFile.bearing;
  var cityCenter = jsonFile.center;
  var fenceVertexDistance = utils.feetToMiles(jsonFile.fence_distance);

  var bearing = 0;
  var points = [];
  while(bearing < 365) {
    var vertex = turf.destination(cityCenter, fenceVertexDistance, bearing + cityBearing, 'miles')
    points.push(vertex);
    bearing += 360/5;
  }

  var collection = turf.featureCollection(points);
  var polygon = turf.convex(collection);
  var ls = turf.lineString(polygon.geometry.coordinates[0],{
    'ref':'fence',
    'name':"Fence"
  })
  return turf.featureCollection([ls]);
}
Ejemplo n.º 5
0
exports.handler = function( event, context ) {
var turf = require('turf');
var ntElectorates = require('./nt_elec');

var coords = [parseFloat(event.long), parseFloat(event.lat)];
var features = [turf.point(coords)];
var fc = turf.featureCollection(features);

var tagged = turf.tag(fc, ntElectorates, 'Name');

// Return first feature
var electorate = tagged.features[0].properties.undefined;
console.log("Returned result of " + electorate);
context.done(null, electorate);

}
 componentWillReceiveProps (np) {
   if (typeof np.audits !== 'undefined' && np.viewport.extent) {
     let bboxPolygon = turf.bboxPolygon(np.viewport.extent)
     let auditFC = turf.featureCollection(np.audits)
     let auditsInView = []
     auditFC.features.forEach(function (audit) {
       if (typeof turf.intersect(audit, bboxPolygon) !== 'undefined') {
         auditsInView.push(audit)
       }
     })
     const resource = np.resource
     let newTotalData = {}
     auditsInView.forEach(function (audit) {
       _.forEach(audit.properties.totalDemand[resource], function (value, key) {
         typeof newTotalData[key] === 'undefined' ? newTotalData[key] = [value] : newTotalData[key].push(value)
       })
     })
     this.setState({
       auditsInView: auditsInView,
       chartData: newTotalData
     })
   }
 }
ToiletParser.prototype.polygons = function(layoutParser) {
    var features = this.toiletsInfo.map(function(toilet){
        return toiletGeoJSON(layoutParser,this.width,this.height,toilet);
    },this);
    return turf.featureCollection(features);
};
Ejemplo n.º 8
0
/**
 * converts geojson points to a linestring & processes meta information
 * @param geojson: geojson featurecollection containing points
 * @param tags:    optional array of tag strings
 * @param done:    node style callback function
 * @returns object in the form of { meta: {...}, events: {...}, track: {...} }
 */
function processGeoJSON(geojson, tags, done) {
  // create a clone of the data & convert strings to numbers where possible
  var data = JSON.parse(JSON.stringify(geojson), function(key, val) {
    return !isNaN(parseFloat(val)) && isFinite(val) ? parseFloat(val) : val;
  });

  var prevPoint = null, prevLine = null, lines = [], eventPoints = [], result = {
    meta: {
      tags: tags || [],
      length: 0,   // kilometers
      duration: 0, // hours
      standingtime: 0, // hours
      maxSpeed: 0, // km/h
      avgSpeed: 0, // km/h
      date: data.features[0].properties.time,
      events: {}
    },
    events: {},
    track: turf.featureCollection(lines)
  };

  turfMeta.featureEach(data, function(point) {
    // create a line from the waypoints
    if (prevPoint !== null) {
      var linestring = turf.lineString([
        prevPoint.geometry.coordinates, point.geometry.coordinates
      ]);
      var duration = new Date(point.properties.time) - new Date(prevPoint.properties.time);
      duration /= 1000 * 60 * 60; // convert millisec to hours
      linestring.properties.length    = roundFloat(turf.distance(prevPoint, point, 'kilometers'), 4);
      linestring.properties.speed     = roundFloat(linestring.properties.length / duration);
      linestring.properties.bearing   = roundFloat(turf.bearing(prevPoint, point), 1);
      linestring.properties.elevation = roundFloat(point.properties.ele - prevPoint.properties.ele);
      lines.push(linestring);

      // update global metadata
      result.meta.length += linestring.properties.length;
      result.meta.duration += duration;
      if (linestring.properties.speed <= 10)
        result.meta.standingtime += duration;
      if (result.meta.maxSpeed < linestring.properties.speed)
        result.meta.maxSpeed = linestring.properties.speed;

      linestring.properties.trackPosition = roundFloat(result.meta.length, 3);
    }

    prevPoint = point;
  });

  prevPoint = null;
  result.meta.avgSpeed = result.meta.length / result.meta.duration;
  result.meta.standingtime = result.meta.standingtime;
  result.meta.length = roundFloat(result.meta.length);
  result.meta.duration = roundFloat(result.meta.duration);

  // detect events
  var events = {
    'stop': {
      fn: function isStop(line, prevLine) {
        return (line.properties.speed <= 10); // slower than 10km/h?
      },
      coordIndex: 1 // apply the event to the i coordinate of the linestring
    },
    /*'turn': {
      fn: function isTurn(line, prevLine) {
        var bearingThresh = 64; // degrees
        var distanceThresh = 0.005; // km
        var angle = line.properties.bearing - prevLine.properties.bearing;
        if (angle > 180)       angle -= 360;
        else if (angle < -180) angle += 360;

        if (prevLine.properties.length > distanceThresh && Math.abs(angle) >= bearingThresh)
          return true;
        return false;
      },
      coordIndex: 0
    }*/
  };

  // init eventcounters
  for (var type in events) result.meta.events[type + 's'] = 0;

  // add a point to result, if at least one event occured on the current line
  turfMeta.featureEach(result.track, function(line) {
    if (prevLine !== null) {
      var point = turf.point(line.geometry.coordinates[1], { events: [] });

      for (var type in events) {
        if (events[type].fn(line, prevLine)) {
          if (events[type].coordIndex === 1) point.properties.events.push(type);
          else if (prevPoint) prevPoint.properties.events.push(type);
          result.meta.events[type + 's']++;
        }
      }
      eventPoints.push(point);
    }
    prevLine = line;
    prevPoint = point;
  });

  result.events = eventPoints.filter(function(val, i, arr) {
    return (val.properties.events.length > 0);
  })

  done(null, result);
}