PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ rt_raster_pixel_as_polygon()

LWPOLY* rt_raster_pixel_as_polygon ( rt_raster  rast,
int  x,
int  y 
)

Get a raster pixel as a polygon.

The pixel shape is a 4 vertices (5 to be closed) single ring polygon bearing the raster's rotation and using projection coordinates

Parameters
raster: the raster to get pixel from
x: the column number
y: the row number
Returns
the pixel polygon, or NULL on error.

Definition at line 607 of file rt_geometry.c.

608 {
609  double scale_x, scale_y;
610  double skew_x, skew_y;
611  double ul_x, ul_y;
612  int32_t srid;
613  POINTARRAY **points;
614  POINT4D p, p0;
615  LWPOLY *poly;
616 
617  assert(rast != NULL);
618 
619  scale_x = rt_raster_get_x_scale(rast);
620  scale_y = rt_raster_get_y_scale(rast);
621  skew_x = rt_raster_get_x_skew(rast);
622  skew_y = rt_raster_get_y_skew(rast);
625  srid = rt_raster_get_srid(rast);
626 
627  points = rtalloc(sizeof(POINTARRAY *)*1);
628  points[0] = ptarray_construct(0, 0, 5);
629 
630  p0.x = scale_x * x + skew_x * y + ul_x;
631  p0.y = scale_y * y + skew_y * x + ul_y;
632  ptarray_set_point4d(points[0], 0, &p0);
633 
634  p.x = p0.x + scale_x;
635  p.y = p0.y + skew_y;
636  ptarray_set_point4d(points[0], 1, &p);
637 
638  p.x = p0.x + scale_x + skew_x;
639  p.y = p0.y + scale_y + skew_y;
640  ptarray_set_point4d(points[0], 2, &p);
641 
642  p.x = p0.x + skew_x;
643  p.y = p0.y + scale_y;
644  ptarray_set_point4d(points[0], 3, &p);
645 
646  /* close it */
647  ptarray_set_point4d(points[0], 4, &p0);
648 
649  poly = lwpoly_construct(srid, NULL, 1, points);
650 
651  return poly;
652 }
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
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 * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:360
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:185
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:217
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:154
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:163
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:194
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:226
double x
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414

References lwpoly_construct(), ptarray_construct(), ptarray_set_point4d(), rtpixdump::rast, rt_raster_get_srid(), rt_raster_get_x_offset(), rt_raster_get_x_scale(), rt_raster_get_x_skew(), rt_raster_get_y_offset(), rt_raster_get_y_scale(), rt_raster_get_y_skew(), rtalloc(), POINT4D::x, pixval::x, POINT4D::y, and pixval::y.

Referenced by RASTER_getPixelPolygons(), RASTER_nearestValue(), and test_raster_pixel_as_polygon().

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