5

How can I create a spatial binning similar to or directly using Uber from QGIS UI?

Are there plugins available to achieve the desired task?

Taras
  • 32,823
  • 4
  • 66
  • 137
Georg Heiler
  • 401
  • 3
  • 12
  • 4
    If you explain how Uber H3 does spatial binning, you're more likely to get a useful answer. Otherwise the only people who can answer would be those who know both Uber H3 and QGIS, which may be a very small number of people. – csk Feb 01 '19 at 17:36
  • It looks like https://eng.uber.com/h3/ and mostly consists of hexagons. A solution in python would also be great. – Georg Heiler Feb 01 '19 at 18:42

4 Answers4

7

You can play with it using my #30DayMapChallenge hexagon demo https://github.com/ThomasG77/30DayMapChallenge/blob/master/day4_hexagons/data/h3-processing.py

Except the fact I do no use an UI, I combine both QGIS and Uber H3 Python library.

I clearly do not use all parts of the H3 Python library. I suppose the example could help you getting started.

Edit 2022-05-20

New QGIS plugin "H3 Toolkit" unrelated to me but doing more or less the same. Although we provide the link, install it directly from QGIS plugins list.

ThomasG77
  • 30,725
  • 1
  • 53
  • 93
  • Thanks Thomas. You're implementation was very helpful. I adapted it to generate hex grids for the extent of an input layer: https://github.com/maphew/code/blob/master/gis/qgis/h3-grid-from-layer.py – matt wilkie Feb 03 '21 at 07:00
  • Thanks mat wilkie. I cant run the script.I get the error: File "", line 55, in IndexError: list index out of range – Torsten Mar 02 '21 at 20:03
  • At https://github.com/maphew/code/blob/master/gis/qgis/h3-grid-from-layer.py#L55, the code is mylayer = QgsProject.instance().mapLayersByName(area_of_interest)[0]. It means QgsProject.instance().mapLayersByName(area_of_interest) is an empty list [] and you can't get the first element with [0]. That's why it throws an error – ThomasG77 Mar 02 '21 at 22:40
  • Thanks Thomas. That bug is now fixed, and a couple more besides. Results posted at https://gis.stackexchange.com/a/408312/108 – matt wilkie Aug 14 '21 at 05:58
6

I adapted @ThomasG77's 30 day challenge script into something that can be run from the Qgis processing toolbox.

Using Uber's H3 hex grid system in Qgis

https://github.com/maphew/code/tree/master/gis/qgis - h3-grid-from-layer.py

Usage

after Preparation has been completed

From Qgis:

  1. Select a template layer in table of contents to get extent from
    1. Optionally select specific features
  2. Processing tool box >> Open existing script: h3-grid-from-layer.py
  3. OR: Plugins >> Python console >> Open editor >> load script: h3-grid-from-layer.py
  4. Edit variables (particularly min/max resolution levels)
  5. Run

There is an error message of "it seems there is no valid script to run", but it works anyway.

screenshot: select extents layer, open script screenshot: edit min/max hexes screenshot: result

matt wilkie
  • 28,176
  • 35
  • 147
  • 280
1

There's the official https://github.com/uber/h3-py

Python bindings for H3, a hierarchical hexagonal geospatial indexing system https://uber.github.io/h3/

but I haven't tried it myself.

underdark
  • 84,148
  • 21
  • 231
  • 413
1

Use the Create Grid tool in QGIS, and select hexagons.

For a more thorough, but still brief walk-through, see Jonathan Soma's blog.

(This is for creating a hex grid, it will not be specific to Uber's H3 grids. If you know the positioning and spacing of that grid you could use those numbers with this tool.)

Unrelated
  • 191
  • 5