PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ rt_util_envelope_to_lwpoly()

LWPOLY * rt_util_envelope_to_lwpoly ( rt_envelope  ext)

Definition at line 588 of file rt_util.c.

590 {
591 LWPOLY *npoly = NULL;
592 POINTARRAY **rings = NULL;
593 POINTARRAY *pts = NULL;
594 POINT4D p4d;
595
596 rings = (POINTARRAY **) rtalloc(sizeof (POINTARRAY*));
597 if (!rings) {
598 rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry");
599 return NULL;
600 }
601 rings[0] = ptarray_construct(0, 0, 5);
602 if (!rings[0]) {
603 rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry ring");
604 return NULL;
605 }
606
607 pts = rings[0];
608
609 /* Upper-left corner (first and last points) */
610 p4d.x = env.MinX;
611 p4d.y = env.MaxY;
612 ptarray_set_point4d(pts, 0, &p4d);
613 ptarray_set_point4d(pts, 4, &p4d);
614
615 /* Upper-right corner (we go clockwise) */
616 p4d.x = env.MaxX;
617 p4d.y = env.MaxY;
618 ptarray_set_point4d(pts, 1, &p4d);
619
620 /* Lower-right corner */
621 p4d.x = env.MaxX;
622 p4d.y = env.MinY;
623 ptarray_set_point4d(pts, 2, &p4d);
624
625 /* Lower-left corner */
626 p4d.x = env.MinX;
627 p4d.y = env.MinY;
628 ptarray_set_point4d(pts, 3, &p4d);
629
630 npoly = lwpoly_construct(SRID_UNKNOWN, 0, 1, rings);
631 if (npoly == NULL) {
632 rterror("rt_util_envelope_to_lwpoly: Could not build envelope's geometry");
633 return NULL;
634 }
635
636 return npoly;
637}
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition lwpoly.c:43
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition lwgeom_api.c:369
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
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:191
double x
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414

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: