PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ST_Square()

Datum ST_Square ( PG_FUNCTION_ARGS  )

Definition at line 387 of file lwgeom_generate_grid.c.

388{
389 LWPOINT *lwpt;
390 double size = PG_GETARG_FLOAT8(0);
391 GSERIALIZED *gsqr;
392 int cell_i = PG_GETARG_INT32(1);
393 int cell_j = PG_GETARG_INT32(2);
394 GSERIALIZED *gorigin = PG_GETARG_GSERIALIZED_P(3);
395 LWGEOM *lwsqr;
396 LWGEOM *lworigin = lwgeom_from_gserialized(gorigin);
397
398 if (lwgeom_is_empty(lworigin))
399 {
400 elog(ERROR, "%s: origin point is empty", __func__);
401 PG_RETURN_NULL();
402 }
403
404 lwpt = lwgeom_as_lwpoint(lworigin);
405 if (!lwpt)
406 {
407 elog(ERROR, "%s: origin argument is not a point", __func__);
408 PG_RETURN_NULL();
409 }
410
411 lwsqr = square(lwpoint_get_x(lwpt), lwpoint_get_y(lwpt),
412 size, cell_i, cell_j,
413 lwgeom_get_srid(lworigin));
414
415 gsqr = geometry_serialize(lwsqr);
416 PG_FREE_IF_COPY(gorigin, 3);
417 PG_RETURN_POINTER(gsqr);
418}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition lwgeom.c:955
double lwpoint_get_x(const LWPOINT *point)
Definition lwpoint.c:63
double lwpoint_get_y(const LWPOINT *point)
Definition lwpoint.c:76
static LWGEOM * square(double origin_x, double origin_y, double size, int cell_i, int cell_j, int32_t srid)
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition lwinline.h:127
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199

References lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_get_srid(), lwgeom_is_empty(), lwpoint_get_x(), lwpoint_get_y(), and square().

Here is the call graph for this function: