MAINT: unify spatial index error handling
See original GitHub issueCurrently, there is no unified approach to error handling for empty spatial indexes or lack of a spatail index backend:
- sjoin does it’s own check for rtree, this means you need rtree even if you have pygeos!
- overlay and clip do not do any checks, they would fail with something like
None does not have any attribute query_bulk
, which is not very helpful.
Further, when you create a spatial index, if:
- The spatial index is empty,
GeoDataFrame.sindex
gets set to None - There is not spatial index backend,
GeoDataFrame.sindex
gets set to None and a warning is raised.
I don’t particularly like that handling. There is no way to tell what happened, aside from a warning.
I would like to propose the following:
- No modules outside of
sindex
shall check for a spatial index backend. They should just blindly try to access thesindex
property. - The
sindex
backends should be instantiated even with no geometries, and should have a__len__
property that reports 0 when empty (this preserves theif gdf.sindex:
syntax used in some modules). - In the case of no spatial index backend, a clear error should be raised by `sindex.*
* Currently, the error is raised only when a property of the spatial index is accessed (sindex.intersection
). There are two options with this:
- Preserve the current behavior, but make the error more useful. This would require setting
GeoDataFrame.sindex
to some non-None value, perhaps a dummy class that raises a user friendly error if any of its methods (query
,query_bulk
, etc.) are accessed and always reports alen
of 0. The big con of this approach is complexity. We’d have to make a dummy class, etc. - Raise an error when
GeoDataFrame.sindex
is accessed. This is the lower complexity approach, we just replace what is currently a warning with an error. It would however require either atry/except
block or an import ofgeopandas.sindex.has_sindex
by other modules to handle this error if they want to operate without a spatial index. Currently, all modules that use a spatial index cannot operate without a spatial index, so they would actually not need to do anything.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Problem: Unable to merge feature classes using the Merge tool
This error usually indicates that there are inconsistencies in the spatial index grid values of the feature classes to be merged.
Read more >Error handling with sync—ArcGIS REST APIs
This topic discusses error cases when using the feature service's createReplica and synchronizeReplica operations. This includes errors and failures due to ...
Read more >Are unfixable spatial index corruptions considered normal?
4427.24 (SQL Server 2014 SP1 CU3). I scripted the table with schema and data, fresh DB, execute. Same error. CHECKDB also has this...
Read more >5 Indexing and Querying Spatial Data - Oracle Help Center
After you have loaded spatial data , you should create a spatial index on it to enable efficient query performance using the data....
Read more >Optimize index maintenance to improve query performance ...
This article describes index maintenance concepts, and a recommended strategy to maintain indexes.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A deprecation warning seems fine to me. So:
None
, in the future will be set to a spatial index instance withlen == 0
.👍
Conflating
None
as an indicator of an empty spatial index with a missing backend is not at all ideal here. Unmet dependencies should raise errors.A deprecation period seems fine for this, in which case it would be good to get the deprecation warning into 0.8.0.