From 543e2f7bd6c7d87df2df5d5054516798618b7d53 Mon Sep 17 00:00:00 2001 From: simei94 <67737999+simei94@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:34:56 -0600 Subject: [PATCH] add trip filter for trip start OR end in shp area (#3198) Co-authored-by: rakow --- .../analysis/population/TripAnalysis.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java index bc656e79a2f..4c6da13627c 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java @@ -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(); @@ -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())); } @@ -404,6 +420,7 @@ private void writeTripPurposes(Table trips) { */ enum LocationFilter { trip_start_and_end, + trip_start_or_end, home, none }