0

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.

link to datasets

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Momchill
  • 284
  • 2
  • 9
  • There is an erase points function in the spatialEco package. – Jeffrey Evans Jul 23 '18 at 21:56
  • I am not sure whether it covers the same problem, as I do not want to erase points outside the polygon, but the ones inside. In any occasion, I could not install the package you provided, but ended up finding the solution in the simplest things imgs_out <- subset(imgs, ! imgs@data$key %in% imgs_in@data$key) . The key variable 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
  • This is a duplicate, if you look at the answer it covers erasing points inside or outside intersecting polygons. In the corresponding function that is what the inside argument is for. What do you mean, "I could not instal the package"? It is a package on CRAN and has passed instal checks for all common OS. If there is an instal issue it would be good to know some details. – Jeffrey Evans Jul 24 '18 at 15:22

0 Answers0