I have a df with spatial points that I've converted into a spatial object (dai18) and I want to select only the points that are inside a polygon (peri_A).

I think my coordinate system is incorrect, because it gives me only NA when I apply this command:

points_withinA <- over(dai18 , peri_A, fn = NULL) 

These are the ways in which I've pre-treated the data:

dai18<-SpatialPointsDataFrame(dai18[,c("latitud","longitud")], data=dai18, 
                                  proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))

peri_A <- readOGR("./centroH/Perimetro_A_region.shp", layer = ogrListLayers("./centroH/Perimetro_A_region.shp"))
peri_A<-spTransform(peri_A, "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
| improve this question | | | | |
  • Welcome to GIS SE! As a new user, please be sure to take the short tour to learn about this site's focused Q&A format. – Andy Jan 28 '19 at 18:29
  • What is proj4string(peri_A) telling you? – Jeffrey Evans Jan 28 '19 at 19:28
  • > proj4string(dai18) [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" > proj4string(peri_A) [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" > – Armando González Díaz Jan 28 '19 at 19:39
  • Are you sure there are points within the polygon? Try plotting the polygon using plot(peri_A) and then run points(dai18) to verify that there is actually overlap. – JepsonNomad Jan 28 '19 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.