Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (timestamp.diff(current) <= 0) {
lastAvailable = state;
}
}
});
if (lastAvailable) {
// onstreet hex bins
var bin = h3.geoToH3(
lastAvailable.event_location.geometry.coordinates[1],
lastAvailable.event_location.geometry.coordinates[0],
Z
);
// store geo
var geo = turf.polygon([h3.h3ToGeoBoundary(bin, true)], {
bin: bin
});
stats.geometry.bins[bin] = geo;
// bootstrap bin
if (!stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")]) {
stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")] = {};
}
if (
!stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")][bin]
) {
stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")][
bin
] = 1;
} else {
stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")][bin]++;
if (timestamp.diff(current) <= 0) {
lastAvailable = state;
}
}
});
if (lastAvailable) {
// availability hex bins
var bin = h3.geoToH3(
lastAvailable.event_location.geometry.coordinates[1],
lastAvailable.event_location.geometry.coordinates[0],
Z
);
// store geo
var geo = turf.polygon([h3.h3ToGeoBoundary(bin, true)], {
bin: bin
});
stats.geometry.bins[bin] = geo;
// bootstrap bin
if (
!stats.availability.bins.minute[current.format(baseDay + "-HH-mm")]
) {
stats.availability.bins.minute[
current.format(baseDay + "-HH-mm")
] = {};
}
if (
!stats.availability.bins.minute[current.format(baseDay + "-HH-mm")][
bin
]
function h3ToPolygon(hexId, coverage = 1, flatten) {
const vertices = h3ToGeoBoundary(hexId, true);
if (coverage !== 1) {
// scale and normalize vertices w.r.t to center
scalePolygon(hexId, vertices, coverage);
} else {
// normalize w.r.t to start vertex
normalizeLongitudes(vertices);
}
if (flatten) {
const positions = new Float64Array(vertices.length * 2);
let i = 0;
for (const pt of vertices) {
positions[i++] = pt[0];
positions[i++] = pt[1];
}
export function getVertices({id}) {
// always reverse it
return h3ToGeoBoundary(id, true);
}
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] = {};
}
if (!stats.flows.pairs.minute[timeBins.minute]) {
stats.flows.pairs.minute[timeBins.minute] = {};
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] = {};
}
function h3ToFeature(hexAddress, properties = {}) {
// Wrap in an array for a single-loop polygon
const coordinates = [h3.h3ToGeoBoundary(hexAddress, true)];
return {
type: FEATURE,
id: hexAddress,
properties,
geometry: {
type: POLYGON,
coordinates
}
};
}
test('featureToH3Set - resolution 10', assert => {
const parentHex = '89283082837ffff';
const vertices = h3.h3ToGeoBoundary(parentHex, true);
const feature = {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
[
vertices[2],
vertices[3],
vertices[4],
vertices[5],
vertices[0],
vertices[1],
vertices[2]
]
]
const boundaries = this._circleMap.data().map(row => {
const h3Idx = geoToH3(row[0], row[1], res);
return [h3Idx, h3ToGeoBoundary(h3Idx, false).map(point => [point[1], point[0]]), 1];
});
this._hexMap.data(boundaries);