Repository: mie-lab/trackintel (language: python)

Issue:
pygeos for trackintel
pygeos is a package that vectorizes the geometry in GeoPandas using Cython. It is maintained basically by the same people that maintain geopandas. As such they've implemented a lot of functions in geopandas to run faster if pygeos is installed. That would give us a free speedup and further allow us to use vectorized functions on geometryArrays similar to ufunc on numpy arrays. 

Further informations:
- https://jorisvandenbossche.github.io/blog/2017/09/19/geopandas-cython/
- https://github.com/pygeos/pygeos

One use case would be the generation of points out of longitude and latitude. Instead of using the relatively slow `.apply(Points)` we can use directly on arrays `pygeos.points(x, y)`. 
This way we get the following times on my laptop.

Preparation
````python
import numpy as np
import pandas as pd
from shapely.geometry import Point

a = np.arange(100_000)
b = np.arange(100_000, 200_000)
df = pd.DataFrame({"a": a, "b": b})
````

`pygeos`
````python
%timeit pygeos.points(df["a"], df["b"])
57.4 ms ± 4.71 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
````

Our way so far
````python
%%timeit
df["geom"] = list(zip(df["a"], df["b"]))
df["geom"] = df["geom"].apply(Point)
1.08 s ± 31 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
````



Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index b1f8b604..25d3f4b0 100644
--- a/README.md
+++ b/README.md
@@ -116,6 +116,7 @@ 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 5946bc48..8ec69096 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -50,6 +50,7 @@
     "geoalchemy2",
     "tqdm",
     "similaritymeasures",
+    "pygeos",
 ]
 
 
diff --git a/docs/environment.yml b/docs/environment.yml
index 1392606b..9957364f 100644
--- a/docs/environment.yml
+++ b/docs/environment.yml
@@ -19,3 +19,4 @@ dependencies:
   - sphinx_rtd_theme
   - tqdm
   - similaritymeasures
+  - pygeos
diff --git a/environment.yml b/environment.yml
index 775c6bdb..e13e8f79 100644
--- a/environment.yml
+++ b/environment.yml
@@ -17,3 +17,4 @@ dependencies:
 - psycopg2
 - tqdm
 - similaritymeasures
+- pygeos
diff --git a/requirements.txt b/requirements.txt
index 3297999c..fe00f6db 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,4 +9,5 @@ geoalchemy2
 osmnx 
 psycopg2
 tqdm
-similaritymeasures
\ No newline at end of file
+similaritymeasures
+pygeos
\ No newline at end of file
diff --git a/setup.py b/setup.py
index bc20126d..98a920f4 100644
--- a/setup.py
+++ b/setup.py
@@ -33,6 +33,7 @@
     "scikit-learn",
     "tqdm",
     "similaritymeasures",
+    "pygeos",
 ]
 
 install_requires = [
@@ -48,6 +49,7 @@
     "tqdm",
     "geopandas",
     "similaritymeasures",
+    "pygeos",
 ]
 
 # What packages are optional?


Test patch:
diff --git a/ci/envs/37-latest-conda-forge.yaml b/ci/envs/37-latest-conda-forge.yaml
index 016279db..5a64500a 100644
--- a/ci/envs/37-latest-conda-forge.yaml
+++ b/ci/envs/37-latest-conda-forge.yaml
@@ -20,4 +20,5 @@ dependencies:
 - pytest-xdist
 - tqdm
 - similaritymeasures
+- pygeos
 - jupyter
diff --git a/ci/envs/38-latest-conda-forge.yaml b/ci/envs/38-latest-conda-forge.yaml
index 40c036ef..e3896e52 100644
--- a/ci/envs/38-latest-conda-forge.yaml
+++ b/ci/envs/38-latest-conda-forge.yaml
@@ -20,4 +20,5 @@ dependencies:
 - pytest-xdist
 - tqdm
 - similaritymeasures
+- pygeos
 - jupyter
diff --git a/ci/envs/39-latest-conda-forge.yaml b/ci/envs/39-latest-conda-forge.yaml
index 814ac7c5..488da4e8 100644
--- a/ci/envs/39-latest-conda-forge.yaml
+++ b/ci/envs/39-latest-conda-forge.yaml
@@ -20,4 +20,5 @@ dependencies:
 - pytest-xdist
 - tqdm
 - similaritymeasures
+- pygeos
 - jupyter