Skip to content

Commit

Permalink
consolidate matcher utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
morganherlocker committed Aug 30, 2019
1 parent e89173d commit 044dfb2
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ public

# config
config.json

# OS
.DS_Store
190 changes: 190 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"prettier": "^1.18.2",
"tap": "^12.7.0"
"tap": "^12.7.0",
"tape": "^4.11.0"
}
}
39 changes: 39 additions & 0 deletions src/matchers/change.js
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;
}
54 changes: 54 additions & 0 deletions src/matchers/trip.js
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 removed test/.DS_Store
Binary file not shown.
Loading

0 comments on commit 044dfb2

Please sign in to comment.