hunzikp / velox

https://hunzikp.github.io/velox/
119 stars 23 forks source link

Extraction around polygon border #21

Closed vincentanutama closed 6 years ago

vincentanutama commented 6 years ago

Ignore other colors but green on the plot below. The green color indicates the cells that were not extracted through VeloxRaster_extract but got extracted through raster::extract. These green regions correspond to the shapefile polygon border. I used small = T in both functions. image

hunzikp commented 6 years ago

Hi there! Thanks for your message. Can you post a reproducible example and/or send me the underlying data via e-mail [hunzikp at gmail dot com]? Otherwise it's difficult to figure out what went wrong. Cheers

hunzikp commented 6 years ago

Hi Vincent, It turns out this is intended behavior (I actually had to look this up myself). The small option in VeloxRaster_extract only returns polygon/cell overlaps (instead of polygon/centroid overlaps) for polygons that are too small to intersect with any cell centroid. From the velox documentation for the small argument:

If TRUE and sp contains polygons, then raster values for small (or oddly shaped) polygons that do not intersect with any cell centroid are established by intersecting the small polygon with the entire (boxed) cells.

This mirrors the behavior of the raster::extract function, where it says in the documentation of the small option:

If y represents polygons, a value is also returned for relatively small polygons (e.g. those smaller than a single cell of the Raster* object), or polygons with an odd shape, for which otherwise no values are returned because they do not cover any raster cell centers.

Now the raster::extract function also has an option weights, which velox does not (yet) support. If this is set to TRUE (which it is in your example), then extract returns polygon/cell overlaps for all polygons (regardless of size or shape), together with weights indicating the size of the overlap. I'm planning to implement a weights option in velox some time in the future.

Hth, Philipp

danielreispereira commented 6 years ago

+1 for a Velox implementation of weights= !