Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
trip.route.features[0].geometry.coordinates[1],
trip.route.features[0].geometry.coordinates[0],
Z
);
var b = h3.geoToH3(
trip.route.features[trip.route.features.length - 1].geometry
.coordinates[1],
trip.route.features[trip.route.features.length - 1].geometry
.coordinates[0],
Z
);
// store pair geometry
var pair = turf.lineString(
[
turf.centroid(turf.polygon([h3.h3ToGeoBoundary(a, true)])).geometry
.coordinates,
turf.centroid(turf.polygon([h3.h3ToGeoBoundary(b, true)])).geometry
.coordinates
],
{ pair: a + ">" + b }
);
stats.geometry.pairs[pair.properties.pair] = pair;
var timeBins = getTimeBins(reportDay, trip.start_time);
// populate time bins
if (!stats.flows.pairs.day[timeBins.day]) {
stats.flows.pairs.day[timeBins.day] = {};
}
if (!stats.flows.pairs.hour[timeBins.hour]) {
stats.flows.pairs.hour[timeBins.hour] = {};
}
continue;
}
osmCover.insert(feature);
}
var features = [];
for (let bFeature of data.buildings.bingbuildings.features) {
var bingOsmIntersect = osmCover.search(bFeature);
if (bingOsmIntersect.features.length == 0) {
// No intersection in the rbush means we should just write out the building
features.push(bFeature);
continue;
} else if (bingOsmIntersect.features.length > 0) {
var bCentroid = turf.centroid(bFeature);
var matchFound = false;
for (let oFeature of bingOsmIntersect.features) {
var oCentroid = turf.centroid(oFeature);
var dist = turf.distance(bCentroid, oCentroid);
if (dist < 0.05) {
matchFound = true;
break;
}
}
if (!matchFound) {
features.push(bFeature);
}
}
}
export const getCentroidFromYearAndCode = (year, code) => {
const featuresArray = [dc2003, dc2007, dc2011, dc2015, dc2019]
const selectedIndex = [2003, 2007, 2011, 2015, 2019].findIndex(
y => y === year
)
if (selectedIndex > -1) {
const selectedFeature = featuresArray[selectedIndex]
const polygon = selectedFeature.features.find(
feature => feature.properties.CACODE === code
)
const centroid = turf.centroid(polygon)
// finetune for concave polygon for 2019 districts
return (
adjustConcavePolygonCentroid(year, code) || centroid.geometry.coordinates
)
}
return
}
centroidStream._transform = function (feature, encoding, done) {
// Shave away all attributes except day for centroid features
const centroidFeature = turf.centroid(feature);
centroidFeature.properties = feature.properties;
this.push(centroidFeature);
done();
};
function getDistance(o1, o2) {
var p, pp;
if (o1.geometry.type === 'Polygon') {
pp = turf.centroid(o1);
p = o2;
} else {
pp = turf.centroid(o2);
p = o1;
}
return turf.distance(pp, p, {
units: 'kilometers'
});
}
function getDistance(o1, o2) {
var p, pp;
if (o1.geometry.type === 'Polygon') {
pp = turf.centroid(o1);
p = o2;
} else {
pp = turf.centroid(o2);
p = o1;
}
return turf.distance(pp, p, {
units: 'kilometers'
});
}
function getDistance(o1, o2) {
var p, pp;
if (o1.geometry.type === 'Polygon') {
pp = turf.centroid(o1);
p = o2;
} else {
pp = turf.centroid(o2);
p = o1;
}
return turf.distance(pp, p, {
units: 'kilometers'
});
}
filterStream._transform = function (feature, encoding, done) {
let result = null;
if (feature.geometry.type === 'Point') {
result = query(feature.geometry.coordinates);
} else {
const centroidFeature = turf.centroid(feature);
result = query(centroidFeature.geometry.coordinates);
}
if (result) {
this.push(feature);
}
done();
};
function getDistance(o1, o2) {
var p, pp;
if (o1.geometry.type === 'Polygon') {
pp = turf.centroid(o1);
p = o2;
} else {
pp = turf.centroid(o2);
p = o1;
}
return turf.distance(pp, p, {
units: 'kilometers'
});
}