r - How can I remove outlines from location data -
i have location data of marine species. however, data fall on land , remove them without finding rows belong using ( ps2<-ps1[-c(1,2,3),]
) because have large data set. have search clue can't find good. thank you.
here codes
require(sp) library(maptools) require(raster) data(wrld_simpl) ps<-read.csv('test.csv') ps #----------------- lat lon 1 -32.98000 154.000000 2 36.94625 8.212916 3 -37.81430 -57.479584 4 -19.77236 -40.019028 5 -25.70459 -48.473195 6 -22.47125 -41.859027 7 -28.08153 -48.627082 8 10.56000 39.090000 9 50.50000 50.600000 10 52.50000 5.700000 ps1 <- subset(ps, !is.na(lon) & !is.na(lat)) plot(wrld_simpl, bg='azure2', col='khaki', border='#aaaaaa') #restore box around map box() #plot points points(ps1$lon, ps1$lat, col='orange', pch=20, cex=0.75) # plot points again add border, better visibility points(ps1$lon, ps1$lat, col='red', cex=0.75) last 3 data fall on land.
this shows how can use %over%
(you can use over
function
library(sp) library(raster) library(maptools) data(wrld_simpl) ps <- matrix( c(-32.98000, 154.000000, 36.94625, 8.212916,-37.81430, -57.479584,-19.77236, -40.019028,-25.70459, -48.473195,-22.47125, -41.859027,-28.08153, -48.627082, 10.56000, 39.090000,50.50000, 50.600000, 52.50000, 5.700000), ncol=2, byrow=true) ps <- ps[,2:1] sp <- spatialpoints(ps) crs(sp) = crs(wrld_simpl) <- sp %over% wrld_simpl marine <- is.na(i$iso3) spm <- sp[marine, ] plot(wrld_simpl) points(ps, pch=20, col='red') points(spm, pch=20, col='blue')
Comments
Post a Comment