Created
February 11, 2018 09:13
-
-
Save mdiener21/65012934208314c7308dada31b47e170 to your computer and use it in GitHub Desktop.
create a survey grid as vector with Postgis as a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION ST_CreateFishnet( | |
nrow integer, ncol integer, | |
xsize float8, ysize float8, | |
x0 float8 DEFAULT 0, y0 float8 DEFAULT 0, | |
OUT "row" integer, OUT col integer, | |
OUT geom geometry) | |
RETURNS SETOF record AS | |
$$ | |
SELECT i + 1 AS row, j + 1 AS col, ST_Translate(cell, j * $3 + $5, i * $4 + $6) AS geom | |
FROM generate_series(0, $1 - 1) AS i, | |
generate_series(0, $2 - 1) AS j, | |
( | |
SELECT ('POLYGON((0 0, 0 '||$4||', '||$3||' '||$4||', '||$3||' 0,0 0))')::geometry AS cell | |
) AS foo; | |
$$ LANGUAGE sql IMMUTABLE STRICT; | |
SELECT ST_Collect(cells.geom) | |
FROM ST_CreateFishnet(4, 6, 10, 10) AS cells; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment