Skip to content

Commit 6450b84

Browse files
authored
Merge 7d298d7 into b58339c
2 parents b58339c + 7d298d7 commit 6450b84

7 files changed

+414
-8
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ PostGIS 3.2.0
7777
- #4986, GIST indexes on Postgres 14 are now created faster using Hilbert-sorting method.
7878
(Han Wang, Aliaksandr Kalenik, Darafei Praliaskouski, Giuseppe Broccolo)
7979
- #4949, Use proj_normalize_for_visualization to hand "axis swap" decisions (Paul Ramsey)
80+
- ST_PixelAsCentroids, ST_PixelAsCentroid reimplemented on top of a C function (Sergei Shoulbakov)
8081

8182
* New features*
8283
- #4923, topology.ValidateTopologyRelation (Sandro Santilli)

raster/rt_core/librtcore.h

+11
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,17 @@ rt_raster_compute_skewed_raster(
15491549
*/
15501550
LWPOLY* rt_raster_pixel_as_polygon(rt_raster raster, int x, int y);
15511551

1552+
/**
1553+
* Get a raster pixel centroid point.
1554+
*
1555+
* @param raster : the raster to get pixel from
1556+
* @param x : the column number
1557+
* @param y : the row number
1558+
*
1559+
* @return the pixel centroid point, or NULL on error.
1560+
*/
1561+
LWPOINT* rt_raster_pixel_as_centroid_point(rt_raster rast, int x, int y);
1562+
15521563
/**
15531564
* Get a raster as a surface (multipolygon). If a band is specified,
15541565
* those pixels with value (not NODATA) contribute to the area

raster/rt_core/rt_geometry.c

+38
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,44 @@ rt_raster_pixel_as_polygon(rt_raster rast, int x, int y)
654654
return poly;
655655
}
656656

657+
/******************************************************************************
658+
* rt_raster_pixel_as_centroid_point()
659+
******************************************************************************/
660+
661+
/**
662+
* Get a raster pixel centroid point.
663+
*
664+
* @param raster : the raster to get pixel from
665+
* @param x : the column number
666+
* @param y : the row number
667+
*
668+
* @return the pixel centroid point, or NULL on error.
669+
*/
670+
LWPOINT*
671+
rt_raster_pixel_as_centroid_point(rt_raster rast, int x, int y)
672+
{
673+
double scale_x, scale_y;
674+
double skew_x, skew_y;
675+
double ul_x, ul_y;
676+
int32_t srid;
677+
double center_x, center_y;
678+
LWPOINT* point;
679+
680+
scale_x = rt_raster_get_x_scale(rast);
681+
scale_y = rt_raster_get_y_scale(rast);
682+
skew_x = rt_raster_get_x_skew(rast);
683+
skew_y = rt_raster_get_y_skew(rast);
684+
ul_x = rt_raster_get_x_offset(rast);
685+
ul_y = rt_raster_get_y_offset(rast);
686+
srid = rt_raster_get_srid(rast);
687+
688+
center_x = scale_x * x + skew_x * y + ul_x + (scale_x + skew_x) * 0.5;
689+
center_y = scale_y * y + skew_y * x + ul_y + (scale_y + skew_y) * 0.5;
690+
point = lwpoint_make2d(srid, center_x, center_y);
691+
692+
return point;
693+
}
694+
657695
/******************************************************************************
658696
* rt_raster_get_envelope_geom()
659697
******************************************************************************/

0 commit comments

Comments
 (0)