PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum ST_MakeEnvelope ( PG_FUNCTION_ARGS  )

Definition at line 2064 of file lwgeom_functions_basic.c.

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

2065 {
2066  LWPOLY *poly;
2068  POINTARRAY **pa;
2069  POINT4D p;
2070  double x1, y1, x2, y2;
2071  int srid = SRID_UNKNOWN;
2072 
2073  POSTGIS_DEBUG(2, "ST_MakeEnvelope called");
2074 
2075  x1 = PG_GETARG_FLOAT8(0);
2076  y1 = PG_GETARG_FLOAT8(1);
2077  x2 = PG_GETARG_FLOAT8(2);
2078  y2 = PG_GETARG_FLOAT8(3);
2079  if ( PG_NARGS() > 4 ) {
2080  srid = PG_GETARG_INT32(4);
2081  }
2082 
2083  pa = (POINTARRAY**)palloc(sizeof(POINTARRAY**));
2084  pa[0] = ptarray_construct_empty(0, 0, 5);
2085 
2086  /* 1st point */
2087  p.x = x1;
2088  p.y = y1;
2089  ptarray_append_point(pa[0], &p, LW_TRUE);
2090 
2091  /* 2nd point */
2092  p.x = x1;
2093  p.y = y2;
2094  ptarray_append_point(pa[0], &p, LW_TRUE);
2095 
2096  /* 3rd point */
2097  p.x = x2;
2098  p.y = y2;
2099  ptarray_append_point(pa[0], &p, LW_TRUE);
2100 
2101  /* 4th point */
2102  p.x = x2;
2103  p.y = y1;
2104  ptarray_append_point(pa[0], &p, LW_TRUE);
2105 
2106  /* 5th point */
2107  p.x = x1;
2108  p.y = y1;
2109  ptarray_append_point(pa[0], &p, LW_TRUE);
2110 
2111  poly = lwpoly_construct(srid, NULL, 1, pa);
2113 
2114  result = geometry_serialize(lwpoly_as_lwgeom(poly));
2115  lwpoly_free(poly);
2116 
2117  PG_RETURN_POINTER(result);
2118 }
double x
Definition: liblwgeom.h:308
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
char ** result
Definition: liblwgeom.h:218
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:239
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:29
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:79
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:555
double y
Definition: liblwgeom.h:308

Here is the call graph for this function: