PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 629 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().

630 {
631  double scale_x, scale_y;
632  double skew_x, skew_y;
633  double ul_x, ul_y;
634  int srid;
635  POINTARRAY **points;
636  POINT4D p, p0;
637  LWPOLY *poly;
638 
639  assert(rast != NULL);
640 
641  scale_x = rt_raster_get_x_scale(rast);
642  scale_y = rt_raster_get_y_scale(rast);
643  skew_x = rt_raster_get_x_skew(rast);
644  skew_y = rt_raster_get_y_skew(rast);
645  ul_x = rt_raster_get_x_offset(rast);
646  ul_y = rt_raster_get_y_offset(rast);
647  srid = rt_raster_get_srid(rast);
648 
649  points = rtalloc(sizeof(POINTARRAY *)*1);
650  points[0] = ptarray_construct(0, 0, 5);
651 
652  p0.x = scale_x * x + skew_x * y + ul_x;
653  p0.y = scale_y * y + skew_y * x + ul_y;
654  ptarray_set_point4d(points[0], 0, &p0);
655 
656  p.x = p0.x + scale_x;
657  p.y = p0.y + skew_y;
658  ptarray_set_point4d(points[0], 1, &p);
659 
660  p.x = p0.x + scale_x + skew_x;
661  p.y = p0.y + scale_y + skew_y;
662  ptarray_set_point4d(points[0], 2, &p);
663 
664  p.x = p0.x + skew_x;
665  p.y = p0.y + scale_y;
666  ptarray_set_point4d(points[0], 3, &p);
667 
668  /* close it */
669  ptarray_set_point4d(points[0], 4, &p0);
670 
671  poly = lwpoly_construct(srid, NULL, 1, points);
672 
673  return poly;
674 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:536
double x
Definition: liblwgeom.h:336
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:29
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
tuple x
Definition: pixval.py:53
double y
Definition: liblwgeom.h:336
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: