forked from sharedstreets/mobility-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e89173d
commit 044dfb2
Showing
9 changed files
with
293 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,6 @@ public | |
|
||
# config | ||
config.json | ||
|
||
# OS | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
}, | ||
"devDependencies": { | ||
"prettier": "^1.18.2", | ||
"tap": "^12.7.0" | ||
"tap": "^12.7.0", | ||
"tape": "^4.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const turf = require('@turf/turf') | ||
|
||
module.exports = function (change, Z, graph, zones) { | ||
// STREETS | ||
|
||
if (!change.properties.matches) change.properties.matches = {} | ||
|
||
const matches = await graph.matchPoint(change.route.features[0], null, 1); | ||
|
||
if (matches.length) { | ||
change.properties.matches.streets = matches; | ||
} | ||
|
||
// BINS | ||
|
||
const bin = h3.geoToH3( | ||
lastAvailable.event_location.geometry.coordinates[1], | ||
lastAvailable.event_location.geometry.coordinates[0], | ||
Z | ||
); | ||
|
||
change.properties.matches.bins = bin; | ||
|
||
// ZONES | ||
|
||
var zoneMatches = [] | ||
|
||
for (let zone of zones.features) { | ||
if (turf.intersect(change.event_location, zone)) { | ||
zoneMatches.push(zone.properties.id); | ||
} | ||
} | ||
|
||
if(zoneMatches.length) { | ||
change.properties.matches.zones = zoneMatches; | ||
} | ||
|
||
return change; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module.exports = function (trip, graph, zones) { | ||
const line = turf.lineString( | ||
trip.route.features.map(pt => { | ||
return pt.geometry.coordinates; | ||
}) | ||
); | ||
|
||
// STREETS | ||
|
||
if (!trip.properties.matches) trip.properties.matches = {} | ||
|
||
const match = await graph.matchTrace(line); | ||
|
||
if ( | ||
match && | ||
match.segments && | ||
match.matchedPath && | ||
match.matchedPath.geometry && | ||
match.matchedPath.geometry.coordinates && | ||
match.matchedPath.geometry.coordinates.length === match.segments.length | ||
) { | ||
trip.properties.matches.streets = match; | ||
} | ||
|
||
// HEXES | ||
|
||
var bins = new Set(); | ||
trip.route.features.forEach(ping => { | ||
var bin = h3.geoToH3( | ||
ping.geometry.coordinates[1], | ||
ping.geometry.coordinates[0], | ||
Z | ||
); | ||
bins.add(bin); | ||
}); | ||
|
||
change.properties.matches.bins = bins; | ||
|
||
// ZONES | ||
|
||
var zoneMatches = [] | ||
|
||
for (let zone of zones.features) { | ||
if (turf.intersect(line, zone)) { | ||
zoneMatches.push(zone.properties.id); | ||
} | ||
} | ||
|
||
if(zoneMatches.length) { | ||
change.properties.matches.zones = zoneMatches; | ||
} | ||
|
||
return trip; | ||
} |
Binary file not shown.
Oops, something went wrong.