I'm putting together some training materials for a workshop on R for spatial data analysis in archaeology, and need to anonymize the true site locations (confidential information) while keeping the spatial integrity of the features within the site's bounding box.
My initial thought is to subtract the minimum X & Y values of the bounding box (all are in UTM coords) from all of the geometries — i.e., make the whole thing an arbitrary relative grid.
I have ESRI point and polygon shapefiles imported to R with sf
, and some rasters loaded with terra
but not sure how to go about doing the global spatial adjustment for either.
I also use QGIS, so some solution through there to pre-process the geometries before loading to R would work as well — but again, don't know how to do that.
Best Answer
There's a function in the
maptools
package calledelide
that is designed to shift and rotate spatial data. It can also flip, reflect, and rotate vector data, but it might be hard to do the equivalent operation on raster data in the same locations.Disguising the real location of data is its raison d'etre:
At the moment it only works on
sp
class objects, but you can do a conversion step and use it.Example, given an
sf
data frame with geometry:I can create a shifted version:
Note this has shifted it so that one particular vertex of the first polygon is at roughly (0,0). Pick your shift values however you wish.
This works with points, lines, and polygon
sf
objects.For
terra
raster objects, you can use theshift
function:Note change of extent when shifted: