[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-geo
Subject:    Re: [R-sig-Geo] Aggregate using Shapefile
From:       Tiffany Smith <smithtiffanyt () gmail ! com>
Date:       2013-03-26 15:49:15
Message-ID: ACCC4298-2C7C-43DD-9736-4DBB5C7954D4 () gmail ! com
[Download RAW message or body]

Robert,

Thanks so much, that worked great.

Best,
Tiffany
On Mar 25, 2013, at 3:33 PM, Robert J. Hijmans wrote:

> Tiffany, 
> 
> cds1 <- rbind(c(-180,-20), c(-160,5), c(-60, 0), c(-160,-60), c(-180,-20))
> cds2 <- rbind(c(80,0), c(100,60), c(120,0), c(120,-55), c(80,0))
> p <- SpatialPolygons(list(Polygons(list(Polygon(cds1)), 1), \
> Polygons(list(Polygon(cds2)), 2))) p <- SpatialPolygonsDataFrame(p, \
> data=data.frame(ID=1:2)) 
> r <- raster()
> values(r) <- 1:ncell(r)
> v <- extract(r, p, fun=mean, na.rm=TRUE)
> 
> p$var <- v
> 
> spplot(p, 'var')
> # and see other plot, spplot or ggplot2 examples for a nicer map
> 
> Robert
> 
> On Mon, Mar 25, 2013 at 9:32 AM, Tiffany Smith <smithtiffanyt@gmail.com> wrote:
> Robert,
> 
> Thanks. I guess my question now is, how can I map the output from using 'extract'? \
> I'd like to be able to map is as I would a Raster* layer. 
> Thanks,
> Tiffany
> On Mar 25, 2013, at 12:07 PM, Robert J. Hijmans wrote:
> 
> > Tiffany,
> > You can indeed use extract to compute a single value for each polygon. See the \
> > examples. Alternatively, you can use rasterize and then use crosstab.  Robert
> > 
> > On Fri, Mar 22, 2013 at 10:13 AM, Tiffany Smith <smithtiffanyt@gmail.com> wrote:
> > Hi all,
> > 
> > I'm looking to use a shapefile to aggregate a raster layer. Here's what I have so \
> > far: 
> > indexAL<-raster("myfile.nc")
> > ALshp<-readShapePoly("ALzipcodes.shp")
> > ALrst<-rasterize(ALshp,indexAL,fun=mean)
> > 
> > "indexAL" has a finer resolution than "ALrst", and I'd like to aggregate \
> > "indexAL" up to the scale of "ALrst" in a way that I'm able to create a map in \
> > the end. I've used "extract", but am not sure then how to map that output. \
> > "aggregate" doesn't seem flexible enough to use a shapefile (or raster layer). \
> > Any suggestions? 
> > Thanks,
> > Tiffany
> > 
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> > 
> 
> 


	[[alternative HTML version deleted]]

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic