[R-sig-Geo] crop and overlay question

Hodgess, Erin HodgessE at uhd.edu
Fri Mar 1 08:46:13 CET 2013


this is great!  Thank you!

________________________________________
From: r-sig-geo-bounces at r-project.org [r-sig-geo-bounces at r-project.org] on behalf of Jesse Berman [berman.jesse at gmail.com]
Sent: Thursday, February 28, 2013 10:44 PM
To: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] crop and overlay question

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.

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list