Repository: mie-lab/trackintel

Issue:
ENH: Enable `generate_trips` for `Staypoints`
`generate_trips` function need staypoints and triplegs as argument. I would find it coherent to add a `generate_trips` method to `Staypoints` as well and not only to `Triplegs`

Comments:

Patch:
diff --git a/README.md b/README.md
index 0afb7c7..e729d60 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ The image below explicitly shows the definition of **locations** as clustered **
 You can enter the *trackintel* framework if your data corresponds to any of the above mentioned movement data representation. Here are some of the functionalities that we provide: 
 
 * **Import**: Import from the following data formats is supported: `geopandas dataframes` (recommended), `csv files` in a specified format, `postGIS` databases. We also provide specific dataset readers for popular public datasets (e.g, geolife).
-* **Aggregation**: We provide functionalities to aggregate into the next level of our data model. E.g., positionfixes->staypoints; positionfixes->triplegs; staypoints->locations; staypoints+triplegs->trips; trips->tours
+* **Aggregation**: We provide functionalities to aggregate into the next level of our data model. E.g., positionfixes&rarr;staypoints; positionfixes&rarr;triplegs; staypoints&rarr;locations; staypoints+triplegs&rarr;trips; trips&rarr;tours
 * **Enrichment**: Activity semantics for staypoints; Mode of transport semantics for triplegs; High level semantics for locations
 
 ## How it works
@@ -58,9 +58,9 @@ import geopandas as gpd
 import trackintel as ti
 
 # read pfs from csv file
-pfs = ti.io.file.read_positionfixes_csv(".\examples\data\pfs.csv", sep=";", index_col="id")
+pfs = ti.io.read_positionfixes_csv(".\examples\data\pfs.csv", sep=";", index_col="id")
 # or with predefined dataset readers (here geolife) 
-pfs, _ = ti.io.dataset_reader.read_geolife(".\tests\data\geolife_long")
+pfs, _ = ti.io.read_geolife(".\tests\data\geolife_long")
 ```
 
 **[2.]** Data model generation. 
diff --git a/trackintel/model/staypoints.py b/trackintel/model/staypoints.py
index f5c97b1..1fc7286 100644
--- a/trackintel/model/staypoints.py
+++ b/trackintel/model/staypoints.py
@@ -154,3 +154,13 @@ class Staypoints(TrackintelBase, TrackintelGeoDataFrame):
         See :func:`trackintel.analysis.temporal_tracking_quality` for full documentation.
         """
         return ti.analysis.tracking_quality.temporal_tracking_quality(self, granularity=granularity)
+
+    def generate_trips(self, triplegs, gap_threshold=15, add_geometry=True):
+        """
+        Generate trips based on staypoints and triplegs.
+
+        See :func:`trackintel.preprocessing.generate_triplegs` for full documentation.
+        """
+        return ti.preprocessing.triplegs.generate_trips(
+            self, triplegs, gap_threshold=gap_threshold, add_geometry=add_geometry
+        )


Test patch:
diff --git a/tests/preprocessing/test_triplegs.py b/tests/preprocessing/test_triplegs.py
index af99006..31448aa 100644
--- a/tests/preprocessing/test_triplegs.py
+++ b/tests/preprocessing/test_triplegs.py
@@ -122,7 +122,7 @@ class TestGenerate_trips:
 
             assert correct_dest_point == dest_point_trips
 
-    def test_accessor(self, example_triplegs):
+    def test_accessor_triplegs(self, example_triplegs):
         """Test if the accessor leads to the same results as the explicit function."""
         sp, tpls = example_triplegs
 
@@ -137,6 +137,21 @@ class TestGenerate_trips:
         assert_geodataframe_equal(sp_expl, sp_acc)
         assert_geodataframe_equal(tpls_acc, tpls_expl)
 
+    def test_accessor_staypoints(self, example_triplegs):
+        """Test if the accessor leads to the same results as the explicit function."""
+        sp, tpls = example_triplegs
+
+        # generate trips using the explicit function import
+        sp_expl, tpls_expl, trips_expl = ti.preprocessing.triplegs.generate_trips(sp, tpls, gap_threshold=15)
+
+        # generate trips using the accessor
+        sp_acc, tpls_acc, trips_acc = sp.as_staypoints.generate_trips(tpls, gap_threshold=15)
+
+        # test if generated trips are equal
+        assert_geodataframe_equal(trips_expl, trips_acc)
+        assert_geodataframe_equal(sp_expl, sp_acc)
+        assert_geodataframe_equal(tpls_acc, tpls_expl)
+
     def test_generate_trips_missing_link(self, example_triplegs):
         """Test nan is assigned for missing link between sp and trips, and tpls and trips."""
         sp, tpls = example_triplegs