PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ rt_util_envelope_to_lwpoly()

LWPOLY* rt_util_envelope_to_lwpoly ( rt_envelope  ext)

Definition at line 439 of file rt_util.c.

441  {
442  LWPOLY *npoly = NULL;
443  POINTARRAY **rings = NULL;
444  POINTARRAY *pts = NULL;
445  POINT4D p4d;
446 
447  rings = (POINTARRAY **) rtalloc(sizeof (POINTARRAY*));
448  if (!rings) {
449  rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry");
450  return NULL;
451  }
452  rings[0] = ptarray_construct(0, 0, 5);
453  if (!rings[0]) {
454  rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry ring");
455  return NULL;
456  }
457 
458  pts = rings[0];
459 
460  /* Upper-left corner (first and last points) */
461  p4d.x = env.MinX;
462  p4d.y = env.MaxY;
463  ptarray_set_point4d(pts, 0, &p4d);
464  ptarray_set_point4d(pts, 4, &p4d);
465 
466  /* Upper-right corner (we go clockwise) */
467  p4d.x = env.MaxX;
468  p4d.y = env.MaxY;
469  ptarray_set_point4d(pts, 1, &p4d);
470 
471  /* Lower-right corner */
472  p4d.x = env.MaxX;
473  p4d.y = env.MinY;
474  ptarray_set_point4d(pts, 2, &p4d);
475 
476  /* Lower-left corner */
477  p4d.x = env.MinX;
478  p4d.y = env.MinY;
479  ptarray_set_point4d(pts, 3, &p4d);
480 
481  npoly = lwpoly_construct(SRID_UNKNOWN, 0, 1, rings);
482  if (npoly == NULL) {
483  rterror("rt_util_envelope_to_lwpoly: Could not build envelope's geometry");
484  return NULL;
485  }
486 
487  return npoly;
488 }
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:51
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:376
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
double x
Definition: liblwgeom.h:400
double y
Definition: liblwgeom.h:400

References lwpoly_construct(), rt_envelope::MaxX, rt_envelope::MaxY, rt_envelope::MinX, rt_envelope::MinY, ptarray_construct(), ptarray_set_point4d(), rtalloc(), rterror(), SRID_UNKNOWN, POINT4D::x, and POINT4D::y.

Referenced by rt_raster_compute_skewed_raster().

Here is the call graph for this function:
Here is the caller graph for this function: