[R-sig-Geo] "Merge" shapefiles
Tyler Frazier
tyler.j.frazier at icloud.com
Fri Nov 14 10:29:30 CET 2014
Not to belittle the spatial capabilities of R, but this sounds like a function that would be better addressed with PostgreSQL/postgis. Integrating r & pgsql can be a good combination.
Sent from my iPhone
> On Nov 14, 2014, at 1:11 AM, Steven Ranney <steven.ranney at gmail.com> wrote:
>
> 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]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list