Skip to content

Commit

Permalink
add trip filter for trip start OR end in shp area (#3198)
Browse files Browse the repository at this point in the history
Co-authored-by: rakow <rakow@users.noreply.github.com>
  • Loading branch information
simei94 and rakow authored Apr 2, 2024
1 parent bc0b198 commit 543e2f7
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Integer call() throws Exception {
.sample(false)
.separator(CsvOptions.detectDelimiter(input.getPath("trips.csv"))).build());

// Trip filter with start and end
// Trip filter with start AND end
if (shp.isDefined() && filter == LocationFilter.trip_start_and_end) {
Geometry geometry = shp.getGeometry();
GeometryFactory f = new GeometryFactory();
Expand All @@ -153,6 +153,22 @@ public Integer call() throws Exception {
}
}

trips = trips.where(Selection.with(idx.toIntArray()));
// trip filter with start OR end
} else if (shp.isDefined() && filter == LocationFilter.trip_start_or_end) {
Geometry geometry = shp.getGeometry();
GeometryFactory f = new GeometryFactory();
IntList idx = new IntArrayList();

for (int i = 0; i < trips.rowCount(); i++) {
Row row = trips.row(i);
Point start = f.createPoint(new Coordinate(row.getDouble("start_x"), row.getDouble("start_y")));
Point end = f.createPoint(new Coordinate(row.getDouble("end_x"), row.getDouble("end_y")));
if (geometry.contains(start) || geometry.contains(end)) {
idx.add(i);
}
}

trips = trips.where(Selection.with(idx.toIntArray()));
}

Expand Down Expand Up @@ -404,6 +420,7 @@ private void writeTripPurposes(Table trips) {
*/
enum LocationFilter {
trip_start_and_end,
trip_start_or_end,
home,
none
}
Expand Down

0 comments on commit 543e2f7

Please sign in to comment.