Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
flat.forEach(function(line) {
// Don't try to match an endpoint to the way that it came from
if (layer == cap.layer && i == cap.i) {
return;
}
if (!reject_class[line.properties.class] && line.geometry.type === 'LineString') {
var distance = turf.distance(cap.point, turf.pointOnLine(line, cap.point));
if (distance < best) {
var already = false;
// Don't try to match an endpoint to a way that the
// way that it comes from already connects to
cap.line.geometry.coordinates.forEach(function(capp) {
line.geometry.coordinates.forEach(function(linep) {
if (capp[0] == linep[0] && capp[1] == linep[1]) {
already = true;
}
});
});
if (!already) {
best = distance;
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
filtered.forEach(function(feature) {
if (feature.geometry.type == "Point") {
// feature.properties.dist = getDistanceFromLatLonInM(feature.geometry.coordinates[0], feature.geometry.coordinates[1], user.geometry.coordinates[0], user.geometry.coordinates[1])
feature.properties.dist = turf.distance(feature, user)
}
})
}
var has_overlap = false;
var all_water = false;
var water_features_checked = 0;
//console.log("Checked "+water_features_checked+" of "+water_data.features.length+" water features");
if (!all_water) {
var dggrid_population = 0.0;
for (tract_index = 0; tract_index < census_data.features.length; tract_index++) {
var tract = census_data.features[tract_index];
var tract_centroid = centroids[tract_index];
var geoid = tract.properties["STATEFP10"] + tract.properties["COUNTYFP10"] + tract.properties["TRACTCE10"];
if (population_density[geoid] > 1000.0) {
var distance = turf.distance(dggrid_centroid, tract_centroid, 'miles');
//console.log(dggrid_centroid);
//console.log(tract_centroid);
//console.log("Distance is "+distance);
if (distance < 10.0) {
var overlap_polygon = turf.intersect(tract, dggrid_polygon);
if (overlap_polygon != undefined) {
var population = populations[geoid];
var area = land_area[geoid];
has_overlap = true;
var overlap_area = turf.area(overlap_polygon);
var new_population = population * (overlap_area/area);
dggrid_population += new_population;
}
}
}
}
var new_data = JSON.parse(JSON.stringify(data));
for (tract_index in data.features) {
var feature = data.features[tract_index]
var properties = feature.properties;
var properties_new = {"S":properties["STATEFP10"], "L":properties["LOCALNAME"],"C":properties["TRACTCE10"],"H":properties["HH_COUNT"]};
new_data.features[tract_index].properties = properties_new;
}
var rem_data = JSON.parse(JSON.stringify(new_data));
rem_data.features = [];
for (tract_index in new_data.features) {
var feature = new_data.features[tract_index]
var centroid = turf.centroid(feature);
//console.log(feature);
console.log(centroid.geometry.coordinates);
var distance = turf.distance(centroid, manhattan_center, "miles");
//console.log(distance);
if (distance < 20.0) {
rem_data.features.push(feature);
}
}
jsonfile.writeFile('everything_node.geojson', rem_data, {spaces: 2}, function(err) {
console.error(err);
});
});
console.log("Calculating voxels");
for (i = 0; i < voxels_dim; i++) {
var lat = lat_min + voxels_res_lat*i;
for (j = 0; j < voxels_dim; j++) {
var lon = lon_min + voxels_res_lon*j;
var square = turf.bboxPolygon([lon, lat, lon+voxels_res_lon, lat+voxels_res_lat]);
var d = 0.0;
for (tract_index = 0; tract_index < data.features.length; tract_index++) {
var tract = data.features[tract_index];
var ct2010 = tract.properties.TRACTCE10;
var centroid = centroids[tract_index];
var square_centroid = turf.center({"type": "FeatureCollection", "features": [square]});
var distance = turf.distance(centroid, square_centroid, 'miles');
if (distance <= 1.0) {
var overlap_polygon = turf.intersect(tract, square);
if (overlap_polygon != undefined) {
var overlap_area = turf.area(overlap_polygon);
var tract_area = turf.area(tract);
if (ct2010 in populations) {
d += populations[ct2010] * overlap_area/tract_area;
} else {
d += 1000.0 * overlap_area/tract_area;
}
}
}
selected.forEach(function(f) {
if (f.geometry.type === 'Point') {
points.push(f)
}
})
}
if (layer.geojson.feature) {
if (layer.geojson.feature.selected) {
if (layer.geojson.feature.geometry.type === 'Point') {
points.push(layer.geojson.feature)
}
}
}
}
}
var bearing = turf.distance(points[0], points[1], 'miles')
var msg = '<p>Distance</p><p>' + numeral(bearing).format('0.0000') + ' mi'
vex.dialog.alert(msg)
},
lineLength: function(layers) {</p>
chunk.forEach(pt => {
if (points.length == 0)
{
points.push(pt);
}
else
{
let distance = turf.distance(pt, points[points.length-1], 'meters');
if (distance < max_distance)
{
points.push(pt);
}
}
});
}
var result = layer.features.filter(function(val) {
if (val.properties.junction && val.properties.junction === 'roundabout' && val.geometry.type === 'LineString') {
var coordinates = val.geometry.coordinates;
var coordinatesLength = coordinates.length;
var start = turf.point(coordinates[0]);
var end = turf.point(coordinates[coordinatesLength - 1]);
var distance = turf.distance(start, end, 'kilometers');
if (distance >= 0.02) {
val.properties._osmlint = 'falseroundabouts';
return true;
}
}
});
newCoords = coords.filter(function(coord, i) {
var p = turf.point(coord),
takePoint = true;
if (i !== 0) {
if (times) {
takePoint = (times[i] - prevTime > minTimeDiff) &&
(turf.distance(prevCoord, p)*1000 > minDistance);
} else {
takePoint = turf.distance(prevCoord, p)*1000 > minDistance;
}
}
if (takePoint)
{
prevCoord = p;
if (times) {
prevTime = times[i];
newTimes.push(times[i]);
}
}
return takePoint;
});