[R-sig-Geo] Extract() fails to return data for boundary admin units

ping yang pingyang.whu at gmail.com
Tue Oct 18 22:31:24 CEST 2016


I also found issues with the raster::extract function, for some reason, I
got crazy values when I compared the resulting value with the one from
QGIS(Zonal Statistics Plugin) and ArcGIS(zonal statistics), while the value
from qgis and arcgis were close but the raster::extract has a lot of
disturbances:

#example
library(raster)
library(rgdal)

r <- raster("PRISM_ppt_stable_4kmM3_201608_bil.bil
http://prism.nacse.org/6month/")
setwd("D:/PRISM/2005-2016/cb_2015_us_state_500k/")
psa <- readOGR(".",paste("cb_2015_us_state_500k
<http://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_state_500k.zip>
",sep=''))
e <- extract(r, psa, weights=TRUE, sp=TRUE, na.rm=TRUE, df=TRUE,fun=mean)

result <- cbind(psa$monmean,e$PRISM_ppt_stable_4kmM3_201609_bil)
result
            [,1]       [,2]
 [1,]  67.756948  59.672969
 [2,]   8.163987  44.415848
 [3,]  91.171480  53.295749
 [4,]  74.446065  52.633753
 [5,] 128.915104  56.779383
 [6,] 105.266005  93.266030
 [7,] 187.633359  45.947235
 [8,] 106.659815  90.639262
 [9,] 160.519008  46.249172
[10,]  57.266614  26.728985
[11,]  23.258635  49.885868
[12,] 132.101744  46.713378
[13,]  21.995937  51.782905
[14,] 168.313586  93.790604
[15,]         NA         NA
......
[56,]  76.527362  82.369481

Has anyone have looked into this issue?

Thanks,

Peter

On Tue, Oct 18, 2016 at 10:10 AM, chris english <
englishchristophera at gmail.com> wrote:

> Mel,
>
> Looking at detail in cjg.png the northmost missing data island shows approx
> 20-25 in Southern three quarters and 0-5 the small North at tip of island.
> Directly above this 0-5 another coastal 0-5.
> If a substantial east-west scarp bisected the island it might explain. I
> would otherwise expect a very slight mismatch in projection, a thing I
> often have problems with.
>
> Though reading raster::extract it looks like you want to employ the weights
> are if your polys are relatively smaller than your cells.
>
> HTH
> Chris
>
> On Oct 18, 2016 4:35 PM, "Bacou, Melanie" <mel at mbacou.com> wrote:
>
> > Hi,
> > I'm summarizing biophysical rasters (UDEL precipitation and temperature)
> > across administrative units for countries in Africa using (pseudo code):
> >
> > raster::extract(udel, admin, fun=mean, na.rm=T, small=T)
> >
> > Out of the 756 units I need data for, extract() fails to return means for
> > a few coastal units (in red on the maps below) even though the rasters
> show
> > data at these locations.
> >
> > Is there a particular reason why this might happen? Shall I look for
> > possible geometry errors in my source shapefiles, or could there be
> another
> > reason?
> >
> > Maps here:
> > https://dl.dropboxusercontent.com/u/30925475/eclgcdmhapfplaml.png
> > https://dl.dropboxusercontent.com/u/30925475/lmkgmdoohpmhdcjg.png
> >
> > Thanks for any tip. --Mel.
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
>         [[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
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list