1

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.

1

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.

  • 1
    You assume correctly. The resulting file should be a polygon file with the attributes from all of the corresponding points, including those where 2 or more points fall within the same polygon. The polygons inherit the info of the points. This task is not a priority for me right now but at I will test your suggestion at some point and confirm the result. – Adam G Dec 20 '18 at 9:12
  • Hi @AdamG, if that is what you want, then st_join should work. Know that it will duplicate those polygons that overlap with more than one point in order to have one row with the info of the overlapping points. This might require attention in following analyses (e.g. careful with when you calculate the total areas of the polygons, for example). – Pablo Herreros Cantis Dec 23 '18 at 12:50
  • Thanks @Pablo. This worked a treat. I've posted a follow-up question which you may also be able to answer: gis.stackexchange.com/questions/320841/… – Adam G Apr 25 at 13:03
  • Hi @AdamG! I will check it for sure. If it worked, I would enormously appreciate if you could mark this as the correct answer. Thank you! – Pablo Herreros Cantis Apr 26 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.