PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_raster_get_envelope_geom()

rt_errorstate rt_raster_get_envelope_geom ( rt_raster  raster,
LWGEOM **  env 
)

Get raster's envelope as a geometry.

Parameters
raster: the raster to get info from
**env: pointer to envelope
Returns
ES_NONE if success, ES_ERROR if error

Definition at line 670 of file rt_geometry.c.

670  {
671  double gt[6] = {0.0};
672  int srid = SRID_UNKNOWN;
673 
674  POINTARRAY *pts = NULL;
675  POINT4D p4d;
676 
677  assert(env != NULL);
678  *env = NULL;
679 
680  /* raster is NULL, envelope is NULL */
681  if (raster == NULL)
682  return ES_NONE;
683 
684  /* raster metadata */
685  srid = rt_raster_get_srid(raster);
687 
689  3,
690  "rt_raster_get_envelope: raster is %dx%d",
691  raster->width,
692  raster->height
693  );
694 
695  /* return point or line since at least one of the two dimensions is 0 */
696  if ((!raster->width) || (!raster->height)) {
697  p4d.x = gt[0];
698  p4d.y = gt[3];
699 
700  /* return point */
701  if (!raster->width && !raster->height) {
702  LWPOINT *point = lwpoint_make2d(srid, p4d.x, p4d.y);
703  *env = lwpoint_as_lwgeom(point);
704  }
705  /* return linestring */
706  else {
707  LWLINE *line = NULL;
708  pts = ptarray_construct_empty(0, 0, 2);
709 
710  /* first point of line */
711  ptarray_append_point(pts, &p4d, LW_TRUE);
712 
713  /* second point of line */
715  raster,
717  &p4d.x, &p4d.y,
718  gt
719  ) != ES_NONE) {
720  rterror("rt_raster_get_envelope: Could not get second point for linestring");
721  return ES_ERROR;
722  }
723  ptarray_append_point(pts, &p4d, LW_TRUE);
724  line = lwline_construct(srid, NULL, pts);
725 
726  *env = lwline_as_lwgeom(line);
727  }
728 
729  return ES_NONE;
730  }
731  else {
732  rt_envelope rtenv;
733  int err = ES_NONE;
734  POINTARRAY **rings = NULL;
735  LWPOLY* poly = NULL;
736 
737  /* only one ring */
738  rings = (POINTARRAY **) rtalloc(sizeof (POINTARRAY*));
739  if (!rings) {
740  rterror("rt_raster_get_envelope_geom: Could not allocate memory for polygon ring");
741  return ES_ERROR;
742  }
743  rings[0] = ptarray_construct(0, 0, 5);
744  if (!rings[0]) {
745  rterror("rt_raster_get_envelope_geom: Could not construct point array");
746  return ES_ERROR;
747  }
748  pts = rings[0];
749 
750  err = rt_raster_get_envelope(raster, &rtenv);
751  if (err != ES_NONE) {
752  rterror("rt_raster_get_envelope_geom: Could not get raster envelope");
753  return err;
754  }
755 
756  /* build ring */
757 
758  /* minx, maxy */
759  p4d.x = rtenv.MinX;
760  p4d.y = rtenv.MaxY;
761  ptarray_set_point4d(pts, 0, &p4d);
762  ptarray_set_point4d(pts, 4, &p4d);
763 
764  /* maxx, maxy */
765  p4d.x = rtenv.MaxX;
766  p4d.y = rtenv.MaxY;
767  ptarray_set_point4d(pts, 1, &p4d);
768 
769  /* maxx, miny */
770  p4d.x = rtenv.MaxX;
771  p4d.y = rtenv.MinY;
772  ptarray_set_point4d(pts, 2, &p4d);
773 
774  /* minx, miny */
775  p4d.x = rtenv.MinX;
776  p4d.y = rtenv.MinY;
777  ptarray_set_point4d(pts, 3, &p4d);
778 
779  poly = lwpoly_construct(srid, 0, 1, rings);
780  *env = lwpoly_as_lwgeom(poly);
781  }
782 
783  return ES_NONE;
784 }
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:320
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
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
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_FALSE,...
Definition: ptarray.c:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:435
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
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
Definition: rt_raster.c:755
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:356
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
rt_errorstate rt_raster_get_envelope(rt_raster raster, rt_envelope *env)
Get raster's envelope.
Definition: rt_raster.c:873
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:706
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
gt
Definition: window.py:77
double x
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
double MinX
Definition: librtcore.h:165
double MaxX
Definition: librtcore.h:166
double MinY
Definition: librtcore.h:167
double MaxY
Definition: librtcore.h:168

References ES_ERROR, ES_NONE, window::gt, LW_TRUE, lwline_as_lwgeom(), lwline_construct(), lwpoint_as_lwgeom(), lwpoint_make2d(), lwpoly_as_lwgeom(), lwpoly_construct(), rt_envelope::MaxX, rt_envelope::MaxY, rt_envelope::MinX, rt_envelope::MinY, ptarray_append_point(), ptarray_construct(), ptarray_construct_empty(), ptarray_set_point4d(), rtrowdump::raster, RASTER_DEBUGF, rt_raster_cell_to_geopoint(), rt_raster_get_envelope(), rt_raster_get_geotransform_matrix(), rt_raster_get_height(), rt_raster_get_srid(), rt_raster_get_width(), rtalloc(), rterror(), SRID_UNKNOWN, POINT4D::x, and POINT4D::y.

Referenced by RASTER_envelope(), and test_raster_envelope_geom().

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