zachasme / h3-pg

PostgreSQL bindings for H3, a hierarchical hexagonal geospatial indexing system
Apache License 2.0
273 stars 36 forks source link

Why is h3_cell_to_boundary_geometry bleeding out of the assigned perimeter? #134

Closed asitemade4u closed 1 year ago

asitemade4u commented 1 year ago

Hi, I have a Postgis table describing special districts, ara.lpc_hid. Each of them has a geom column attached. I want to insert the H3 hexagons inside each of these districts into another table, h_3.tst.

So, I followed your conversation with @rbrtmrtn and came up with the following procedure, that worked (I apply it here to a district called Fieldston):

TRUNCATE h_3.tst;
WITH cells AS (
    SELECT h3_polygon_to_cells(st_setsrid(st_extent(H.geom),4326),11) AS hexref FROM ara.lpc_hid AS H WHERE NOT st_isempty(H.geom) AND H.nam_spl='Fieldston'
)
INSERT INTO h_3.tst (ref,res,geom) SELECT hexref,11 AS res,h3_cell_to_boundary_geometry(hexref) FROM cells;

However, here is the result, as visualized in QGis -- in red the district perimeter, in blue the resulting H3 hexagons:

'20230703_193114'

As you can see, the hexagons at resolution 11 are "bleeding" a lot out of the perimeter.

What am I missing here? S.

asitemade4u commented 1 year ago

Sorry Zach, I had not noticed the use of st_extent in your example. My bad. S.