Repository: mie-lab/trackintel
Pull request #477 (2023-06-27 13:39:36)

ENH: replace pygeos with calls to shapely 2.0
With pygeos being integrated into shapely we don't need this dependency anymore.
Thus this PR removes all calls to pygeos. 

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/mie-lab/trackintel/pull/477?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab) Report
Patch coverage: **`100.00`**% and project coverage change: **`-0.01`** :warning:
> Comparison is base [(`11ff487`)](https://app.codecov.io/gh/mie-lab/trackintel/commit/11ff487b1596d0da5f346446df0fd340df433210?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab) 92.35% compared to head [(`502959c`)](https://app.codecov.io/gh/mie-lab/trackintel/pull/477?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab) 92.35%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
- Coverage   92.35%   92.35%   -0.01%     
==========================================
  Files          39       39              
  Lines        2015     2014       -1     
  Branches      344      344              
==========================================
- Hits         1861     1860       -1     
  Misses        133      133              
  Partials       21       21              
```


| [Impacted Files](https://app.codecov.io/gh/mie-lab/trackintel/pull/477?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab) | Coverage Δ | |
|---|---|---|
| [trackintel/geogr/distances.py](https://app.codecov.io/gh/mie-lab/trackintel/pull/477?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab#diff-dHJhY2tpbnRlbC9nZW9nci9kaXN0YW5jZXMucHk=) | `94.56% <100.00%> (ø)` | |
| [trackintel/preprocessing/util.py](https://app.codecov.io/gh/mie-lab/trackintel/pull/477?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab#diff-dHJhY2tpbnRlbC9wcmVwcm9jZXNzaW5nL3V0aWwucHk=) | `100.00% <100.00%> (ø)` | |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/mie-lab/trackintel/pull/477?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab).

hongyeehh: Thanks for the fix. This is great; we shall push a new version soon and update the conda dependencies accordingly. 

Patch:
diff --git a/README.md b/README.md
index 303c7c5..748ed74 100644
--- a/README.md
+++ b/README.md
@@ -125,7 +125,6 @@ ti.print_version()
 * tqdm
 * OSMnx
 * similaritymeasures
-* pygeos
 
 ## Development
 You can find the development roadmap under `ROADMAP.md` and further development guidelines under `CONTRIBUTING.md`.
diff --git a/docs/conf.py b/docs/conf.py
index 9bde8b0..dec7f94 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -50,7 +50,6 @@ autodoc_mock_imports = [
     "geoalchemy2",
     "tqdm",
     "similaritymeasures",
-    "pygeos",
 ]
 
 
diff --git a/docs/environment.yml b/docs/environment.yml
index f326877..7590295 100644
--- a/docs/environment.yml
+++ b/docs/environment.yml
@@ -19,4 +19,3 @@ dependencies:
   - sphinx_rtd_theme
   - tqdm
   - similaritymeasures
-  - pygeos>=0.10.0
diff --git a/environment.yml b/environment.yml
index 43655c1..3fa07df 100644
--- a/environment.yml
+++ b/environment.yml
@@ -16,4 +16,3 @@ dependencies:
 - psycopg2
 - tqdm
 - similaritymeasures
-- pygeos>=0.10.0
diff --git a/requirements.txt b/requirements.txt
index e4de600..b3889e8 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,5 +9,4 @@ osmnx
 psycopg2
 tqdm
 similaritymeasures
-pygeos>=0.10.0
 virtualenv
diff --git a/setup.py b/setup.py
index 19fbf22..17c7628 100644
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,6 @@ REQUIRED = [
     "scikit-learn",
     "tqdm",
     "similaritymeasures",
-    "pygeos>=0.10.0",
 ]
 
 install_requires = [
@@ -49,7 +48,6 @@ install_requires = [
     "tqdm",
     "geopandas>=0.10.0",
     "similaritymeasures",
-    "pygeos>=0.10.0",
 ]
 
 # What packages are optional?
diff --git a/trackintel/geogr/distances.py b/trackintel/geogr/distances.py
index eb7bc4b..47b30c6 100644
--- a/trackintel/geogr/distances.py
+++ b/trackintel/geogr/distances.py
@@ -5,10 +5,10 @@ from math import cos, pi
 
 import numpy as np
 import pandas as pd
-import pygeos
+import shapely
+import similaritymeasures
 from scipy.spatial.distance import cdist
 from sklearn.metrics import pairwise_distances
-import similaritymeasures
 
 from trackintel.geogr.point_distances import haversine_dist
 
@@ -250,9 +250,9 @@ def calculate_haversine_length(gdf):
     >>> from trackintel.geogr.distances import calculate_haversine_length
     >>> triplegs['length'] = calculate_haversine_length(triplegs)
     """
-    geom = pygeos.from_shapely(gdf.geometry)
-    assert np.any(pygeos.get_type_id(geom) == 1)  # 1 is LineStrings
-    geom, index = pygeos.get_coordinates(geom, return_index=True)
+    geom = gdf.geometry
+    assert np.any(shapely.get_type_id(geom) == 1)  # 1 is LineStrings
+    geom, index = shapely.get_coordinates(geom, return_index=True)
     no_mix = index[:-1] == index[1:]  # mask where LineStrings are not overlapping
     dist = haversine_dist(geom[:-1, 0], geom[:-1, 1], geom[1:, 0], geom[1:, 1])
     return np.bincount((index[:-1])[no_mix], weights=dist[no_mix])
diff --git a/trackintel/preprocessing/util.py b/trackintel/preprocessing/util.py
index 07a777b..1339cbf 100644
--- a/trackintel/preprocessing/util.py
+++ b/trackintel/preprocessing/util.py
@@ -3,7 +3,7 @@ from datetime import timedelta
 import geopandas as gpd
 import numpy as np
 import pandas as pd
-import pygeos
+import shapely
 from joblib import Parallel, delayed
 from shapely.geometry.base import BaseGeometry
 from tqdm import tqdm
@@ -127,8 +127,7 @@ def angle_centroid_multipoints(geometry):
     geopandas.GeometryArray
         Centroid of geometries (shapely.Point)
     """
-    g = pygeos.from_shapely(geometry)
-    g, index = pygeos.get_coordinates(g, return_index=True)
+    g, index = shapely.get_coordinates(geometry, return_index=True)
     # number of coordinate pairs per MultiPoint
     count = np.bincount(index)
     x, y = g[:, 0], g[:, 1]


Test patch:
diff --git a/.github/envs/39-latest-conda-forge.yaml b/.github/envs/39-latest-conda-forge.yaml
index 57d86f4..1a3b9e7 100644
--- a/.github/envs/39-latest-conda-forge.yaml
+++ b/.github/envs/39-latest-conda-forge.yaml
@@ -19,7 +19,6 @@ dependencies:
 - similaritymeasures
 - jupyter
 - geopandas>=0.10.0
-- pygeos>=0.10.0
 
 # tests
 - pytest