1

I am new to GIS and GIS in R. I have two Spatial Polygon Data Frames (spdf), one contains the marine ecoregions of the world (MEOW), the other one contains Exclusive Economic Zones (EEZ) of the world. I want to find which polygons of this two spdf's overlaps (I am not sure about the term, what I mean is, if two polygons from the two spdf's share a common area, I want to find the names of those two polygons).

I imported two spdf's with readOGR function, then I tried st_intersects() and gIntersection() functions but it did not work for me.

How can I reach my goal?

Is there a function or package that handles a situation such as this?

1
  • what output are you looking for? a list, a column in the data frame where it says the name of the overlapping region? you say you were not looking for the intersecting area. You may as well read and use functions from package sf (read_sf(your_file.gpkg) and st_intersects(a_df, b_df) for instance.
    – Elio Diaz
    Jan 22, 2021 at 2:46

1 Answer 1

1

For GIS analysis in R I recommend the sf package. One of the great advantages of this package is that, once you loaded a file into your enviroment with read_sf(), you can manipulate your data using the regular data.frame methods commonly used in R.

# read your data into your environment, make sure your data is stored in your working directory
meow <- read_sf("meow_ecos.shp")
eez <- read_sf("eez_v11.shp")

Once loaded in, you will see that meow has 232 observations and 10 variables, while eez has 281 observations and 32 variables. st_intersection, the tool that will allow you to get the overlapping areas, will add the variables of the two objects together. So, you will have 42 variables for every polygon in your intersection-object. It's handy to determine which variables you are interested in beforehand. (if you want to keep all of them, it's fine). Let's say we want to keep only the variable PROVINCE from meow, and the first 5 variables from eez.

# subset meow and eez
meowprov <- subset(meow, select = PROVINCE)
eezfirst5 <- eez[, c(1-5)]

Before you can start your intersection analysis, you should check whether the coordinate reference systems are equal. When they are not equal, it will cause an error.

#make sure your coordinate systems projections are equal.
st_crs(meowprov) == st_crs(eezfirst5)

This returns True, so we can continue. Now, since your EEZ file is large, you'll have to be patient doing the intersection.

# apply your intersection
meow_eez_intersection <- st_intersection (meowprov, eezfirst5) 

After a lot of waiting, I got meow_eez_intersection in my environment with 701 observations.

3
  • Hi saQuist. This definitely did the trick. All I had to do was to extract the columns from meow_eez_intersection. Thank you for your incredible help. Jan 24, 2021 at 0:13
  • Hi Ekin, I'm glad it helped. If any answer to your question solved your problem, you could consider accepting it by clicking the check-mark (✓) next to the answer. This indicates to the wider community that you've found a solution and your question won't be displayed on the "unanswered"-section of the website anymore. Accepting an answer gives some reputation to both the answerer and yourself. There is no obligation to do this.
    – saQuist
    Jan 25, 2021 at 16:16
  • Of course, again, thank you so much. Jan 27, 2021 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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