[R-sig-Geo] crop and overlay question

Jesse Berman berman.jesse at gmail.com
Fri Mar 1 05:44:02 CET 2013


Hi Erin,

I'm sure someone else will have a more elegant solution, but if you need a
quick fix try this (adapted from your posted code)

Jesse

tmp <- map("state","Texas",fill=TRUE,plot=FALSE) 
texas.boundary <- map2SpatialPolygons(tmp, IDs=tmp$names,
proj4string=CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")) 
texas1.boundary <- spTransform(texas.boundary,CRS("+proj=aea +lat_1=27.5
+lat_2=35 +lat_0=18 +lon_0=-100 +x_0=1500000 +y_0=6000000 +ellps=GRS80
+datum=NAD83 +units=m +no_defs") ) 
grd <- SpatialPoints(makegrid(texas1.boundary, n=300))

# New steps 
Overlay<-overlay(grd, texas1.boundary) #To find out which points fall within
the TX boundary
grd at coords<-cbind(grd at coords,Overlay) #To mark those points outside TX with
an NA
tex.grid<-na.exclude(as.data.frame(grd)) # Transfers to non-spatial
dataframe to remove NA points
coordinates(tex.grid)=~x1+x2 # Now turn back into spatial points dataframe
proj4string(tex.grid)=("+proj=aea +lat_1=27.5 +lat_2=35 +lat_0=18
+lon_0=-100 +x_0=1500000 +y_0=6000000 +ellps=GRS80 +datum=NAD83 +units=m
+no_defs")
plot(tex.grid)



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/crop-and-overlay-question-tp7582894p7582896.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list