0

I have a set of SpatialDataFrames, both Lines and Polygons. I would like to find the lines/polygons where they overlap. Ultimate goal is to keep all overlaps (preferably with data included) and remove the not-overlapping polygons. The users should be able to see which polygons do overlap and can take action.

I am hoping you can give me a little push to complete this task. Thanks!

Preferably it is showed on leaflet. If that’s too difficult a dataframe with overlapping data will work too.

I have tried using st_intersection, which gives me error ‘no applicable method for ‘st_intersection’… and using gIntersects(spgeom1, spgeom2) which gives me results in TRUE/FALSE format. With some editing I can get the results in row (spgeom2) and col (spgeom1) format. But that’s it…

spdf1 = geojsonio::geojson_read("C:/Users/folder/json/data1.json", what = "sp")
spdf2 = geojsonio::geojson_read("C:/Users/folder/json/data2.json", what = "sp")
spdf3 = geojsonio::geojson_read("C:/Users/folder/json/data3.json", what = "sp")

sp1sp2 = gIntersect(spgeom1, spgeom2, byid = TRUE)
dfoverlaps = as.data.frame(sp1sp2)
overlaps = which(dfoverlaps == “TRUE”, arr.ind = TRUE)
camille
  • 16,432
  • 18
  • 38
  • 60
  • 1
    Are you mixing up different object types? If you're calling `sf::st_intersection` on non-`sf` objects, that might get you a "no applicable method" error. Different intersection functions will return different types of information: matrix of which polygons do or don't intersect, spatial data containing the intersection shapes themselves, etc. Beyond that, you'll need a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for folks to give more specific help – camille Aug 26 '19 at 13:09
  • also perhaps the `gUnion()` function could be of use? https://www.rdocumentation.org/packages/rgeos/versions/0.5-1/topics/gUnion – Amit Kohli Aug 26 '19 at 13:12
  • The ```overlay()``` function in the sp package allows you to identify spatial overlaps between two spatial objects https://www.rdocumentation.org/packages/sp/versions/0.9-7/topics/overlay – Dominix Aug 26 '19 at 13:17
  • Use `gIntersection` rather than `gIntersects`. – Edzer Pebesma Aug 26 '19 at 19:27
  • if you are using `sf` objects, then `sf::st_read()` will read the `.json` files directly into sf objects. – SymbolixAU Aug 28 '19 at 00:07

0 Answers0