geopandasr-tree

How to install libspatialindex without sudo right


My code is

from geopandas.tools import sjoin
ref_bts_adm = sjoin(Airport, ref_adm, how='left', op = 'within')

The error message

--------------------------------------------------------------------------
ImportError                              Traceback (most recent call last)
<ipython-input-10-5c31e9843a8a> in <module>
      1 from geopandas.tools import sjoin
----> 2 ref_bts_adm = sjoin(Airport, ref_adm, how='left', op = 'within')

~/.local/lib/python3.6/site-packages/geopandas/tools/sjoin.py in sjoin(left_df, right_df, how, op, lsuffix, rsuffix)
     87     _basic_checks(left_df, right_df, how, lsuffix, rsuffix)
     88 
---> 89     indices = _geom_predicate_query(left_df, right_df, op)
     90 
     91     joined = _frame_join(indices, left_df, right_df, how, lsuffix, rsuffix)

~/.local/lib/python3.6/site-packages/geopandas/tools/sjoin.py in _geom_predicate_query(left_df, right_df, op)
    171             # see discussion at https://github.com/geopandas/geopandas/pull/1421
    172             predicate = "contains"
--> 173             sindex = left_df.sindex
    174             input_geoms = right_df.geometry
    175         else:

~/.local/lib/python3.6/site-packages/geopandas/base.py in sindex(self)
   2628                [2]])
   2629         """
-> 2630         return self.geometry.values.sindex
   2631 
   2632     @property

~/.local/lib/python3.6/site-packages/geopandas/array.py in sindex(self)
    307     def sindex(self):
    308         if self._sindex is None:
--> 309             self._sindex = _get_sindex_class()(self.data)
    310         return self._sindex
    311 

~/.local/lib/python3.6/site-packages/geopandas/sindex.py in _get_sindex_class()
     20         return RTreeIndex
     21     raise ImportError(
---> 22         "Spatial indexes require either `rtree` or `pygeos`. "
     23         "See installation instructions at https://geopandas.org/install.html"
     24     )

ImportError: Spatial indexes require either `rtree` or `pygeos`. See installation instructions at https://geopandas.org/install.html

Basically I have similar error with this

ImportError: Spatial indexes require either `rtree` or `pygeos` in geopanda but rtree is installed

But I don't have sudo right


Solution

  • I had a similar issue and solved it by installing libspatialindex via spack, e.g., spack install libspatialindex (note: this installs the library in your homedir and does not require sudo privileges). Then you can pip install pygeos and rtree, as indicated in the other answers.