Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var coords = String(argv.extent).split(',').map(parseFloat);
var input = turf.featurecollection([
turf.point([coords[1], coords[0]]),
turf.point([coords[3], coords[2]])
]);
geojson = turf.extent(input);
} else {
displayHelp();
console.error('No geometry provided. Pipe geojson, or use --point or --extent');
return process.exit(1);
}
if (argv.buffer) {
var radius = parseFloat(argv.buffer);
var units = /mi$/.test(argv.buffer) ? 'miles' : 'kilometers';
geojson = turf.buffer(geojson, radius, units);
}
// tilecover doesn't like features
geojson = turf.merge(geojson);
if (geojson.type === 'Feature') {
geojson = geojson.geometry;
}
callback();
},
function performAction(callback) {
function findNearestStops(lat, lon) {
var point = turf.point([lon, lat]);
var buffer = turf.buffer(point, config.NEAREST_BUFFER, 'miles');
var nearest_stops = turf.within(gtfs.all_stops, buffer);
var out = nearest_stops.features.map(function(stop){
var stopId = stop.properties.stop_id.match(/\d+/g)[0];
return { route: stop.properties.name,
stopId: stopId,
distance: turf.distance(point, stop, "miles"),
ll: stopLatLong(stopId)
}
});
// returns empty if none found nearby
out.sort(function(a, b) {
return (a.distance - b.distance)
});
if (out.length > config.NEAREST_MAX) out = out.slice(0,config.NEAREST_MAX);
return out;
}
function queryOverpass(lon, lat, radius, callback) {
var query = fs.readFileSync(__dirname + '/query.ql').toString();
var x = lon;
var y = lat;
var point = turf.point([x, y]);
var buffer = turf.buffer(point, radius, 'kilometers');
// wsen
var bbox = turf.bbox(buffer);
// swne
var overpassBbox = [bbox[0], bbox[1], bbox[2], bbox[3]].toString();
var query = util.format(query, overpassBbox, overpassBbox);
overpass(query, function(error, data) {
if (error) {
return callback(error, null);
};
// ::id,::lon,::lat,"place","name","name:en","name:zh","wikipedia","wikidata"
var d = [];
data.features.forEach(function (f) {
var interestedProps = {
'id': f.properties.id,
'type': f.properties.type,
streetBuffers.features = streets.features.map(function(road){
return turf.buffer(road, 5, 'meters').features[0];
});
streetBuffers = normalize(turf.merge(streetBuffers));
streets.features.forEach(function(street){
streetBuff.features = streetBuff.features.concat(turf.buffer(street, 0.0189394, 'miles').features);
});
function villagesInCircle(center,time,maxspeed) {
var centerPt = turf.point([center[0],center[1]]);
var length = (time/3600)*maxspeed;
var circle = turf.buffer(centerPt,length,'kilometers');
var result = turf.within(villages,circle);
console.log(result.features.length +' villages within max distance')
return result;
}
var preserveType = {};
preserveType = _.extend(preserveType, majorRoads);
var osmlint = 'junctionymotorway';
for (var z = 0; z < layer.features.length; z++) {
var val = layer.features[z];
if (val.geometry.type === 'LineString' && preserveType[val.properties.highway]) {
var bboxA = turf.bbox(val);
bboxA.push({
id: val.properties['@id']
});
bboxes.push(bboxA);
highways[val.properties['@id']] = val;
}
if (val.geometry.type === 'Point' && val.properties.highway && val.properties.highway === 'motorway_junction') {
var bboxP = turf.bbox(turf.buffer(val, 20, 'meters'));
bboxP.push({
id: val.properties['@id'] + 'P',
junction: true
});
bboxes.push(bboxP);
motorwayJunction[val.properties['@id'] + 'P'] = val;
}
}
var highwaysTree = rbush(bboxes.length);
highwaysTree.load(bboxes);
for (var i = 0; i < bboxes.length; i++) {
var valueBbox = bboxes[i];
if (!valueBbox[4].junction) {
var valueHighway = highways[valueBbox[4].id];
valueHighway.properties._osmlint = osmlint;
var overlaps = highwaysTree.search(valueBbox);
var preserveType = {};
preserveType = _.extend(preserveType, majorRoads);
var osmlint = 'getylane';
for (var z = 0; z < layer.features.length; z++) {
var val = layer.features[z];
if (val.geometry.type === 'LineString' && preserveType[val.properties.highway]) {
var bboxA = turf.bbox(val);
bboxA.push({
id: val.properties['@id']
});
bboxes.push(bboxA);
highways[val.properties['@id']] = val;
}
if (val.geometry.type === 'Point' && val.properties.highway && val.properties.highway === 'motorway_junction') {
var bboxP = turf.bbox(turf.buffer(val, 20, 'meters'));
bboxP.push({
id: val.properties['@id'] + 'P',
junction: true
});
bboxes.push(bboxP);
motorwayJunction[val.properties['@id'] + 'P'] = val;
}
}
var highwaysTree = rbush(bboxes.length);
highwaysTree.load(bboxes);
for (var i = 0; i < bboxes.length; i++) {
var valueBbox = bboxes[i];
if (!valueBbox[4].junction) {
var valueHighway = highways[valueBbox[4].id];
valueHighway.properties._osmlint = osmlint;
var overlaps = highwaysTree.search(valueBbox);
module.exports = function(tileLayers, tile, writeData, done) {
var layer = tileLayers.osm.osm;
var bbox = tilebelt.tileToBBOX(tile);
var bboxLineString = turf.bboxPolygon(bbox);
bboxLineString.geometry.type = 'LineString';
bboxLineString.geometry.coordinates = bboxLineString.geometry.coordinates[0];
var buffer = turf.featurecollection(turf.buffer(bboxLineString, 5, 'meters').features[0]);
var buildings = layer.features.filter(function(val) {
if (val.properties.building && val.geometry.type === 'Polygon') {
var flag = 0;
var buildingPoints = turf.explode(val);
var pointsWithin = turf.within(buildingPoints, buffer);
if (!pointsWithin.features.length) {
var props = {
"_osm_way_id": val.properties._osm_way_id,
"building": val.properties.building,
};
//area in m^2
props.area = parseFloat((turf.area(val)).toFixed(3));