I have two SpatialPolygonsDataFrames. One is the LSOA shapefile of Great Britain (i.e., Great Britain divided into ~41,000 regions with approximately equal population densities), the other is a bunch of regions in Great Britain (coal fields). I want to add the coal field info to the LSOA object, in order to have a variable added to the LSOA object that tells me whether an LSOA region falls into a coal field or not.
I got the shapefiles from here:
- LSOA regions: https://www.statistics.digitalresources.jisc.ac.uk/dataset/2011-census-geography-boundaries-lower-layer-super-output-areas-and-data-zones/resource-1
- Coal mines: https://data.gov.uk/dataset/coal-mining-reporting-area
This is how I attempted to do the merge:
# read in LSOA regions
LSOA <- readOGR(dsn = "Infuse", layer = "infuse_lsoa_lyr_2011")
# transform map to OSGB projection
bng = '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs'
LSOA.bng <- spTransform(LSOA,bng)
# read in coalmining regions:
coalmine <- readOGR(dsn = "coalmining_shapefiles", layer = "Coalfield_polygon")
# transform map to OSGB projection
coalmine.bng <- spTransform(coalmine,bng)
# merge data
coalmines.LSOA.over <- over(LSOA.bng, coalmine.bng)
LSOA.coalmines <- spCbind(LSOA.bng,coalmines.LSOA.over)
This is the error message I get after the spCbind command:
Error in spCbind(LSOA.bng, coalmines.LSOA.over) : row names not identical
What did I do wrong?