[R-sig-Geo] Polygons of a SpatialPolygonsDataFrame

Rafael Wüest rafael.wueest at wsl.ch
Fri Feb 17 18:17:40 CET 2012


Oops, there's a mistake in the first line of code. should be:

extract(raster, SPdataframe,fun="mean",na.rm=TRUE,method="simple")

On 17.02.2012, at 17:58, Emmenegger Tamara wrote:

> Merci!
> 
> -----Ursprüngliche Nachricht-----
> Von: Rafael Wüest [mailto:rafael.wueest at wsl.ch] 
> Gesendet: Freitag, 17. Februar 2012 17:45
> An: Emmenegger Tamara
> Betreff: Re: [R-sig-Geo] Polygons of a SpatialPolygonsDataFrame
> 
> Hi Tamara
> 
> assuming SPdatframe is the SpatialPolygonsDataFrame, if you need the mean of every polygon, then you can as well try
> 
> extract(raster, SpatialPolygons(SPdataframe at polygons),fun="mean",na.rm=TRUE,method="simple")
> 
> this will give you the mean for each polygon in a vector.
> 
> If you want to do them seperately, you will have to select each polygon like:
> 
> extract(raster, SPdataframe[i,],fun="mean",na.rm=TRUE,method="simple")
> 
> Rafael
> 
> 
> On 17.02.2012, at 16:57, Emmenegger Tamara wrote:
> 
>> I have a SpatialPolygonsDataFrame with 120 Polygons and some 
>> associated data. Now I'd like to extract the mean of the values on a 
>> raster within each polygon separately. I succeded in plotting 
>> individual polygons with:
>> plot(SpatialPolygons(SPdataframe at polygons)[i])
>> 
>> But it did not work to extract the values in the same manner:
>> extract(raster, 
>> SpatialPolygons(SPdataframe at polygons)[i],fun="mean",na.rm=TRUE,method=
>> "simple")
>> 
>> Can anyone explain the difference between the use of the same 
>> indexation in this two cases? What is the official way to choose 
>> particular polygons of a SpatialPolygonsData- Frame with indices?
>> 
>> Thank you a lot for your help in advance!
>> 
>> 
>> ____________________________________________________
>> 
>> Tamara Emmenegger
>> Msc student
>> Bird migration
>> Tel. ++41 41 462 97 00
>> 
>> tamara.emmenegger at vogelwarte.ch<mailto:tamara.emmenegger at vogelwarte.ch
>>> www.vogelwarte.ch<http://www.vogelwarte.ch/>
>> 
>> Schweizerische Vogelwarte | Seerose 1 | CH-6204 Sempach | Schweiz 
>> Station ornithologique suisse | Seerose 1 | CH-6204 Sempach | Suisse 
>> Stazione ornitologica svizzera | Seerose 1 | CH-6204 Sempach | 
>> Svizzera Swiss Ornithological Institute | Seerose 1 | CH-6204 Sempach 
>> | Switzerland
>> 
>> 
>> 	[[alternative HTML version deleted]]
>> 
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> 
> 
> --
> Rafael Wüest
> Swiss Federal Research Institute WSL
> Zürcherstrasse 111
> 8903 Birmensdorf
> Switzerland
> 
> +41 44 7392126
> rafael.wueest at wsl.ch
> http://www.wsl.ch/info/mitarbeitende/wueest
> 
> 
> 



--
Rafael Wüest
Swiss Federal Research Institute WSL
Zürcherstrasse 111
8903 Birmensdorf
Switzerland

+41 44 7392126
rafael.wueest at wsl.ch
http://www.wsl.ch/info/mitarbeitende/wueest



More information about the R-sig-Geo mailing list