1

When I try to make an intersection between two Geodataframes in google colab, I get it the next error message:

enter image description here

This is my pace of code:

link1 = 'https://drive.google.com/open?id=10OXg2zhFp9Dhxqz_4mXqw4R16_13VoMv'
wdir, id = link1.split('=')
id

downloaded = drive.CreateFile({'id':id}) 
downloaded.GetContentFile('Forest_zone.geojson')
print('The files was downloaded')

forest_zone = gpd.read_file('Forest_zone.geojson')

link2 = 'https://drive.google.com/open?id=1t5b5aUfVrOh3e5uBylmbVaXsBshc6l6f'
wdir, id = link2.split('=')
id

downloaded = drive.CreateFile({'id':id}) 
downloaded.GetContentFile('Study_area.geojson')
print('The files was downloaded')

study_area = gpd.read_file('Study_area.geojson')

inter = gpd.overlay(forest_zone, study_area, how='intersection')

if you wanna see all notebook for helping me, this is the link of my current notebook: https://colab.research.google.com/drive/1kTba6gqc5yDj_a3AhgwOIV3LUXG18Frs

  • The error message indicates that the rtree module is not installed – gene Oct 3 at 18:51
  • Can you post the error as formatted text so it is searchable for users? – MrXsquared Oct 3 at 18:51
  • Yes I can, I make a few changes on this post, I hope that works for yours – Juan Pablo Cuevas Oct 4 at 3:54
1

It is not a problem of Google colad, but, as I said in my comment, you must install rtree.

warn("Cannot generate spatial index: Missing package `rtree`.")

Look at Overlay Function from GeoPandas Not Working

To be able to use the overlay function you need more than just install geopandas, you need install rtree, but rtree is a wrapper to the C library libspatialindex. So to use rtree library you need to install libspatialindex C library.

In GeoPandas: install

Warning
When using pip to install GeoPandas, you need to make sure that all dependencies are installed correctly.
....
rtree does not provide wheels.
....

Therefore you cannot install rtree with pip and you must choose another method, independently of GeoPandas (Rtree installation)

And

inter = gpd.overlay(forest_zone, study_area, how='intersection')
print(inter.head())
   st_area_sh      cod_dane  ...     departamen           geometry
0  717156560.907    73001    ...      TOLIMA  POLYGON ((-75.33499022858835 4.66015859992620...
1   1227.8963508    73001    ...      TOLIMA  POLYGON ((-75.27023446072464 4.443991322020056...
2   184060.36275    73001    ...      TOLIMA  POLYGON ((-75.18259468247429 4.379858423561434...
3  129158.354723    73001    ...      TOLIMA  POLYGON ((-75.29231944063352 4.471500289298558...
4  45861.4469718    73001    ...      TOLIMA  POLYGON ((-75.23275926314781 4.50074008924839,...
  • yes is very interesting your explain... but, when I use this code into google colab: !easy_install Rtree !sudo apt-get update && apt-get install -y libspatialindex-dev. I still getting the error: warn("Cannot generate spatial index: Missing package rtree.") – Juan Pablo Cuevas Oct 5 at 15:59
  • Use the explications of Rtree installation.: install libspatialindex first, then rtree – gene Oct 5 at 19:03
  • Thank you the explain it works. This is I notebook that I founded... do you think that the code was made in the right way... or you see any mistake? colab.research.google.com/drive/… – Juan Pablo Cuevas Oct 6 at 1:11
  • If it works, no problem – gene Oct 6 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.