PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ ST_MakeEnvelope()

Datum ST_MakeEnvelope ( PG_FUNCTION_ARGS  )

Definition at line 2059 of file lwgeom_functions_basic.c.

References geometry_serialize(), LW_TRUE, lwgeom_add_bbox(), lwpoly_as_lwgeom(), lwpoly_construct(), lwpoly_free(), PG_FUNCTION_INFO_V1(), ptarray_append_point(), ptarray_construct_empty(), SRID_UNKNOWN, ST_IsCollection(), POINT4D::x, and POINT4D::y.

Referenced by LWGEOM_same().

2060 {
2061  LWPOLY *poly;
2062  GSERIALIZED *result;
2063  POINTARRAY **pa;
2064  POINT4D p;
2065  double x1, y1, x2, y2;
2066  int srid = SRID_UNKNOWN;
2067 
2068  POSTGIS_DEBUG(2, "ST_MakeEnvelope called");
2069 
2070  x1 = PG_GETARG_FLOAT8(0);
2071  y1 = PG_GETARG_FLOAT8(1);
2072  x2 = PG_GETARG_FLOAT8(2);
2073  y2 = PG_GETARG_FLOAT8(3);
2074  if ( PG_NARGS() > 4 ) {
2075  srid = PG_GETARG_INT32(4);
2076  }
2077 
2078  pa = (POINTARRAY**)palloc(sizeof(POINTARRAY**));
2079  pa[0] = ptarray_construct_empty(0, 0, 5);
2080 
2081  /* 1st point */
2082  p.x = x1;
2083  p.y = y1;
2084  ptarray_append_point(pa[0], &p, LW_TRUE);
2085 
2086  /* 2nd point */
2087  p.x = x1;
2088  p.y = y2;
2089  ptarray_append_point(pa[0], &p, LW_TRUE);
2090 
2091  /* 3rd point */
2092  p.x = x2;
2093  p.y = y2;
2094  ptarray_append_point(pa[0], &p, LW_TRUE);
2095 
2096  /* 4th point */
2097  p.x = x2;
2098  p.y = y1;
2099  ptarray_append_point(pa[0], &p, LW_TRUE);
2100 
2101  /* 5th point */
2102  p.x = x1;
2103  p.y = y1;
2104  ptarray_append_point(pa[0], &p, LW_TRUE);
2105 
2106  poly = lwpoly_construct(srid, NULL, 1, pa);
2108 
2109  result = geometry_serialize(lwpoly_as_lwgeom(poly));
2110  lwpoly_free(poly);
2111 
2112  PG_RETURN_POINTER(result);
2113 }
double x
Definition: liblwgeom.h:351
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:252
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:152
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:612
double y
Definition: liblwgeom.h:351
Here is the call graph for this function:
Here is the caller graph for this function: