ST_MapPolygonsToGrid
Map polygon geometries that are contained in a table to grid cells.
Syntax
ST_MapPolygonsToGrid(gridsize, table, col[, debug[, srid[, idcol[, includeAllCols]]]])
- gridsize
- The grid size in degrees. Possible values:
If the grid table doesn't already exist, it will be created.1 0.1 0.01Type: DOUBLE
- table
- The table that contains the polygons to be mapped.
Type: VARCHAR(ANY)
- col
- The column that contains the polygons to be mapped.
Type: VARCHAR(ANY)
- debug
- Whether to enable debug messages and preserve all intermediate tables.
Type: BOOLEAN
Default: FALSE
- srid
- The SRID used to initialize the grid.
Type: INTEGER
- idcol
- The column of the input table that contains the identifier of each of the input polygon
geometries.
Type: VARCHAR(ANY)
- includeAllCols
- If the value of this parameter is TRUE, the output table is augmented to include, in addition to
its other columns, all the columns of the input table.
Type: BOOLEAN
Default: FALSE
Returns
This function returns two outputs:
- A value of type INTEGER that is 0 if the function was successful or 1 if an error occurred.
- A table with one row for each intersection of an input polygon geometry with a grid cell. Each
row of the output table has the following columns:
- ID_COLUMN
- The identifier from the column of the input table that was specified by the idcol parameter.
- GEOM_COLUMN
- GRID_ID
- GRID_GEOMETRY
Examples
set PATH=inza.inza;
create table POINTS (ID INTEGER, MY_GEOM ST_GEOMETRY(64000)); insert into POINTS VALUES (1,
inza..ST_WKTToSQL('Point (1.1 1.1)'));
insert into POINTS VALUES (2, inza..ST_WKTToSQL('Point (2.2 2.2)'));
insert into POINTS VALUES (3, inza..ST_WKTToSQL('Point (3.3 3.3)'));
alter table points owner to inzauser;
call inza..ST_MAPPOLYGONSTOGRID(1,'POINTS','MY_GEOM',false,4326,'ID',true);
select ID, inza..ST_ASTEXT(MY_GEOM), ONEGID, inza..ST_ASTEXT(ONEGRID_GEOM) from POINTS_ONE_GRIDMAP;
drop table POINTS_ONE_GRIDMAP;
drop table POINTS;
drop table GRID_ONE_GEOMETRIES;
delete from GEOMETRY_COLUMNS where F_TABLE_NAME='POINTS_ONE_GRIDMAP';
ST_MAPPOLYGONSTOGRID
--------------------
0
(1 row)
ID | ST_ASTEXT | ONEGID | ST_ASTEXT
---+-----------------+--------+-------------------------------------
2 | POINT (2.2 2.2) | 92182 | POLYGON ((2 2, 3 2, 3 3, 2 3, 2 2))
3 | POINT (3.3 3.3) | 93183 | POLYGON ((3 3, 4 3, 4 4, 3 4, 3 3))
1 | POINT (1.1 1.1) | 91181 | POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))
(3 rows)