uber / uber/h3

bboxHexEstimate: Calculated area is way too big

Open
#708 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
6.5k
Forks
627
Avg merge
3d 21h
Merged PRs (30d)
6

Description

I noticed that maxPolygonToCellsSize is giving me numbers way too big for my input geometries. I could track it down to bboxHexEstimate. 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))

CleanShot 2022-10-07 at 16 05 38

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 call polygonToCells 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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading bboxHexEstimate and its caller, maxPolygonToCellsSize, then trace how polygonToCells uses the estimate. Reproduce the provided narrow, elongated polygon and inspect the diagonal, aspect-ratio, and area calculations. Done means the estimate reflects the bounding box dimensions without causing excessive memory use at resolution 15, with regression coverage if the existing test structure is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.