maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
makegrid_2d(geometry, integer, integer)
Parameters
Name
Type
Mode
bound_polygon
USER-DEFINED
IN
grid_step
integer
IN
metric_srid
integer
IN
Definition
DECLARE BoundM public.geometry; --Bound polygon transformed to the metric projection (with metric_srid SRID) Xmin DOUBLE PRECISION; Xmax DOUBLE PRECISION; Ymax DOUBLE PRECISION; X DOUBLE PRECISION; Y DOUBLE PRECISION; sectors public.geometry[]; i INTEGER; BEGIN BoundM := ST_Transform($1, $3); --From WGS84 (SRID 4326) to the metric projection, to operate with step in meters Xmin := ST_XMin(BoundM); Xmax := ST_XMax(BoundM); Ymax := ST_YMax(BoundM); Y := ST_YMin(BoundM); --current sector's corner coordinate i := -1; <<yloop>> LOOP IF (Y > Ymax) THEN --Better if generating polygons exceeds the bound for one step. You always can crop the result. But if not you may get not quite correct data for outbound polygons (e.g. if you calculate frequency per sector) EXIT; END IF; X := Xmin; <<xloop>> LOOP IF (X > Xmax) THEN EXIT; END IF; i := i + 1; sectors[i] := ST_GeomFromText('POLYGON(('||X||' '||Y||', '||(X+$2)||' '||Y||', '||(X+$2)||' '||(Y+$2)||', '||X||' '||(Y+$2)||', '||X||' '||Y||'))', $3); X := X + $2; END LOOP xloop; Y := Y + $2; END LOOP yloop; RETURN ST_Transform(ST_Collect(sectors), ST_SRID($1)); END;