Closed andresfchamorro closed 1 month ago
@alukach and I dove more into this.
As you described, there's an issue with how we are using the H3 polyfill method, which determines the containment of hexagons within a polygon. The problem arises because this method verifies containment by checking the centroid of the H3 hexagons, not the polygon’s geometry itself. This is problematic as we assumed the API used a “touches” (intersects) logic to determine which hexagons intersect with the input polygon.
For more information on the polyfill method, please look at the H3 polyfill documentation.
We could store the geometries as a lookup table and rely on spatial indexing. Given we are working at a single h3 level 6, this could be considered as an approach. However, we would significantly inflate the size and reliance on the Postgis database.
To address this issue, I plan to implement a new approach that maintains efficiency while performing spatial operations, even though it requires processing a limited number of features.
I worked on a more straightforward approach that leverages the h3 functionality as much as possible instead of relying on spatial functions.
within
Method: For the “within” spatial join method, we filter the hexagons whose polygon boundaries are not entirely contained within the AOI polygon.touches
method: First, we identify hexagons that intersect the boundary and generate their neighboring hexagons. Finally, we filter these neighbors to exclude any that do not intersect with the input polygon.@andresfchamorro, confirming that with the new changes in #69. I added your initial work as another example.
As a workaround to https://github.com/worldbank/DECAT_Space2Stats/issues/56, I tried iterating over every polygon component. The API fails either because there is no source data or the intersect does not provide any matches (I tried both centroid and touches). Can we investigate which is the case? Either way, it should raise an exception explaining the issue. Right now it still returns an empty array.
To Reproduce