2

First I installed packages and such and set the working directory (example given)…

library(rgdal)
library(rgeos)
library(raster)
library(maptools)

setwd("V:/Water/GIS/"Shapefiles Intersected in R")

Then I read in shapefiles from computer folder - they are both of different polygon shapes of areas in NJ – example file pathways

munis <- readOGR("V:/water/GIS/Shapefiles to Intersect in RStudio/municipalities.shp", "municipalities")

streamsheds <- readOGR("V:/water/GIS/Shapefiles to Intersect in RStudio /streamsheds.shp", "streamsheds")

Then I intersect both shapefiles

munistreamsRInt <-intersect(munis,streamsheds)

Then I save the shp and view them in ArcGIS

writeOGR(obj=munistreamsRInt, dsn="Shapefiles Intersected in R", layer="munistreamsRInt", driver="ESRI Shapefile")

I used the same shapefile “munis” to intersect 4 different times with different shapefiles each time. So I did 4 different intersections. I did each intersection in R as well as in ArcGIS to compare. If “streamsheds” is shapefile 1, I did intersections between the following shapefiles:

  • Munis and shapefile 1
  • Munis and shapefile 2
  • Munis and shapefile 3
  • Munis and shapefile 4

The intersection with shapefile 1 was a perfect match visually, both the intersection in R and in ArcGIS were exactly the same when viewed. The attribute table data matched only after taking an additional step using the dissolve tool on the resulting shapefile of the intersection done in ArcGIS (afterwards both have 1497 rows).

The intersection with shapefile 2 done in R matched the intersect done in ArcGIS exactly. Both visually and in the attribute table. Without needing to use the Dissolve tool when doing it in ArcGIS.

The intersection with shapefile 3 and the intersection with shapefile 4 done in ArcGIS were not perfectly matched with the intersections in R even after I tried using the Intersect and Dissolve tools. Majority of the results are the same, except for a few differences in each:

The results of Munis and shapefile 3 done in R have 364 rows in the attribute table, and the one done in ArcGIS have 368 rows in the attribute table. The shapefiles intersected in R are missing 3 polygon shapes which can be seen in the ArcGIS intersected and dissolved shapefiles.

The results of Munis and shapefile 4 done in R have 944 rows in the attribute table, and the one done in ArcGIS have 943 rows in the attribute table. The resulting shapefile in R is missing 2 polygon shapes in the map (which can be seen in the ArcGIS shapefile) and the resulting shapefile in ArcGIS is also missing a different two shapefiles (which can be found in the R shapefile).

Anyone know what might be the issue and how to fix it? Thank you.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
08625
  • 21
  • 3

0 Answers0