-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bboxHexEstimate: Calculated area is way too big #708
Comments
As it happens, I was also looking at this function recently ^^ From my understanding there are two issues here:
The ratio is always computed as With the current formula we get:
Which is way too big, indeed... If we fix the formula by making sure we always compute ratio as double d1 = fabs(p1.lng - p2.lng);
double d2 = fabs(p1.lat - p2.lat);
double length = fmax(d1, d2);
double width = fmin(d1, d2);
double ratio = length/width;
// Derived constant based on: https://math.stackexchange.com/a/1921940
// Clamped to 3 as higher values tend to rapidly drag the estimate to zero.
double a = (d * d) / fmin(3, ratio); We get better result:
But we can get an even better estimation, by removing the capping to 3: double d1 = fabs(p1.lng - p2.lng);
double d2 = fabs(p1.lat - p2.lat);
double length = fmax(d1, d2);
double width = fmin(d1, d2);
double ratio = length/width;
// Derived constant based on: https://math.stackexchange.com/a/1921940
double a = (d * d) / ratio; Now we get
Given that the polyfill of your shape actually returns ~20k cells at res 15, we only over-estimate by a factor 3.5 (instead of ~x17,000) Now those are just my 2 cents, I'm not an expert on H3 internals though ^^ |
Thanks for your detailed analysis @grim7reaper. I would be more than happy even with your first example where capping to 3 is still present. Shall I create a pull request containing these changes? |
At first I didn't understand how the formula from the linked Stackexchange issue was reduced from |
Yes, I think you can make a PR (not sure if it breaks any existing tests though).
Yup, that's my guess too, probably considered that |
* ratio for calculation of bbox area should always be > 1 (#708) * Add unit test for bboxHexEstimate ratio fix * Use reasonable test data and fix unit test. * Apply suggestions from code review Co-authored-by: Nick Rabinowitz <public@nickrabinowitz.com> Co-authored-by: Nick Rabinowitz <public@nickrabinowitz.com>
I noticed that
maxPolygonToCellsSize
is giving me numbers way too big for my input geometries. I could track it down tobboxHexEstimate
. There the calculated area is way to big.Here is an example geometry:
Polygon ((7.54402069689999966 47.13895667900000319, 7.54419258430000017 47.13895667900000319, 7.54419258430000017 47.15093149700000197, 7.54402069689999966 47.15093149700000197, 7.54402069689999966 47.13895667900000319))
It is a street. So it is quite long but narrow.
bboxHexEstimate
calculates a distance (bbox diagonal) of 1.33km. This sounds about right. But the calculated area then is 103.87km2 which is way too big. We callpolygonToCells
with an index resolution of 15 and this causes memory problems in our application.I do not understand your formula to calculate the bbox area:
double a = d * d / fmin(3.0, fabs((p1.lng - p2.lng) / (p1.lat - p2.lat)));
But it seems to work really bad for bboxes where one side is much much longer than the other.
Do you have any idea how to fix this?
The text was updated successfully, but these errors were encountered: