isciences / exactextractr

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

Parse Exception ERROR, Unknown WKB type 235 #26

Closed danielreispereira closed 4 years ago

danielreispereira commented 4 years ago

I'm getting the following error when trying to get the coverage fraction from a .kml that has multiple holes in it (multipolygon?). Same code works fine if the kml is simple (no holes in the middle).

Since I have no idea what the error means: what should I try first? Redraw the KML ?

> cov_frac <- coverage_fraction(x = rast, y = poly, crop=TRUE)
**Error in CPP_coverage_fraction(x, wkb, crop) :   ParseException: Unknown WKB type 235**

GithubExample

dbaston commented 4 years ago

Can you share the KML?

danielreispereira commented 4 years ago

Sure thing. Attached. kmlExample_BastonGithub.kml.txt

dbaston commented 4 years ago

Works with the raster I'm using. Can you share the extent and resolution of yours?

danielreispereira commented 4 years ago

Hmm. I'm using the raster attached. CHIRPS rainfall from: https://data.chc.ucsb.edu/products/CHIRPS-2.0/global_daily/tifs/p05/.

class      : RasterLayer 
dimensions : 2000, 7200, 14400000  (nrow, ncol, ncell)
resolution : 0.05, 0.05  (x, y)

rasterTEST.tif.txt

dbaston commented 4 years ago

Here's what I'm running:

library(raster)
library(sf)
library(exactextractr)

prec <- raster('chirps-v2.0.2020.02.29.tif')
poly <- st_read('test.kml')

cf <- coverage_fraction(prec, poly, crop=TRUE)[[1]]

plot(cf)
plot(st_geometry(poly), add=TRUE)

image

danielreispereira commented 4 years ago

Interesting. I keep getting the same error:

image

Pkg version, windows dependencies maybe?

dbaston commented 4 years ago

Interesting. I assume you have the latest exactextractr and sf from CRAN. I'll try to reproduce on a Windows machine.

I suspect this is somehow related to the third dimension, in which case a workaround would be coverage_fraction(prec, st_zm(poly), crop=TRUE) .

danielreispereira commented 4 years ago

That does the trick. What should have I noticed that I missed in this case? KMLs with 3 dimensions ?

dbaston commented 4 years ago

I don't think you missed anything. Ideally the Z dimension would just be ignored, and I'm not sure why this appears to happen on one platform but not another. I'll keep this issue open until I have time to look into it.

danielreispereira commented 4 years ago

Thanks for the fix