1

Is the return value of java api kRingDistances orderly?

Does the H3Index of two adjacent cells have other H3Index?

for example,List<List<Long>> result = h3.kRingDistances(index, k)

here is the result: [[613344576152797183], [613344576150700031, 613344574395383807, 613344575655772159, 613344575651577855, 613344576148602879, 613344576146505727], [613344576159088639, 613344574454104063, 613344574393286655, 613344574384898047, 613344574386995199, 613344575647383551, 613344575643189247, 613344575653675007, 613344576167477247, 613344576175865855, 613344576156991487, 613344576154894335]]

1 Answers1

1

I'm not 100% clear on the question, but two answers here:

  • H3 indexes themselves are not ordered sequentially, but indexes that are numerically close to each other are also geographically close. There's an illustration of indexing order here: https://beta.observablehq.com/@nrabinowitz/h3-indexing-order

  • The indexes from kRing are not in guaranteed order. The guarantees here are fairly well explained in the docs - kRing output order is undefined. Other functions like kRingDistances can give you H3 indexes ordered by distance from the origin, but not necessarily ordered within the ring. hexRange and hexRing do guarantee ordered hexagons, but will fail with an error code if they encounter pentagon distortion.

nrabinowitz
  • 55,314
  • 10
  • 149
  • 165
  • Thanks! I have doubts about this sentence: H3 indexes are created by taking the position number (0-6) of a given cell at each resolution of the H3 grid. If the index of these 7 cells is [[613344576152797183], [613344576150700031, 613344574395383807, 613344575655772159, 613344575651577855, 613344576148602879, 613344576146505727]]. Is there another index such as 613344576146505717 between these indexes? Because I want to store these indexes with Redis SortedSet, the score is these indexes. This will enable commands like Redis GEORADIUSBYMEMBER. – Blast of Tempest Dec 25 '18 at 02:48
  • I just discovered H3 a couple of days ago and find the hexagonal approach very clever and appealing. Documentation is a bit terse for me, however, so if I may ask you here since you're one of the pioneers. I'm exploring H3 as a geoquery solution (and finally ditch the ugly geohash we're using now). Geoquerying (in NoSQL anyway) requires performing a single range operation on cell (hexagon) IDs. With H3, can we locate a hexagon, specify how many rings we want around it, and express all of those cells (center + rings) as a single range of hex IDs? – lurning too koad Feb 01 '19 at 01:00
  • @hgale No, probably not. While H3 indexes that are close to each other numerically *are* close geographically, the reverse is not true - a hexagon may border another with a significantly different numeric address (eg if they are children of different base cells). There are various ways to use H3 as a fast geo index (probably worth a different SO question to elaborate), but numeric range isn’t going to be viable. – nrabinowitz Feb 03 '19 at 04:08
  • @BlastofTempest See my answer above. For any given k-ring, there is no guarantee that there are not other valid indexes numerically in between the indexes in the ring - for rings that cross base cells, there could be thousands, or millions at fine resolutions. – nrabinowitz Feb 03 '19 at 04:14