isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
274 stars 26 forks source link

exact_extractr very different behaviour to raster::extract in center of polygon #23

Closed LCroote closed 4 years ago

LCroote commented 4 years ago

Hi, Thanks for a awesome and fast package. I have been using exact_extract quite a bit but have run into a problem.

I was trying to extract raster values into a polygon that sits well within the bounds of the raster, but values are only being extracted onto the border of the polygon.

When I compared to the results of raster::extract there was no problems. I haven't managed to be able to make a small reproducible example as this problem only showed up now and I have been using exact_extract for a while now.

Any help would be much appreciated!

extract(r, p)[[1]] %>% length() #823
exact_extract(r, p)[[1]] %>% nrow() #160

Data (Sorry for the dput dump):

p <- 
structure(list(rowname = "3", Zone = structure(3L, .Label = c("zone_1", 
"zone_2", "zone_3"), class = "factor"), geometry = structure(list(
    `31` = structure(list(structure(c(146.375, 146.425, 146.475, 
    146.475, 146.525, 146.575, 146.575, 146.625, 146.675, 146.725, 
    146.775, 146.775, 146.825, 146.875, 146.925, 146.975, 147.025, 
    147.075, 147.125, 147.125, 147.175, 147.225, 147.225, 147.275, 
    147.325, 147.374999999999, 147.374999999999, 147.374999999999, 
    147.374999999999, 147.374999999999, 147.374999999999, 147.374999999999, 
    147.374999999999, 147.374999999999, 147.374999999999, 147.374999999999, 
    147.374999999999, 147.374999999999, 147.374999999999, 147.325, 
    147.275, 147.275, 147.225, 147.225, 147.225, 147.175, 147.175, 
    147.225, 147.225, 147.175, 147.175, 147.125, 147.075, 147.075, 
    147.125, 147.125, 147.125, 147.125, 147.175, 147.175, 147.175, 
    147.175, 147.225, 147.225, 147.225, 147.175, 147.175, 147.225, 
    147.225, 147.275, 147.275, 147.325, 147.374999999999, 147.374999999999, 
    147.374999999999, 147.374999999999, 147.374999999999, 147.374999999999, 
    147.325, 147.325, 147.275, 147.275, 147.275, 147.275, 147.275, 
    147.225, 147.225, 147.175, 147.125, 147.125, 147.125, 147.075, 
    147.025, 147.025, 146.975, 146.925, 146.925, 146.875, 146.825, 
    146.775, 146.775, 146.725, 146.725, 146.675, 146.675, 146.625, 
    146.625, 146.575, 146.525, 146.525, 146.525, 146.475, 146.475, 
    146.425, 146.375, 146.325, 146.275, 146.225, 146.175, 146.125, 
    146.075, 146.025, 146.025, 146.025, 146.025, 145.975, 145.925, 
    145.925, 145.925, 145.975, 145.975, 145.975, 145.975, 146.025, 
    146.025, 146.025, 146.025, 146.025, 146.075, 146.125, 146.125, 
    146.125, 146.175, 146.175, 146.175, 146.175, 146.225, 146.225, 
    146.275, 146.275, 146.275, 146.325, 146.325, 146.325, 146.375, 
    146.375, 146.425, 146.425, 146.425, 146.375, 146.375, 146.425, 
    146.425, 146.425, 146.425, 146.475, 146.475, 146.475, 146.425, 
    146.375, 146.375, 146.375, 146.325, 146.275, 146.275, 146.225, 
    146.225, 146.175, 146.175, 146.125, 146.125, 146.175, 146.175, 
    146.175, 146.225, 146.275, 146.325, 146.375, 146.375, -33.475, 
    -33.475, -33.475, -33.525, -33.525, -33.525, -33.575, -33.575, 
    -33.575, -33.575, -33.575, -33.525, -33.525, -33.525, -33.525, 
    -33.525, -33.525, -33.525, -33.525, -33.575, -33.575, -33.575, 
    -33.525, -33.525, -33.525, -33.525, -33.575, -33.625, -33.675, 
    -33.725, -33.775, -33.825, -33.875, -33.925, -33.975, -34.025, 
    -34.075, -34.125, -34.175, -34.175, -34.175, -34.125, -34.125, 
    -34.175, -34.225, -34.225, -34.275, -34.275, -34.325, -34.325, 
    -34.375, -34.375, -34.375, -34.425, -34.425, -34.475, -34.525, 
    -34.575, -34.575, -34.625, -34.675, -34.725, -34.725, -34.775, 
    -34.825, -34.825, -34.875, -34.875, -34.925, -34.925, -34.975, 
    -34.975, -34.975, -35.025, -35.075, -35.125, -35.175, -35.225, 
    -35.225, -35.175, -35.175, -35.225, -35.275, -35.325, -35.375, 
    -35.375, -35.325, -35.325, -35.325, -35.375, -35.425, -35.425, 
    -35.425, -35.475, -35.475, -35.475, -35.425, -35.425, -35.425, 
    -35.425, -35.475, -35.475, -35.525, -35.525, -35.475, -35.475, 
    -35.425, -35.425, -35.425, -35.475, -35.525, -35.525, -35.475, 
    -35.475, -35.475, -35.475, -35.475, -35.475, -35.475, -35.475, 
    -35.475, -35.475, -35.425, -35.375, -35.325, -35.325, -35.325, 
    -35.275, -35.225, -35.225, -35.175, -35.125, -35.075, -35.075, 
    -35.025, -34.975, -34.925, -34.875, -34.875, -34.875, -34.825, 
    -34.775, -34.775, -34.725, -34.675, -34.625, -34.625, -34.575, 
    -34.575, -34.525, -34.475, -34.475, -34.425, -34.375, -34.375, 
    -34.325, -34.325, -34.275, -34.225, -34.225, -34.175, -34.175, 
    -34.125, -34.075, -34.025, -34.025, -33.975, -33.925, -33.925, 
    -33.925, -33.875, -33.825, -33.825, -33.825, -33.775, -33.775, 
    -33.725, -33.725, -33.675, -33.675, -33.625, -33.625, -33.575, 
    -33.525, -33.525, -33.525, -33.525, -33.525, -33.475), .Dim = c(189L, 
    2L)), structure(c(147.175, 147.175, 147.125, 147.125, 147.175, 
    -35.225, -35.175, -35.175, -35.225, -35.225), .Dim = c(5L, 
    2L))), class = c("XY", "POLYGON", "sfg"))), class = c("sfc_POLYGON", 
"sfc"), precision = 0, bbox = structure(c(xmin = 145.925, ymin = -35.525, 
xmax = 147.374999999999, ymax = -33.475), class = "bbox"), crs = structure(list(
    epsg = 4326L, proj4string = "+proj=longlat +datum=WGS84 +no_defs"), class = "crs"), n_empty = 0L)), row.names = 1L, sf_column = "geometry", agr = structure(c(rowname = NA_integer_, 
Zone = NA_integer_), .Label = c("constant", "aggregate", "identity"
), class = "factor"), class = c("sf", "data.frame"))

