Changes between Version 2 and Version 3 of UsersWikiCreateFishnet
- Timestamp:
- 06/16/13 21:25:18 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UsersWikiCreateFishnet
v2 v3 3 3 Make a 2D grid of rectangular polygons, which is sometimes called a fishnet grid. 4 4 5 Use the following source :5 Use the following source for a set returning function: 6 6 {{{ 7 7 CREATE OR REPLACE FUNCTION ST_CreateFishnet( 8 8 nrow integer, ncol integer, 9 9 xsize float8, ysize float8, 10 x0 float8 DEFAULT 0, y0 float8 DEFAULT 0) 11 RETURNS SETOF geometry AS 10 x0 float8 DEFAULT 0, y0 float8 DEFAULT 0, 11 OUT "row" integer, OUT col integer, 12 OUT geom geometry) 13 RETURNS SETOF record AS 12 14 $$ 13 SELECT ST_Translate(cell, j * $3 + $5, i * $4 + $6)15 SELECT i + 1 AS row, j + 1 AS col, ST_Translate(cell, j * $3 + $5, i * $4 + $6) AS geom 14 16 FROM generate_series(0, $1 - 1) AS i, 15 17 generate_series(0, $2 - 1) AS j, … … 19 21 $$ LANGUAGE sql IMMUTABLE STRICT; 20 22 }}} 21 Where :23 Where input parameters: 22 24 {{{nrow}}} integer:: 23 25 number of rows in ''y''-direction … … 33 35 origin offset in ''y''-direction; DEFAULT is 0 34 36 37 Returning output parameters are: 38 {{{row}}} integer:: 39 row number, starting from 1 at the bottom 40 {{{col}}} integer:: 41 column number, starting from 1 at the left 42 {{{geom}}} geometry:: 43 grid cell geometry 44 35 45 Example: 36 46 {{{ 37 SELECT ST_Collect(cells )38 FROM ST_CreateFishnet(4, 6,10,10) AS cells;47 SELECT ST_Collect(cells.geom) 48 FROM ST_CreateFishnet(4, 6, 10, 10) AS cells; 39 49 }}} 40 50 [[Image(http://i.stack.imgur.com/vQY0Z.png)]]