PostGIS  3.4.0dev-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 geom
Returns
ES_NONE if success, ES_ERROR if error
Parameters
raster: the raster to get info from
**env: pointer to envelope
Returns
ES_NONE if success, ES_ERROR if error

Definition at line 705 of file rt_geometry.c.

705  {
706  double gt[6] = {0.0};
707  int32_t srid = SRID_UNKNOWN;
708 
709  POINTARRAY *pts = NULL;
710  POINT4D p4d;
711 
712  assert(env != NULL);
713  *env = NULL;
714 
715  /* raster is NULL, envelope is NULL */
716  if (raster == NULL)
717  return ES_NONE;
718 
719  /* raster metadata */
720  srid = rt_raster_get_srid(raster);
722 
724  3,
725  "rt_raster_get_envelope: raster is %dx%d",
726  raster->width,
727  raster->height
728  );
729 
730  /* return point or line since at least one of the two dimensions is 0 */
731  if ((!raster->width) || (!raster->height)) {
732  p4d.x = gt[0];
733  p4d.y = gt[3];
734 
735  /* return point */
736  if (!raster->width && !raster->height) {
737  LWPOINT *point = lwpoint_make2d(srid, p4d.x, p4d.y);
738  *env = lwpoint_as_lwgeom(point);
739  }
740  /* return linestring */
741  else {
742  LWLINE *line = NULL;
743  pts = ptarray_construct_empty(0, 0, 2);
744 
745  /* first point of line */
746  ptarray_append_point(pts, &p4d, LW_TRUE);
747 
748  /* second point of line */
750  raster,
752  &p4d.x, &p4d.y,
753  gt
754  ) != ES_NONE) {
755  rterror("rt_raster_get_envelope: Could not get second point for linestring");
756  return ES_ERROR;
757  }
758  ptarray_append_point(pts, &p4d, LW_TRUE);
759  line = lwline_construct(srid, NULL, pts);
760 
761  *env = lwline_as_lwgeom(line);
762  }
763 
764  return ES_NONE;
765  }
766  else {
767  rt_envelope rtenv;
768  int err = ES_NONE;
769  POINTARRAY **rings = NULL;
770  LWPOLY* poly = NULL;
771 
772  /* only one ring */
773  rings = (POINTARRAY **) rtalloc(sizeof (POINTARRAY*));
774  if (!rings) {
775  rterror("rt_raster_get_envelope_geom: Could not allocate memory for polygon ring");
776  return ES_ERROR;
777  }
778  rings[0] = ptarray_construct(0, 0, 5);
779  if (!rings[0]) {
780  rterror("rt_raster_get_envelope_geom: Could not construct point array");
781  return ES_ERROR;
782  }
783  pts = rings[0];
784 
785  err = rt_raster_get_envelope(raster, &rtenv);
786  if (err != ES_NONE) {
787  rterror("rt_raster_get_envelope_geom: Could not get raster envelope");
788  return err;
789  }
790 
791  /* build ring */
792 
793  /* minx, maxy */
794  p4d.x = rtenv.MinX;
795  p4d.y = rtenv.MaxY;
796  ptarray_set_point4d(pts, 0, &p4d);
797  ptarray_set_point4d(pts, 4, &p4d);
798 
799  /* maxx, maxy */
800  p4d.x = rtenv.MaxX;
801  p4d.y = rtenv.MaxY;
802  ptarray_set_point4d(pts, 1, &p4d);
803 
804  /* maxx, miny */
805  p4d.x = rtenv.MaxX;
806  p4d.y = rtenv.MinY;
807  ptarray_set_point4d(pts, 2, &p4d);
808 
809  /* minx, miny */
810  p4d.x = rtenv.MinX;
811  p4d.y = rtenv.MinY;
812  ptarray_set_point4d(pts, 3, &p4d);
813 
814  poly = lwpoly_construct(srid, 0, 1, rings);
815  *env = lwpoly_as_lwgeom(poly);
816  }
817 
818  return ES_NONE;
819 }
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:339
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:329
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
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
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:147
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
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:369
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:219
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
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:759
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:360
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:306
@ ES_NONE
Definition: librtcore.h:182
@ ES_ERROR
Definition: librtcore.h:183
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:133
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:125
rt_errorstate rt_raster_get_envelope(rt_raster raster, rt_envelope *env)
Get raster's envelope.
Definition: rt_raster.c:904
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:710
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:78
double x
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
double MinX
Definition: librtcore.h:167
double MaxX
Definition: librtcore.h:168
double MinY
Definition: librtcore.h:169
double MaxY
Definition: librtcore.h:170

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: