![]() There are a couple reasons I want a table of H3 hexes.įirst, I want to be able to run a spatial analysis and find areas where With nearest neighbor style searches, I really wanted to get to the point where IĬould create a grid of hexes, similar to Step 2 in While many examples using H3 will be most interested in that type of operation coupled The prior example showed how existing geometry data can be assigned to an H3 hex. The image above shows that at resolution 6, the selected line fits entirely within a single hexagon. ST_Centroid(ST_Transform(geom, 4326)), 6)), *Īssigning long lines to a hex based on only its centroid may work for some use cases, while others may need to calculate the hex for individual nodes within the line for best results. The ST_Transform() was required, as my default geometry data is in SRID 3857. This step with h3_to_geo_boundary_geometry() that I realized that To help verify it is working the way I assume it is. The H3 index is a big part of what makes the really cool stuff work,īut for now all I want to see the geometry. The following query selects a single road segment, transforms it to SRID 4326,Ĭalculates the centroid and determines the hex index for resolution 6. ERROR: geometry_to_point only accepts Points The h3_geo_to_h3() function results in an error. I found the first caveat because one of my most commonly used tables from The h3_geo_to_h3 function does exactly this. With a database full of OpenStreetMap data loaded via PgOSM Flex, my next step is to grab some data and see The generate_series() function is useful in so many ways! Index from geometry ![]() The H3 extension comes with a h3_num_hexagons(resolution int4) function thatĪlso provides the hexagon counts for a given resolution. Resolutions 5 through 8 end up being the most helpful to me. Resolution 6 starts gettingĭecently large (14 million hexagons) and resolution 15 is large by all means, With only 122 hexagons for the entire globe. Shows these resolutions with average size details and the number of unique The Table of Cell Areas for H3 Resolutions H3 uses 16 resolutions (zoom level) from 0 to 15. This helped me to start understanding how the various functions work Once installed, create the H3 extension in the database. The H3 library is available to PostGIS as a Postgres extension. See my post H3 indexes for performance with PostGIS data for a look into high performance spatial searches with H3. Note: This post does not focus on using H3 for the best performance. One additionalįocus is how to generate a table of H3 hexagons for a given resolution. This post works through a few of the functions available in the H3 extensionĪnd how they can be used for spatial aggregation in an analysis. See Using v4 of the Postgres H3 extension for usage in the latest version. On the other hand, the H3 grid is a globally defined grid that scales up and down Though it has shortcomings for larger scale consistency. ![]() The hex grid built-in to PostGIS is great for one-off projects covering a specific region, In my post Find missing crossings in OpenStreetMap with PostGIS. Over the PostGIS native ST_HexagonGrid() function used H3 was developed by Uber and has some cool benefits This post explores using the H3 hex grid system By Ryan Lambert - Published April 24, 2022
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |