I have two sf multipolygon layers - one is a 5km buffer along the Mexico-US border and the other is an administrative 2-level layer of Mexico. I am trying to figure out how to layer these on top of one another and have the final product be one layer that can be visualized like this:

Ideal output -- geometry of buffer layer overlaying admin2 layer, and attributes of buffer layer overwriting those of the admin 2 layer

I have tried spatially joining with st_join, however this results in either just the border polygon with attributes from the admin 2 layer (listing buffer layer first) or in the admin 2 layer with buffer layer attributes. I am looking to get one layer with the polygons from both and attributes in overlapping areas to be defined by the buffer layer.

1 Answer 1


You can do this in two steps:

  1. Erase the area of the buffer from the administrative 2-level layer using the ST_Difference function.
  2. Add the buffer polygon to the resulted layer using the ST_Union function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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