[R-sig-Geo] "Merge" shapefiles

Steven Ranney steven.ranney at gmail.com
Fri Nov 14 01:11:36 CET 2014


All -

I am slowly learning more about spatial data in R.  However, I am still a
relative neophyte.

What I want to do:

I have two shapefiles, shpA has ~401,000 individual polygons with
attributes.  shpB is a subset of those polygons with different attribute
data.  Even though shpB is a subset of those data, there may be multiple
rows for a given polyon, thus giving shpB more total rows (~780,000).

Effectively, I want to merge these two shapefiles.  With two dataFrame
objects in R, I would merge them like

merge(shpA, shpB, by = "APN_LABEL", all = TRUE)

but apparently, this doesn't work with shapefiles.  I have tried

merge(shpA at data, shpB at data, by = "APN_LABEL", all = TRUE)

which creates a dataFrame of the the two files but drops all of the spatial
geometries.

I've looked into gUnion() as it seems like that may be what I'm looking
for, but I get the following error:

tmp <- gUnion(shpA, shpB)
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td,
"rgeos_union") :
  std::bad_alloc

Ultimately, I want a shapeFile of all ~401,000 geometries in shpA that
includes ALL of the attribute data from shpB that may exist in multiple
rows for a given polygon.

Is this possible?  Is this simple?

Steven H. Ranney

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list