PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWPOLY* rt_util_envelope_to_lwpoly ( rt_envelope  ext)

Definition at line 543 of file rt_api.c.

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(), and rt_raster_gdal_rasterize().

545  {
546  LWPOLY *npoly = NULL;
547  POINTARRAY **rings = NULL;
548  POINTARRAY *pts = NULL;
549  POINT4D p4d;
550 
551  rings = (POINTARRAY **) rtalloc(sizeof (POINTARRAY*));
552  if (!rings) {
553  rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry");
554  return NULL;
555  }
556  rings[0] = ptarray_construct(0, 0, 5);
557  if (!rings[0]) {
558  rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry ring");
559  return NULL;
560  }
561 
562  pts = rings[0];
563 
564  /* Upper-left corner (first and last points) */
565  p4d.x = env.MinX;
566  p4d.y = env.MaxY;
567  ptarray_set_point4d(pts, 0, &p4d);
568  ptarray_set_point4d(pts, 4, &p4d);
569 
570  /* Upper-right corner (we go clockwise) */
571  p4d.x = env.MaxX;
572  p4d.y = env.MaxY;
573  ptarray_set_point4d(pts, 1, &p4d);
574 
575  /* Lower-right corner */
576  p4d.x = env.MaxX;
577  p4d.y = env.MinY;
578  ptarray_set_point4d(pts, 2, &p4d);
579 
580  /* Lower-left corner */
581  p4d.x = env.MinX;
582  p4d.y = env.MinY;
583  ptarray_set_point4d(pts, 3, &p4d);
584 
585  npoly = lwpoly_construct(SRID_UNKNOWN, 0, 1, rings);
586  if (npoly == NULL) {
587  rterror("rt_util_envelope_to_lwpoly: Could not build envelope's geometry");
588  return NULL;
589  }
590 
591  return npoly;
592 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:501
double x
Definition: liblwgeom.h:308
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:49
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:29
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
double y
Definition: liblwgeom.h:308

Here is the call graph for this function:

Here is the caller graph for this function: