| 1 | = Generate Hexagonal Grid = |
| 2 | |
| 3 | |
| 4 | The following SQL generates a table containing a set of polygons forming |
| 5 | a grid of hexagonal cells. |
| 6 | |
| 7 | Substitute the values in the generate_series calls with the desired min/max X/Y extents. |
| 8 | |
| 9 | |
| 10 | {{{ |
| 11 | CREATE TABLE hex_grid (gid serial not null primary key, the_geom geometry not null); |
| 12 | |
| 13 | INSERT INTO hex_grid (the_geom) |
| 14 | SELECT translate(the_geom, x_series, y_series) |
| 15 | from generate_series(0 - 128, 10000 + 128, 128) as x_series, |
| 16 | generate_series(0 - 128, 10000 + 128, 256) as y_series, |
| 17 | ( |
| 18 | SELECT 'POLYGON((0 0,64 64,64 128,0 192,-64 128,-64 64,0 0))'::geometry as the_geom |
| 19 | UNION |
| 20 | SELECT translate('POLYGON((0 0,64 64,64 128,0 192,-64 128,-64 64,0 0))'::geometry, 64, 128) as the_geom |
| 21 | ) as one_hex |
| 22 | |
| 23 | }}} |