| 1 | = Create Fishnet Grid = |
| 2 | |
| 3 | Make a 2D grid of rectangular polygons, which is sometimes called a fishnet grid. |
| 4 | |
| 5 | Use the following source: |
| 6 | {{{ |
| 7 | CREATE OR REPLACE FUNCTION ST_CreateFishnet( |
| 8 | nrow integer, ncol integer, |
| 9 | xsize float8, ysize float8, |
| 10 | x0 float8 DEFAULT 0, y0 float8 DEFAULT 0) |
| 11 | RETURNS SETOF geometry AS |
| 12 | $$ |
| 13 | SELECT ST_Translate(cell, j * $3 + $5, i * $4 + $6) |
| 14 | FROM generate_series(0, $1 - 1) AS i, |
| 15 | generate_series(0, $2 - 1) AS j, |
| 16 | ( |
| 17 | SELECT ('POLYGON((0 0, 0 '||$4||', '||$3||' '||$4||', '||$3||' 0,0 0))')::geometry AS cell |
| 18 | ) AS foo; |
| 19 | $$ LANGUAGE sql IMMUTABLE STRICT; |
| 20 | }}} |
| 21 | |
| 22 | Example: |
| 23 | {{{ |
| 24 | SELECT ST_Collect(cells) |
| 25 | FROM ST_CreateFishnet(3,4,10,10) AS cells; |
| 26 | }}} |
| 27 | [[Image(http://i.stack.imgur.com/vQY0Z.png)]] |