Open jejoenje opened 5 years ago
I keep meaning to take a look at this more carefully @jejoenje -- will try to help soon here.
Hi @jejoenje , apologies I don't know what it going on here, but based on the coding club today, Thiago is probably the best person to ask!
Hi all
Could someone help me with some R-based spatial analyses? I figure I must be doing something really simple wrong but I can't seem to work this out easily...
So, what I want to do is to calculate the extent of overlap of one polygon (or set of polygons) with another set of polygons. More specifically, I have species distribution maps and I want to calculate how much of each country a species occurs in (i.e. a value of 1 would mean it occurs in all of a given country, 0.5 it would occur in 50% of a country etc). In the simplest case, a species would consist of only a single polygon overlapping multiple country polygons. However, in many cases a species distribution consists of multiple (non-contiguous) polygons.
The first answer on this Stackexchange thread essentially seems to neatly illustrate the sort of problem thing I'm talking about and essentially gives me what I would need (area of overlap).
However, I don't seem to be able replicate this example with my "real" data (just as an example - Indian Pangolin). Here is my code (code and data in https://github.com/jejoenje/sp_poly_overlap):
In the example I've based this off, it does seem to work with two polygons in one set, and multiple ones in the other (i.e. it doesn't only calculate overlaps for the second of the "field" polygons... and I can't figure out why? Is this something to do with my species distribution data format?
Any thoughts greatly appreciated!