PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 608 of file rt_geometry.c.

609{
610 double scale_x, scale_y;
611 double skew_x, skew_y;
612 double ul_x, ul_y;
613 int32_t srid;
614 POINTARRAY **points;
615 POINT4D p, p0;
616 LWPOLY *poly;
617
618 assert(rast != NULL);
619
620 scale_x = rt_raster_get_x_scale(rast);
621 scale_y = rt_raster_get_y_scale(rast);
622 skew_x = rt_raster_get_x_skew(rast);
623 skew_y = rt_raster_get_y_skew(rast);
624 ul_x = rt_raster_get_x_offset(rast);
625 ul_y = rt_raster_get_y_offset(rast);
626 srid = rt_raster_get_srid(rast);
627
628 points = rtalloc(sizeof(POINTARRAY *)*1);
629 points[0] = ptarray_construct(0, 0, 5);
630
631 p0.x = scale_x * x + skew_x * y + ul_x;
632 p0.y = scale_y * y + skew_y * x + ul_y;
633 ptarray_set_point4d(points[0], 0, &p0);
634
635 p.x = p0.x + scale_x;
636 p.y = p0.y + skew_y;
637 ptarray_set_point4d(points[0], 1, &p);
638
639 p.x = p0.x + scale_x + skew_x;
640 p.y = p0.y + scale_y + skew_y;
641 ptarray_set_point4d(points[0], 2, &p);
642
643 p.x = p0.x + skew_x;
644 p.y = p0.y + scale_y;
645 ptarray_set_point4d(points[0], 3, &p);
646
647 /* close it */
648 ptarray_set_point4d(points[0], 4, &p0);
649
650 poly = lwpoly_construct(srid, NULL, 1, points);
651
652 return poly;
653}
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
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
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(), 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().

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