2

The gist of this is pretty straight forward, even if the implementation isn't...


I want to get the outside edges of a hexRing, as opposed to all edges of the hexagons. Pretty much creating a single polygon from the outside edge of the ring encompassing everything inside of it. Currently we can use geojson2h3.h3SetToFeature() which uses h3SetToMultiPolygon() to create that polygon.

This looks like:

HexRingPolygon:

enter image description here

Instead, I want to get just the outside edge, which would look like the following:

Outside Edges:

enter image description here

To achieve just an outside border, I'm currently using kRing(), however, the performance characteristics of this become unusable on mobile devices in a variety of scenarios due to the number of hexagons contained in that region. Where as a hexRing() would have a minimal number of hexagons to work with.


How can I achieve this?

Douglas Gaskell
  • 9,017
  • 9
  • 71
  • 128

1 Answers1

3

The H3-centric answer is to use the K-ring, as you suggest, but this is definitely more calculation (likely slower in both calculating the set of hexes and calculating the outline).

The easy answer here is to use the output of h3SetToMultiPolygon and simply drop the second ring from the geojson. The format of the geojson is

{
  "type": "Feature",
  "geometry": {
    "type": "MultiPolygon",
    "coordinates": [
      // list of polygons, there's only one in your case
      [
        // list of loops: first is outline, the rest are holes
        [...],
        [...]
      ]
    ]
  }
}

So all you need to do is set

geojson.geometry.coordinates[0] = [geojson.geometry.coordinates[0][0]]

which sets the polygon to only the outside ring, dropping the hole (untested, but I think that's right).

nrabinowitz
  • 55,314
  • 10
  • 149
  • 165