PostGIS  2.4.9dev-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 610 of file rt_geometry.c.

References lwpoly_construct(), ptarray_construct(), ptarray_set_point4d(), 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, and POINT4D::y.

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

611 {
612  double scale_x, scale_y;
613  double skew_x, skew_y;
614  double ul_x, ul_y;
615  int srid;
616  POINTARRAY **points;
617  POINT4D p, p0;
618  LWPOLY *poly;
619 
620  assert(rast != NULL);
621 
622  scale_x = rt_raster_get_x_scale(rast);
623  scale_y = rt_raster_get_y_scale(rast);
624  skew_x = rt_raster_get_x_skew(rast);
625  skew_y = rt_raster_get_y_skew(rast);
626  ul_x = rt_raster_get_x_offset(rast);
627  ul_y = rt_raster_get_y_offset(rast);
628  srid = rt_raster_get_srid(rast);
629 
630  points = rtalloc(sizeof(POINTARRAY *)*1);
631  points[0] = ptarray_construct(0, 0, 5);
632 
633  p0.x = scale_x * x + skew_x * y + ul_x;
634  p0.y = scale_y * y + skew_y * x + ul_y;
635  ptarray_set_point4d(points[0], 0, &p0);
636 
637  p.x = p0.x + scale_x;
638  p.y = p0.y + skew_y;
639  ptarray_set_point4d(points[0], 1, &p);
640 
641  p.x = p0.x + scale_x + skew_x;
642  p.y = p0.y + scale_y + skew_y;
643  ptarray_set_point4d(points[0], 2, &p);
644 
645  p.x = p0.x + skew_x;
646  p.y = p0.y + scale_y;
647  ptarray_set_point4d(points[0], 3, &p);
648 
649  /* close it */
650  ptarray_set_point4d(points[0], 4, &p0);
651 
652  poly = lwpoly_construct(srid, NULL, 1, points);
653 
654  return poly;
655 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:437
double x
Definition: liblwgeom.h:352
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 rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:213
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
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
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:150
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:356
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:159
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
double y
Definition: liblwgeom.h:352
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
Here is the call graph for this function:
Here is the caller graph for this function: