I have carried out a spatial join in R in order to join a points shapefile to the corresponding polygon in a polygon shapefile using over() from the sp package and spCbind().
join <- over(polygons, points)
join <- spCbind(polygons, join)
However, some of the polygons have multiple corresponding points. Using this method, only one of these corresponding points is maintained in the joined dataset.
Is there a method for carrying out this task that will keep the data of all of the corresponding points for each polygon in the resulting dataset?
I would prefer an R solution if possible but I can also use QGIS or ArcGIS if they have tools to solve this.
Answer
Not super sure of what you want, but I will assume that what you want is to perform a spatial join in which each entity of one layer captures the attributes of another one.
I recommend you use the sf
package, which deals with shapefiles as both simple features (spatial) and as data-frames, allowing to deal with spatial data in a very comfortable way.
In this package, you can explore the st_join
function. by default, this option will duplicate the entities that overlap with more than one of the entities of the layer to join. Which means that if you have one polygon that overlaps with two points, and you want the polygon to spatially inherit the information of the point, you will obtain an object in which the polygon has been duplicated, and each row presents the info of the polygon plus each of the joined points.
Finally, it is not clear if you want to join the info of the polygons to the points, or the points to the shapefiles
. (polygon, points) will make the polygons inherit the info of the points.
No comments:
Post a Comment