Changes between Version 2 and Version 3 of UsersWikiCreateFishnet


Ignore:
Timestamp:
Jun 16, 2013, 9:25:18 PM (9 years ago)
Author:
Mike Taves
Comment:

make a set-returning function instead

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiCreateFishnet

    v2 v3  
    33Make a 2D grid of rectangular polygons, which is sometimes called a fishnet grid.
    44
    5 Use the following source:
     5Use the following source for a set returning function:
    66{{{
    77CREATE OR REPLACE FUNCTION ST_CreateFishnet(
    88        nrow integer, ncol integer,
    99        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
    1214$$
    13 SELECT ST_Translate(cell, j * $3 + $5, i * $4 + $6)
     15SELECT i + 1 AS row, j + 1 AS col, ST_Translate(cell, j * $3 + $5, i * $4 + $6) AS geom
    1416FROM generate_series(0, $1 - 1) AS i,
    1517     generate_series(0, $2 - 1) AS j,
     
    1921$$ LANGUAGE sql IMMUTABLE STRICT;
    2022}}}
    21 Where:
     23Where input parameters:
    2224 {{{nrow}}} integer::
    2325  number of rows in ''y''-direction
     
    3335  origin offset in ''y''-direction; DEFAULT is 0
    3436
     37Returning 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
    3545Example:
    3646{{{
    37 SELECT ST_Collect(cells)
    38 FROM ST_CreateFishnet(4,6,10,10) AS cells;
     47SELECT ST_Collect(cells.geom)
     48FROM ST_CreateFishnet(4, 6, 10, 10) AS cells;
    3949}}}
    4050[[Image(http://i.stack.imgur.com/vQY0Z.png)]]