PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rt_util_envelope_to_lwpoly()

LWPOLY* rt_util_envelope_to_lwpoly ( rt_envelope  env)

Definition at line 435 of file rt_util.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().

437  {
438  LWPOLY *npoly = NULL;
439  POINTARRAY **rings = NULL;
440  POINTARRAY *pts = NULL;
441  POINT4D p4d;
442 
443  rings = (POINTARRAY **) rtalloc(sizeof (POINTARRAY*));
444  if (!rings) {
445  rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry");
446  return NULL;
447  }
448  rings[0] = ptarray_construct(0, 0, 5);
449  if (!rings[0]) {
450  rterror("rt_util_envelope_to_lwpoly: Out of memory building envelope's geometry ring");
451  return NULL;
452  }
453 
454  pts = rings[0];
455 
456  /* Upper-left corner (first and last points) */
457  p4d.x = env.MinX;
458  p4d.y = env.MaxY;
459  ptarray_set_point4d(pts, 0, &p4d);
460  ptarray_set_point4d(pts, 4, &p4d);
461 
462  /* Upper-right corner (we go clockwise) */
463  p4d.x = env.MaxX;
464  p4d.y = env.MaxY;
465  ptarray_set_point4d(pts, 1, &p4d);
466 
467  /* Lower-right corner */
468  p4d.x = env.MaxX;
469  p4d.y = env.MinY;
470  ptarray_set_point4d(pts, 2, &p4d);
471 
472  /* Lower-left corner */
473  p4d.x = env.MinX;
474  p4d.y = env.MinY;
475  ptarray_set_point4d(pts, 3, &p4d);
476 
477  npoly = lwpoly_construct(SRID_UNKNOWN, 0, 1, rings);
478  if (npoly == NULL) {
479  rterror("rt_util_envelope_to_lwpoly: Could not build envelope's geometry");
480  return NULL;
481  }
482 
483  return npoly;
484 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:437
double x
Definition: liblwgeom.h:352
double MinY
Definition: librtcore.h:167
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:62
double MaxY
Definition: librtcore.h:168
double MaxX
Definition: librtcore.h:166
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
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
double MinX
Definition: librtcore.h:165
double y
Definition: liblwgeom.h:352
Here is the call graph for this function:
Here is the caller graph for this function: