I am using the gIntersects function from the rgeos package to check whether a river layer (polyline) intersects with a species maps (polygons). However, it is taking ages to do the calculations, despite I have simplified the layers with gSimplify and added prepared=TRUE to the function formula. Is there any way to improve the speed of the process?

  • Probably the best speed up is to migrate to using sf package instead of sp/rgeos. You can convert the objects with st_as_sf. The analogous function is sf::st_intersects – mdsumner Mar 20 '17 at 10:21
  • it seems that st_as_sf turns my files into tables, can I still do the sf_intersects with them? they have the coordinates in a column, but I don´t know if the program detects them as coordinates – Imanol Miqueleiz Mar 21 '17 at 9:04
  • You can, it's like sp but a bit different. See the sf vignettes for an overview. (The sp objects behaved mostly as-if they were data frames, but they weren't. The sf objects are data frames. ) – mdsumner Mar 21 '17 at 11:32
  • @Imanol Miqueleiz, did moving from sp to sf package functionality as @mdsumner suggested bring any improvement? I didn't find sf::st_intersects faster than rgeos::gIntersects so far. Maybe the only way to speed thing up would be executing things in parallel, e.g. foreach . Also, prepared=TRUE is the default in gIntersects, so no need to add it. – Valentin Sep 1 '17 at 21:37

Your Answer

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

Browse other questions tagged or ask your own question.