I am trying to recreate the suggestion from this link but instead of using it on a sPolygondf, to do the same for a sPointdf. All is well, but I get an unexpected output - when I do the difference between my one point feature and the other I get a result of X (59104); when I do the same for the attribute information in order to join these and create a sPointdf for later steps I get a result of Y (59488).
Can anyone explain why this is so?
Code:
#------load data
cities_nl <- readOGR('/home/iordamo/Documents/GIS_Workload/DutchCities/allcities_dis.shp')
imgs <- readOGR('/home/iordamo/Documents/GIS_Workload/DutchAgriculturalParcels/mapillary-public.geojson')
#------selection
imgs <- spTransform(imgs, '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs')
imgsdf <- data.frame(imgs)
imgs_in <- imgs[cities_nl,]
imgs_indf <- data.frame(imgs_in)
imgs_out <- gDifference(imgs, imgs_in)
imgs_outdf <- setdiff(imgsdf, imgs_indf)
> nrow(imgs_outdf)
[1] 59488
> imgs_out
class : SpatialPoints
features : 59104
So in the case of the spatial operations I am using the gDifference function from the rgeos package and in the other the setdiff from the dplyr package. To my mind these should result in the same number of features in the end.
imgs_out <- subset(imgs, ! imgs@data$key %in% imgs_in@data$key). Thekeyvariable of in the dataset is unique and can thus be used to do indexing. Thank you for the suggestion though, I will look through your package in the future when I have more time. – Momchill Jul 24 '18 at 07:54