geoblaze icon indicating copy to clipboard operation
geoblaze copied to clipboard

Potentially unsupported geometry?

Open chrispahm opened this issue 1 year ago • 1 comments

Describe the bug When trying to calculate means for many (thousand) polygons, I frequently receive the "No Values were found in the given geometry" error. However, the raster definitely covers the given geometry and has values in it (checked using QGIS → Zonal Statistics). Also, the mean calculation works when I just pass the geometries bboxes. Could it be that the type of polygon, e.g. "MultiPolygons" or concave polygons are not supported by geoblaze?

To Reproduce See the following Observable notebook to reproduce: https://observablehq.com/@chrispahm/geoblaze-unsupported-geometry-type

Expected behavior The mean method should return the same mean as QGIS zonal statistics.

chrispahm avatar Aug 09 '22 16:08 chrispahm

Hi, @chrispahm . I'm very sorry I missed this. I think the issue is that the algorithm that geoblaze uses dufour-peyton-intersection, was originally built for use cases where the geometries were larger in size than the pixels. However, this is not always the case as we have seen with your dataset.

The most immediate solution would be to see if you could resample your tiff to a higher resolution (it's technically not going to be higher "resolution" in some sense, but will have a lot more pixels).

Alternatively, you could calculate the size of the bounding box of the geometry using https://turfjs.org/ and if the size of the bounding box is smaller than the size of a pixel, calculate the centroid and run geoblaze.identify(georaster, centroid). After all, the mean of one value is equal to that one value.

Long term, it would be great to make geoblaze smarter to more gracefully handle these use cases. I know for a fact is is quite possible to solve this issue as we did as much with geowarp (https://github.com/DanielJDufour/geowarp/blob/main/geowarp.js#L779). I'm light on time at the moment, so a better solution will probably take a few months.

In the meantime, I'd love to keep this issue open as it is a very valid issue and I very much would like to see a solution for it.

Thank you very much for bringing this to our attention!

DanielJDufour avatar Mar 05 '23 00:03 DanielJDufour