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

Definition at line 1999 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(), SRID_UNKNOWN, POINT4D::x, and POINT4D::y.

2000 {
2001  LWPOLY *poly;
2002  GSERIALIZED *result;
2003  POINTARRAY **pa;
2004  POINT4D p;
2005  double x1, y1, x2, y2;
2006  int srid = SRID_UNKNOWN;
2007 
2008  POSTGIS_DEBUG(2, "ST_MakeEnvelope called");
2009 
2010  x1 = PG_GETARG_FLOAT8(0);
2011  y1 = PG_GETARG_FLOAT8(1);
2012  x2 = PG_GETARG_FLOAT8(2);
2013  y2 = PG_GETARG_FLOAT8(3);
2014  if ( PG_NARGS() > 4 ) {
2015  srid = PG_GETARG_INT32(4);
2016  }
2017 
2018  pa = (POINTARRAY**)palloc(sizeof(POINTARRAY**));
2019  pa[0] = ptarray_construct_empty(0, 0, 5);
2020 
2021  /* 1st point */
2022  p.x = x1;
2023  p.y = y1;
2024  ptarray_append_point(pa[0], &p, LW_TRUE);
2025 
2026  /* 2nd point */
2027  p.x = x1;
2028  p.y = y2;
2029  ptarray_append_point(pa[0], &p, LW_TRUE);
2030 
2031  /* 3rd point */
2032  p.x = x2;
2033  p.y = y2;
2034  ptarray_append_point(pa[0], &p, LW_TRUE);
2035 
2036  /* 4th point */
2037  p.x = x2;
2038  p.y = y1;
2039  ptarray_append_point(pa[0], &p, LW_TRUE);
2040 
2041  /* 5th point */
2042  p.x = x1;
2043  p.y = y1;
2044  ptarray_append_point(pa[0], &p, LW_TRUE);
2045 
2046  poly = lwpoly_construct(srid, NULL, 1, pa);
2048 
2049  result = geometry_serialize(lwpoly_as_lwgeom(poly));
2050  lwpoly_free(poly);
2051 
2052  PG_RETURN_POINTER(result);
2053 }
double x
Definition: liblwgeom.h:336
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: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:156
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:61
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
double y
Definition: liblwgeom.h:336

Here is the call graph for this function: