PostGIS  2.1.10dev-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 13182 of file rt_api.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().

13183 {
13184  double scale_x, scale_y;
13185  double skew_x, skew_y;
13186  double ul_x, ul_y;
13187  int srid;
13188  POINTARRAY **points;
13189  POINT4D p, p0;
13190  LWPOLY *poly;
13191 
13192  assert(rast != NULL);
13193 
13194  scale_x = rt_raster_get_x_scale(rast);
13195  scale_y = rt_raster_get_y_scale(rast);
13196  skew_x = rt_raster_get_x_skew(rast);
13197  skew_y = rt_raster_get_y_skew(rast);
13198  ul_x = rt_raster_get_x_offset(rast);
13199  ul_y = rt_raster_get_y_offset(rast);
13200  srid = rt_raster_get_srid(rast);
13201 
13202  points = rtalloc(sizeof(POINTARRAY *)*1);
13203  points[0] = ptarray_construct(0, 0, 5);
13204 
13205  p0.x = scale_x * x + skew_x * y + ul_x;
13206  p0.y = scale_y * y + skew_y * x + ul_y;
13207  ptarray_set_point4d(points[0], 0, &p0);
13208 
13209  p.x = p0.x + scale_x;
13210  p.y = p0.y + skew_y;
13211  ptarray_set_point4d(points[0], 1, &p);
13212 
13213  p.x = p0.x + scale_x + skew_x;
13214  p.y = p0.y + scale_y + skew_y;
13215  ptarray_set_point4d(points[0], 2, &p);
13216 
13217  p.x = p0.x + skew_x;
13218  p.y = p0.y + scale_y;
13219  ptarray_set_point4d(points[0], 3, &p);
13220 
13221  /* close it */
13222  ptarray_set_point4d(points[0], 4, &p0);
13223 
13224  poly = lwpoly_construct(srid, NULL, 1, points);
13225 
13226  return poly;
13227 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:501
double x
Definition: liblwgeom.h:308
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:49
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_api.c:5527
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_api.c:5486
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_api.c:5495
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_api.c:5518
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
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_api.c:5455
tuple x
Definition: pixval.py:53
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_api.c:5464
double y
Definition: liblwgeom.h:308
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: