Comments (11)
This issue is legitimate, even if it doesn't affect the OP. Reversing the lat/long in the test case is still a valid polygon, and does hit this issue.
Repro case:
static GeoCoord testVerts[] = {{0.10068990369902957, 0.8920772174196191},
{0.10032914690616246, 0.8915914753447348},
{0.10033349237998787, 0.8915860128746426},
{0.10069496685903621, 0.8920742194546231}};
static Geofence testGeofence = {.numVerts = 4, .verts = testVerts};
static GeoPolygon testPolygon;
SUITE(polyfill) {
testPolygon.geofence = testGeofence;
testPolygon.numHoles = 0;
TEST(weirdShape) {
int res = 13;
int numHexagons = H3_EXPORT(maxPolyfillSize)(&testPolygon, res);
H3Index* hexagons = calloc(numHexagons, sizeof(H3Index));
H3_EXPORT(polyfill)(&testPolygon, res, hexagons);
int actualNumHexagons = countActualHexagons(hexagons, numHexagons);
printf("Hex count: %d\n", actualNumHexagons);
free(hexagons);
}
}
Output with the current 1.5
coeffecient in bboxHexRadius
:
TEST polyfill
Hex count: 3945
Output with the coefficient set to 1.0
:
TEST polyfill
Hex count: 4353
from h3.
First of all, thanks! This is a great bug report - really thorough. I think the issue here is that the 1.5
constant comes from a regular polyhedron model, and doesn't work when the projection distorts the shape of the hexagon - I think this is less a function of the shape you're trying to polyfill, and more a function of whether it's aligned with the long or short axis of the hexagons in its particular area of the grid. My guess is that the same shape, rotated 90 degrees, would be polyfilled correctly with the current settings (and in fact that's what happens at res 12 - suggesting that res 11 would also potentially fail to fill the shape).
We've been considering an alternative approach for polyfill that would solve this problem and be much more efficient for this kind of shape, using h3ToIJ
(#102). I'd rather pursue that approach than try to fiddle with the scaling factor here, though I'd like thoughts from @isaacbrodsky and @dfellis on whether that's a reasonable stop-gap. One option would be to calculate the scale factor from a hexagon at res - 1
, which is the approximate shape of the k-ring.
from h3.
Definitely an amazing bug report.
I disagree on leaving the issue alone until h3ToIJ is ready for use, though. I think we should alter the scaling factor to guarantee correctness and deal with the polyfill slowdown for the short term and then get the performance back up.
We don't have to do the math to determine the maximum extent of hex distortion, if that's what you're worried about wasting time on; just set the constant to something we know could never be reached even with distortion, such as 1.1, and move on.
from h3.
just set the constant to something we know could never be reached even with distortion, such as 1.1, and move on.
I'm fine with this, though given the perf implications it seems worthwhile calculating the worst-case scenario offline and using that as a constant.
from h3.
Thank you both!
You are correct @nrabinowitz , resolution 11 also has this problem:
I had a brief look at #102 and will keep an eye on this functionality in the future. For now I will wait and use the released version of H3.
In the meantime I am thinking of additionally tackling this issue outside of H3 by splitting the polygon into smaller parts and running polyfill
on each of them separately. I hope to compensate the increased radius and keep performance up by having to generate and check less indexes.
from h3.
I just noticed something embarrassing - seems I had a quite stupid bug in my code I simply missed.
I will re-check this issue tomorrow, but there is a good chance this issue is invalid and H3 works as expected. So please do not spend any more time on this right now.
from h3.
Please close this issue as invalid. The problem was caused on my side where I had a systematic mixup of coordinate positions (x,y to lon,lat and back). I am working on an Postgresql binding for H3 and the bug happened during the translation from native postgresql geometry types to the H3 types. Because this error was a systematic mistake, it took a while for me to notice it. It can be frustrating when such simple errors can be the cause for bugs.
Thank you both for your support. I am sorry for the effort this caused on your side.
from h3.
Glad to hear it's working for you. I'll close this issue since it seems the current solutions is working well enough.
from h3.
I think it might still be worth looking into this, though - the original bug report seemed legit, and even if the OP's current issue is solved, there may still be areas of the world/H3 resolutions where this is an issue. Seeing if we can get a repro case would allow us to say whether we fixed it with an h3ToIJ
implementation.
from h3.
Sorry for my Englist!
I try to creat a KML file that contain the global grid in res 2. I find indexes within the given geofence by Polyfill and get the boundary by GeoToBoundary. I found an issue where the grid which the Function's return out of the geofence.You can see the geofence vertices and the grids in the image:
from h3.
@greatathrun There's currently a known issue where you can't polyfill a polygon containing a pole. For this particular purpose, though, you ought to be able to use the h3ToGeoBoundaryHier
utility, passing in each of the base cells.
from h3.
Related Issues (20)
- Broken Link to website docs in contributing.md
- Broken link to website in contributing docs
- Uber CLA Contact HOT 1
- Has cell_to_vertex been implemented? HOT 2
- Replace empty function parameters with `void` HOT 1
- cell_to_child_pos() version 4 of the Python API client HOT 3
- polygonToCells: validity of polygons HOT 3
- Missing library stubs MYPY HOT 2
- polygonToCells not returning all H3Cells for the bounding box containing both USA and Russia HOT 1
- Confirmation of grid algorithm HOT 3
- cellToChildren error HOT 2
- Add function for returning the H3 indices of each endpoint of a directed edge HOT 5
- Expose cellToChildrenSize in bindings HOT 1
- Getting unexpected results when converting coordinates in either direction HOT 4
- Meta: blog post has broken images HOT 5
- API | distance between h3s challenging to work around HOT 5
- Example H3 data sets HOT 3
- Completely cover a polygon with H3 cells using H3 extension for PostGIS
- Hi
- H3 Bug - Easily Reproducible HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from h3.