enter image description here

  1. I have two documents. One is a csv file which contains lon and lat information. Another is a shapefile.
  2. I want use "over" command in r to select points inside the polygons, but I get all NA results. However, based on the projection, clearly there are some points inside of the polygons....

Here are some of my codes:

>"SpatialPointsDataFrame" "SpatialPoints"     "Spatial"               

>"SpatialPolygonsDataFrame" "SpatialPolygons"  "Spatial"     

mapdata$longitude <- as.numeric(mapdata$longitude) 

mapdata$latitude<- as.numeric(mapdata$latitude)

mapdata <- SpatialPointsDataFrame(
    subset(mapdata, select=-c(latitude, longitude)),
    proj4string = CRS(gsub("lcc","longlat",proj4string(shapefile))))   

mapdata <- spTransform(mapdata, shapefile@proj4string)

joinednew <- over(mapdata, shapefile)
mapdata@data$inside <- as.numeric(!is.na(joinednew))
  • Looks okay at first glance but we can't help without your data or a reproducible example. – Spacedman Jul 18 at 11:22

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.