r <-
new("RasterLayer", file = new(".RasterFile", name = "", datanotation = "FLT4S", 
    byteorder = "little", nodatavalue = -3.4e+38, NAchanged = FALSE, 
    nbands = 1L, bandorder = "BIL", offset = 0L, toptobottom = TRUE, 
    blockrows = 0L, blockcols = 0L, driver = "", open = FALSE), 
    data = new(".SingleLayerData", values = c(NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, 0.266666666666667, 0.266666666666667, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, 0.366666666666667, 0.4, 0.366666666666667, 
    0.366666666666667, 0.366666666666667, 0.333333333333333, 
    0.3, 0.3, NA, NA, NA, NA, 0.666666666666667, 0.633333333333333, 
    0.7, 0.733333333333333, 0.7, 0.766666666666667, 0.8, NA, 
    NA, 1, 1.06666666666667, 1.06666666666667, NA, NA, NA, NA, 
    NA, 0.466666666666667, 0.5, 0.466666666666667, 0.466666666666667, 
    0.4, 0.333333333333333, 0.3, 0.3, 0.3, 0.366666666666667, 
    0.533333333333333, 0.566666666666667, 0.5, 0.5, 0.566666666666667, 
    0.666666666666667, 0.733333333333333, 0.7, 0.733333333333333, 
    0.8, 0.866666666666667, 1.06666666666667, 1.1, 1.1, NA, NA, 
    NA, NA, 0.533333333333333, 0.566666666666667, 0.633333333333333, 
    0.6, 0.566666666666667, 0.466666666666667, 0.366666666666667, 
    0.333333333333333, 0.3, 0.3, 0.433333333333333, 0.5, 0.5, 
    0.5, 0.533333333333333, 0.566666666666667, 0.666666666666667, 
    0.666666666666667, 0.7, 0.733333333333333, 0.766666666666667, 
    0.866666666666667, 1.03333333333333, 1.1, 1.13333333333333, 
    NA, NA, NA, NA, NA, 0.733333333333333, 0.933333333333333, 
    0.833333333333333, 0.566666666666667, 0.566666666666667, 
    0.4, 0.366666666666667, 0.4, 0.466666666666667, 0.433333333333333, 
    0.466666666666667, 0.5, 0.533333333333333, 0.5, 0.666666666666667, 
    0.666666666666667, 0.7, 0.7, 0.766666666666667, 0.766666666666667, 
    0.933333333333333, 1.03333333333333, 1.06666666666667, 1.13333333333333, 
    NA, NA, NA, NA, NA, NA, 0.9, 0.9, 0.666666666666667, 0.433333333333333, 
    0.4, 0.4, 0.4, 0.433333333333333, 0.466666666666667, 0.533333333333333, 
    0.533333333333333, 0.566666666666667, 0.533333333333333, 
    0.6, 0.7, 0.7, 0.8, 0.866666666666667, 0.866666666666667, 
    0.966666666666667, 1, 1, 1.06666666666667, NA, NA, NA, NA, 
    NA, NA, NA, 0.633333333333333, 0.5, 0.4, 0.4, 0.366666666666667, 
    0.366666666666667, 0.466666666666667, 0.466666666666667, 
    0.466666666666667, 0.566666666666667, 0.666666666666667, 
    0.666666666666667, 0.7, 0.666666666666667, 0.7, 0.833333333333333, 
    0.866666666666667, 0.9, 1, 1, 1, 1.06666666666667, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, 0.4, 0.333333333333333, 0.366666666666667, 
    0.466666666666667, 0.5, 0.533333333333333, 0.6, 0.6, 0.7, 
    0.833333333333333, 0.833333333333333, 0.766666666666667, 
    0.733333333333333, 0.833333333333333, 0.9, 0.933333333333333, 
    0.966666666666667, 1, 1.06666666666667, 1.06666666666667, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.366666666666667, 0.333333333333333, 
    0.333333333333333, 0.433333333333333, 0.466666666666667, 
    0.566666666666667, 0.666666666666667, 0.6, 0.666666666666667, 
    0.766666666666667, 0.833333333333333, 0.9, 0.866666666666667, 
    0.866666666666667, 0.9, 0.866666666666667, 0.9, 0.966666666666667, 
    1.06666666666667, 1.1, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, 0.3, 0.333333333333333, 0.333333333333333, 0.533333333333333, 
    0.666666666666667, 0.533333333333333, 0.6, 0.566666666666667, 
    0.8, 0.866666666666667, 0.866666666666667, 0.833333333333333, 
    0.9, 0.933333333333333, 0.933333333333333, 1, 1.06666666666667, 
    1.1, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.3, 0.333333333333333, 
    0.3, 0.333333333333333, 0.433333333333333, 0.466666666666667, 
    0.5, 0.566666666666667, 0.6, 0.7, 0.766666666666667, 0.833333333333333, 
    0.833333333333333, 0.933333333333333, 0.966666666666667, 
    1, 1.1, 1.2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.333333333333333, 
    0.3, 0.3, 0.3, 0.3, 0.366666666666667, 0.7, 0.433333333333333, 
    0.5, 0.566666666666667, 0.633333333333333, 0.733333333333333, 
    0.766666666666667, 0.966666666666667, 0.933333333333333, 
    0.966666666666667, 1.1, 1.1, 1.26666666666667, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, 0.366666666666667, 0.333333333333333, 
    0.266666666666667, 0.266666666666667, 0.333333333333333, 
    0.333333333333333, 0.566666666666667, 0.4, 0.5, 0.666666666666667, 
    0.8, 0.766666666666667, 0.933333333333333, 1.03333333333333, 
    0.966666666666667, 1.06666666666667, 1.13333333333333, 1.23333333333333, 
    1.23333333333333, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    0.366666666666667, 0.333333333333333, 0.333333333333333, 
    0.266666666666667, 0.3, 0.333333333333333, 0.333333333333333, 
    0.366666666666667, 0.466666666666667, 0.766666666666667, 
    0.8, 0.833333333333333, 0.933333333333333, 0.966666666666667, 
    1.06666666666667, 1.2, 1.43333333333333, 1.4, 1.46666666666667, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.4, 0.366666666666667, 
    0.333333333333333, 0.333333333333333, 0.266666666666667, 
    0.3, 0.3, 0.333333333333333, 0.366666666666667, 0.533333333333333, 
    0.633333333333333, 0.933333333333333, 0.833333333333333, 
    0.833333333333333, 0.966666666666667, 1.1, 1.4, 1.46666666666667, 
    1.56666666666667, 1.66666666666667, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, 0.333333333333333, 0.333333333333333, 0.333333333333333, 
    0.333333333333333, 0.3, 0.3, 0.333333333333333, 0.433333333333333, 
    0.5, 0.866666666666667, 0.666666666666667, 0.766666666666667, 
    0.833333333333333, 1.03333333333333, 1.16666666666667, 1.4, 
    1.6, 1.76666666666667, 2.06666666666667, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, 0.4, 0.333333333333333, 0.333333333333333, 
    0.333333333333333, 0.366666666666667, 0.3, 0.333333333333333, 
    0.533333333333333, 0.6, 0.566666666666667, 0.733333333333333, 
    0.733333333333333, 0.9, 0.966666666666667, 1.16666666666667, 
    1.33333333333333, 1.56666666666667, 1.9, 2.16666666666667, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.433333333333333, 
    0.433333333333333, 0.4, 0.433333333333333, 0.433333333333333, 
    0.366666666666667, 0.4, 0.533333333333333, 0.566666666666667, 
    0.566666666666667, 0.7, 0.833333333333333, 1.16666666666667, 
    1.13333333333333, 1.23333333333333, 1.46666666666667, 1.83333333333333, 
    2.1, 2.36666666666667, NA, NA, NA, NA, NA, NA, NA, NA, 0.4, 
    0.6, 0.433333333333333, 0.4, 0.433333333333333, 0.466666666666667, 
    0.5, 0.466666666666667, 0.433333333333333, 0.4, 0.466666666666667, 
    0.6, 0.733333333333333, 0.9, 1.06666666666667, 1.4, 1.5, 
    1.76666666666667, 2.1, 2.26666666666667, 2.46666666666667, 
    NA, NA, NA, NA, NA, NA, NA, NA, 0.366666666666667, 0.4, 0.5, 
    0.433333333333333, 0.433333333333333, 0.533333333333333, 
    0.5, 0.5, 0.5, 0.566666666666667, 0.7, 0.666666666666667, 
    0.9, 1.1, 1.16666666666667, 1.33333333333333, 1.6, 1.9, 2.13333333333333, 
    2.36666666666667, 2.66666666666667, NA, NA, NA, NA, NA, NA, 
    NA, 0.433333333333333, 0.366666666666667, 0.366666666666667, 
    0.366666666666667, 0.933333333333333, 0.966666666666667, 
    0.7, 0.733333333333333, 0.5, 0.5, 0.5, 0.666666666666667, 
    0.666666666666667, 0.733333333333333, 0.933333333333333, 
    1.2, 1.26666666666667, 1.73333333333333, 2.03333333333333, 
    2.13333333333333, 2.63333333333333, 2.9, NA, NA, NA, NA, 
    NA, NA, NA, 0.4, 0.4, 0.366666666666667, 0.366666666666667, 
    0.4, 0.466666666666667, 0.533333333333333, 0.533333333333333, 
    0.5, 0.466666666666667, 0.533333333333333, 0.633333333333333, 
    0.7, 0.8, 0.966666666666667, 1.3, 1.33333333333333, 1.73333333333333, 
    1.9, 2.1, 2.66666666666667, 3, NA, NA, NA, NA, NA, NA, 0.466666666666667, 
    0.4, 0.4, 0.4, 0.433333333333333, 0.4, 0.4, 0.6, 0.666666666666667, 
    0.433333333333333, 0.533333333333333, 0.633333333333333, 
    0.633333333333333, 0.633333333333333, 0.766666666666667, 
    0.866666666666667, 1, 1.46666666666667, 1.63333333333333, 
    1.96666666666667, 2.13333333333333, 2.36666666666667, 2.66666666666667, 
    NA, NA, NA, NA, NA, 0.5, 0.5, 0.4, 0.4, 0.4, 0.4, 0.433333333333333, 
    0.4, 0.433333333333333, 0.433333333333333, 0.466666666666667, 
    0.533333333333333, 0.566666666666667, 0.666666666666667, 
    0.666666666666667, 0.8, 0.866666666666667, 1.03333333333333, 
    1.33333333333333, 1.63333333333333, 1.96666666666667, 2, 
    2.3, 2.83333333333333, NA, NA, NA, NA, NA, 0.533333333333333, 
    0.5, 0.4, 0.4, 0.4, 0.433333333333333, 0.433333333333333, 
    0.466666666666667, 0.466666666666667, 0.833333333333333, 
    0.633333333333333, 0.533333333333333, 0.6, 0.633333333333333, 
    0.7, 0.8, 0.9, 1.1, 1.26666666666667, 1.56666666666667, 1.86666666666667, 
    1.96666666666667, 2.4, 2.86666666666667, NA, NA, NA, NA, 
    NA, 0.5, 0.466666666666667, 0.4, 0.4, 0.433333333333333, 
    0.433333333333333, 0.433333333333333, 0.466666666666667, 
    0.866666666666667, 0.533333333333333, 0.466666666666667, 
    0.566666666666667, 0.6, 0.7, 0.733333333333333, 0.833333333333333, 
    0.9, 1.1, 1.23333333333333, 1.5, 1.56666666666667, 1.9, 2.3, 
    2.66666666666667, NA, NA, NA, NA, 0.533333333333333, 0.5, 
    0.433333333333333, 0.4, 0.433333333333333, 0.433333333333333, 
    0.433333333333333, 0.533333333333333, 0.466666666666667, 
    0.466666666666667, 0.5, 0.566666666666667, 0.6, 0.6, 0.633333333333333, 
    0.733333333333333, 0.833333333333333, 0.9, 1.2, 1.2, 1.43333333333333, 
    1.66666666666667, 2.03333333333333, 2.33333333333333, 2.53333333333333, 
    NA, NA, NA, NA, 0.5, 0.466666666666667, 0.433333333333333, 
    0.433333333333333, 0.433333333333333, 0.466666666666667, 
    0.533333333333333, 0.566666666666667, 0.6, 0.566666666666667, 
    0.566666666666667, 0.6, 0.6, 0.6, 0.7, 0.733333333333333, 
    0.833333333333333, 0.933333333333333, 1.2, 1.26666666666667, 
    1.46666666666667, 1.83333333333333, 2.2, 2.36666666666667, 
    2.8, NA, NA, 0.533333333333333, 0.533333333333333, 0.533333333333333, 
    0.466666666666667, 0.466666666666667, 0.433333333333333, 
    0.433333333333333, 0.466666666666667, 0.6, 0.566666666666667, 
    0.6, 0.566666666666667, 0.633333333333333, 0.6, 0.6, 0.633333333333333, 
    0.633333333333333, 0.733333333333333, 0.833333333333333, 
    1.06666666666667, 1.2, 1.43333333333333, 1.46666666666667, 
    1.8, 1.9, 2.2, 2.46666666666667, NA, NA, 0.533333333333333, 
    0.533333333333333, 0.5, 0.5, 0.433333333333333, 0.433333333333333, 
    0.466666666666667, 0.533333333333333, 0.6, 0.666666666666667, 
    0.666666666666667, 0.633333333333333, 0.633333333333333, 
    0.633333333333333, 0.633333333333333, 0.633333333333333, 
    0.7, 0.7, 0.8, 0.9, 1.1, 1.33333333333333, 1.66666666666667, 
    1.56666666666667, 1.83333333333333, 1.93333333333333, 2, 
    NA, NA, 0.5, 0.533333333333333, 0.5, 0.466666666666667, 0.466666666666667, 
    0.466666666666667, 0.533333333333333, 0.533333333333333, 
    0.566666666666667, 0.666666666666667, 0.666666666666667, 
    0.666666666666667, 0.7, 0.666666666666667, 0.666666666666667, 
    0.633333333333333, 0.666666666666667, 0.733333333333333, 
    0.833333333333333, 0.9, 1.13333333333333, 1.3, 1.3, 1.36666666666667, 
    1.36666666666667, 1.7, 1.76666666666667, NA, NA, 0.5, 0.5, 
    0.466666666666667, 0.5, 0.5, 0.533333333333333, 0.533333333333333, 
    0.533333333333333, 0.6, 0.7, 0.633333333333333, 0.666666666666667, 
    0.666666666666667, 0.7, 0.7, 0.666666666666667, 0.733333333333333, 
    0.8, 0.866666666666667, 0.9, 0.866666666666667, 1.03333333333333, 
    1.13333333333333, 1.2, 1.5, 1.4, 1.8, NA, 0.533333333333333, 
    0.5, 0.5, 0.5, 0.5, 0.5, 0.533333333333333, 0.533333333333333, 
    0.566666666666667, 0.7, 0.666666666666667, 0.666666666666667, 
    0.666666666666667, 0.666666666666667, 0.733333333333333, 
    0.8, 0.933333333333333, 0.866666666666667, 0.9, 0.966666666666667, 
    0.933333333333333, 0.966666666666667, 1.16666666666667, 1.16666666666667, 
    1.16666666666667, 1.2, 1.36666666666667, 1.33333333333333, 
    NA, 0.533333333333333, 0.533333333333333, 0.5, 0.5, 0.5, 
    0.5, 0.6, 0.566666666666667, 0.633333333333333, 0.666666666666667, 
    0.666666666666667, 0.666666666666667, 0.666666666666667, 
    0.733333333333333, 0.766666666666667, 0.833333333333333, 
    0.9, 1.03333333333333, 0.966666666666667, 0.966666666666667, 
    0.933333333333333, 1.03333333333333, 1.1, 1.5, 1.53333333333333, 
    1.26666666666667, 1.5, 1.5, NA, 0.566666666666667, 0.533333333333333, 
    0.533333333333333, 0.5, 0.5, 0.5, 0.5, 0.6, 0.666666666666667, 
    0.666666666666667, 0.666666666666667, 0.666666666666667, 
    0.666666666666667, 0.766666666666667, 0.766666666666667, 
    0.833333333333333, 0.9, 1, 0.966666666666667, 0.966666666666667, 
    0.966666666666667, 1.03333333333333, 1.16666666666667, 1.6, 
    1.16666666666667, 1.23333333333333, 1.56666666666667, 1.5, 
    0.566666666666667, 0.566666666666667, 0.566666666666667, 
    0.533333333333333, 0.533333333333333, 0.533333333333333, 
    0.5, 0.533333333333333, 0.633333333333333, 0.633333333333333, 
    0.633333333333333, 0.633333333333333, 0.633333333333333, 
    0.733333333333333, 0.8, 0.833333333333333, 0.9, 1, 1.03333333333333, 
    1, 1, 1, 1.26666666666667, 1.26666666666667, 1.3, 1.53333333333333, 
    1.4, 1.56666666666667, 1.93333333333333, 0.6, 0.566666666666667, 
    0.6, 0.566666666666667, 0.566666666666667, 0.566666666666667, 
    0.566666666666667, 0.566666666666667, 0.666666666666667, 
    0.666666666666667, 0.666666666666667, 0.633333333333333, 
    0.766666666666667, 0.8, 0.9, 0.933333333333333, 0.933333333333333, 
    1.06666666666667, 1.13333333333333, 1.1, 1.03333333333333, 
    0.966666666666667, 1.16666666666667, 1.43333333333333, 1.46666666666667, 
    1.33333333333333, 1.43333333333333, 1.63333333333333, 1.7, 
    NA, NA, 0.666666666666667, 0.666666666666667, 0.666666666666667, 
    0.666666666666667, 0.6, 0.633333333333333, 0.766666666666667, 
    0.733333333333333, 0.8, 0.833333333333333, 0.9, 0.933333333333333, 
    0.933333333333333, 0.933333333333333, 0.966666666666667, 
    1.1, 1.16666666666667, 1.1, 1.06666666666667, 1.23333333333333, 
    1.43333333333333, 1.4, 1.73333333333333, 1.43333333333333, 
    1.36666666666667, 1.46666666666667, 2.03333333333333, NA, 
    NA, 0.733333333333333, 0.8, 0.766666666666667, 0.733333333333333, 
    0.8, 0.866666666666667, 0.9, 0.966666666666667, 1, 1, 1.06666666666667, 
    0.933333333333333, 0.933333333333333, 0.933333333333333, 
    1, 1.2, 1.2, 1.06666666666667, 1.13333333333333, 1.13333333333333, 
    1.2, 1.26666666666667, 1.36666666666667, 1.4, 1.43333333333333, 
    1.43333333333333, 2.2, NA, NA, 0.866666666666667, 0.933333333333333, 
    0.9, 0.933333333333333, 0.933333333333333, 1, 1.03333333333333, 
    1.03333333333333, 1, 1.03333333333333, 1.23333333333333, 
    1.26666666666667, 0.966666666666667, 0.966666666666667, 1.03333333333333, 
    1.3, 1.13333333333333, 1.33333333333333, 1.1, 1.16666666666667, 
    1.26666666666667, 1.43333333333333, 1.33333333333333, 1.5, 
    1.43333333333333, 1.4, 1.46666666666667, NA, NA, 1.03333333333333, 
    1.06666666666667, 0.966666666666667, 1.1, 1.06666666666667, 
    1.03333333333333, 1.13333333333333, 1.13333333333333, 1.1, 
    1.16666666666667, 1.2, 1.3, 1.23333333333333, 1.03333333333333, 
    1.03333333333333, 1.26666666666667, 1.53333333333333, 1.13333333333333, 
    1.1, 1.26666666666667, 1.26666666666667, 1.33333333333333, 
    1.36666666666667, 1.4, 1.43333333333333, 1.53333333333333, 
    1.56666666666667), offset = 0, gain = 1, inmemory = TRUE, 
        fromdisk = FALSE, isfactor = FALSE, attributes = list(), 
        haveminmax = TRUE, min = 0.266666666666667, max = 3, 
        band = 1L, unit = "", names = "mean_cold_events"), legend = new(".RasterLegend", 
        type = character(0), values = logical(0), color = logical(0), 
        names = logical(0), colortable = logical(0)), title = character(0), 
    extent = new("Extent", xmin = 145.9249999999, xmax = 147.3749999999, 
        ymin = -35.5249999999999, ymax = -33.475), rotated = FALSE, 
    rotation = new(".Rotation", geotrans = numeric(0), transfun = function () 
    NULL), ncols = 29L, nrows = 41L, crs = new("CRS", projargs = NA_character_), 
    history = list(), z = list())
dbaston commented 4 years ago

Thanks for an excellent report! For visual reference, the raster and polygon look like this:

plot(r)
plot(st_geometry(p), add=TRUE)

image

In which the extracted cells can be seen:

exact_extract(r, p, include_xy=TRUE)[[1]] %>%
  st_as_sf(coords=c('x','y')) %>% 
  st_geometry() %>% 
  plot(pch=7, cex=0.8, add=TRUE)

image

Will try to bring up in the debugger and see what I can figure out.

LCroote commented 4 years ago

Thanks, yes the images are much more insightful! I am looking forward to your response.

dbaston commented 4 years ago

I have a candidate fix in place.

remotes::install_git('https://gitlab.com/isciences/exactextractr', ref='gh-23')

LCroote commented 4 years ago

Thanks very much for the quick response and fix, that seems to do the trick!

dbaston commented 4 years ago

Fixed version (0.2.1) is now in CRAN, by the way.