I want to perform a spatial join (one-to-many relation) between two Spatial Dataframe layers in R. More specifically, I have a set of lines (SpatialLinesDataframe) that need to be joined to the ID of a neighborhood (SpatialPolygonsDataframe) if they overlap with it.

I tried using the over function (as indicated below) and get the following error:

over.list <- over(lines, neighorhood, returnList = TRUE)

Error in RGEOSBinPredFunc(spgeom1, spgeom2, byid, func) : rgeos_binpredfunc_prepared: maximum returned dense matrix size exceeded

I presume this is due to the size of the sp objects (475365 and 170045, respectively). What is the best approach to go about doing this?

  • 1
    Have you tried doing it with a subset of your data in order to test your presumption? – Spacedman Jun 8 '20 at 19:16
  • Hi! I did and it worked. But I need an approach that can scale to large spatial data frames. I managed to resolve the issue using sf (see below). But I am curious to see if there is a way to approach this issue using sp. #join streets and neighborhoods inter_sf <- st_join(lines_sf, neigh_sf) #leave only streets that overlap with neighborhoods streets_sub_sf <- inter_sf[neigh_sf, ] – tinker Jun 8 '20 at 22:50
  • IMO, I'd switch to sf instead of using sp since sf is more up to date and mostly faster! – GISKid Jun 11 '20 at 23:50

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.