# 如何控制添加到R中x，y空间点的噪声量？

...因为当我使用ArcGIS遵循该问题的答案的指示时，我得到了一系列随机点，但是却失去了与这些点相关的属性，因此我不容易找到一种方法将它们进行备份。

``````mydf <- data.frame("point_id" = 1:6, "date_time" = c("6/5/2018 10:57","6/5/2018 14:30","6/6/2018 10:06","6/6/2018 11:06","6/7/2018 10:35","6/7/2018 15:50"), "Animal_ID" = c(4,5,4,5,4,6), "Rock_ID" = c(1,2,1,3,4,5), x_proj = c(831120.3759,831441.0415,831120.3759,831433.4414,831128.4778,831422.0822), y_proj = c(5877582.998,5875337.074,5877582.998,5875328.897,5877575.360,5875338.216))

#make a separate object for the coordinates#
xy <- mydf[,c(5,6)]

#Convert to a spatialpoints data frame (insert own epsg)
sp.mydf <- SpatialPointsDataFrame(coords = xy, data = tumbling_test, proj4string = CRS("+init=epsg:xxxxx"))

``````

``````library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3
library(tidyverse)

# load example data
nc <- read_sf(system.file('gpkg/nc.gpkg', package = 'sf'))

#make single points from polygons
nc_points <- st_centroid(nc)
#> Warning in st_centroid.sf(nc): st_centroid assumes attributes are constant over
#> geometries of x
#> Warning in st_centroid.sfc(st_geometry(x), of_largest_polygon =
#> of_largest_polygon): st_centroid does not give correct centroids for longitude/
#> latitude data

# Transform to a crs that uses meters as the distance
nc_points <- st_transform(nc_points, 3358)

nc_points_jittered <- st_jitter(nc_points, amount = 5000)

p1 <- ggplot(nc_points) +
geom_sf() +
ggtitle('Original')

p2 <- ggplot(nc_points_jittered) +
geom_sf() +
ggtitle('Jittered')

p3 <- ggplot() +
geom_sf(data = nc_points, color = 'red') +
geom_sf(data = nc_points_jittered, color = 'black') +
ggtitle('Both')

cowplot::plot_grid(p1, p2, p3, ncol = 1)
``````

reprex软件包（v0.3.0）创建于2020-01-12

0条评论