From 08e13675eb6cc557dee9c50015fbec2a75f54d9e Mon Sep 17 00:00:00 2001 From: BRAUN REMI Date: Tue, 17 Dec 2024 15:48:05 +0100 Subject: [PATCH] OPTIM: Compute the spatial index by default in `vectors.read` (set `vectors.read(..., compute_sindex=False)` if you don't want to compute them) --- CHANGES.md | 1 + sertit/vectors.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0f9ef78..4b95635 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ - **ENH: Use `pyproject.toml` instead of `setup.py`** - FIX: Fix too broad exception in case of `geopandas >= 1.0` - FIX: Fix deprecation warning for `get_nodata_value_from_dtype` in `rasters_rio` +- OPTIM: Compute the spatial index by default in `vectors.read` (set `vectors.read(..., compute_sindex=False)` if you don't want to compute them) ## 1.44.1 (2024-12-12) diff --git a/sertit/vectors.py b/sertit/vectors.py index 9b214b2..15074e8 100644 --- a/sertit/vectors.py +++ b/sertit/vectors.py @@ -425,6 +425,7 @@ def read( In case of an iterable, assumption is made it corresponds to geographic bounds. Mimics :code:`rasters.read(..., window=)`. If given, :code:`bbox` is ignored. **kwargs: Additional arguments used in gpd.read_file. You can also give :code:`file_list`, the list of files of the archive to get the vector from, as this operation is expensive when done with large archives stored on the cloud. + You can also set :code:`compute_sindex=False` to avoid computing the spatial index of the vector. Returns: gpd.GeoDataFrame: Read vector as a GeoDataFrame @@ -512,6 +513,10 @@ def read( vect.attrs["path"] = str(vector_path) vect.attrs["name"] = path.get_filename(vector_path) + # Generate spatial index for optimization + if kwargs.get("compute_sindex", True) and not vect.has_sindex: + vect.sindex # noqa + return vect