1395 double nodataval = 0;
1409 HeapTupleHeader tup;
1422 if (PG_ARGISNULL(0))
1424 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
1429 PG_FREE_IF_COPY(pgraster, 0);
1430 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not deserialize raster");
1442 if (PG_ARGISNULL(1)) {
1443 elog(NOTICE,
"Band index cannot be NULL. Value must be 1-based. Returning original raster");
1445 PG_RETURN_POINTER(pgraster);
1448 nband = PG_GETARG_INT32(1);
1449 if (nband < 1 || nband > numbands) {
1450 elog(NOTICE,
"Band index is invalid. Value must be 1-based. Returning original raster");
1452 PG_RETURN_POINTER(pgraster);
1463 if (PG_ARGISNULL(2)) {
1464 elog(NOTICE,
"No values to set. Returning original raster");
1466 PG_RETURN_POINTER(pgraster);
1469 array = PG_GETARG_ARRAYTYPE_P(2);
1470 etype = ARR_ELEMTYPE(array);
1471 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1476 typlen, typbyval, typalign,
1481 elog(NOTICE,
"No values to set. Returning original raster");
1483 PG_RETURN_POINTER(pgraster);
1490 PG_FREE_IF_COPY(pgraster, 0);
1491 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not intialize argument structure");
1496 if (arg->
gv == NULL) {
1499 PG_FREE_IF_COPY(pgraster, 0);
1500 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not allocate memory for geomval array");
1506 for (i = 0; i < n; i++) {
1516 tup = (HeapTupleHeader) DatumGetPointer(e[i]);
1520 PG_FREE_IF_COPY(pgraster, 0);
1521 elog(ERROR,
"RASTER_setPixelValuesGeomval: Invalid argument for geomval at index %d", i);
1527 tupv = GetAttributeByName(tup,
"geom", &isnull);
1529 elog(NOTICE,
"First argument (geom) of geomval at index %d is NULL. Skipping", i);
1538 PG_FREE_IF_COPY(pgraster, 0);
1539 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not deserialize geometry of geomval at index %d", i);
1545 elog(NOTICE,
"First argument (geom) of geomval at index %d is an empty geometry. Skipping", i);
1551 elog(NOTICE,
"Geometry provided for geomval at index %d does not have the same SRID as the raster: %d. Returning original raster", i, srid);
1554 PG_RETURN_POINTER(pgraster);
1606 PG_FREE_IF_COPY(pgraster, 0);
1607 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not rasterize geometry of geomval at index %d", i);
1616 tupv = GetAttributeByName(tup,
"val", &isnull);
1618 elog(NOTICE,
"Second argument (val) of geomval at index %d is NULL. Treating as NODATA", i);
1630 if (arg->
gv == NULL) {
1633 PG_FREE_IF_COPY(pgraster, 0);
1634 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not reallocate memory for geomval array");
1640 if (!PG_ARGISNULL(3))
1646 POSTGIS_RT_DEBUG(3,
"keepnodata = TRUE and band is NODATA. Not doing anything");
1649 else if (allpoint == arg->
ngv) {
1650 double igt[6] = {0};
1659 POSTGIS_RT_DEBUG(3,
"all geometries are points, using direct to pixel method");
1665 for (i = 0; i < arg->
ngv; i++) {
1670 for (j = 0; j < coll->
ngeoms; j++) {
1677 PG_FREE_IF_COPY(pgraster, 0);
1678 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not process coordinates of point");
1684 (xy[0] < 0 || xy[0] >= width) ||
1685 (xy[1] < 0 || xy[1] >= height)
1687 elog(NOTICE,
"Point is outside raster extent. Skipping");
1695 PG_FREE_IF_COPY(pgraster, 0);
1696 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not get pixel value");
1713 PG_FREE_IF_COPY(pgraster, 0);
1714 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not set pixel value");
1728 if (itrset == NULL) {
1731 PG_FREE_IF_COPY(pgraster, 0);
1732 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not allocate memory for iterator arguments");
1742 for (i = 0, j = 1; i < arg->
ngv; i++, j++) {
1744 itrset[j].
nband = 0;
1750 itrset, arg->
ngv + 1,
1753 hasnodata, nodataval,
1765 PG_FREE_IF_COPY(pgraster, 0);
1766 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not run raster iterator function");
1772 if (_band == NULL) {
1776 PG_FREE_IF_COPY(pgraster, 0);
1777 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not get band from working raster");
1782 if (_band == NULL) {
1786 PG_FREE_IF_COPY(pgraster, 0);
1787 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not replace band in output raster");
1799 PG_FREE_IF_COPY(pgraster, 0);
1806 SET_VARSIZE(pgrtn, pgrtn->
size);
1807 PG_RETURN_POINTER(pgrtn);
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
#define LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
lwvarlena_t * lwgeom_to_wkb_varlena(const LWGEOM *geom, uint8_t variant)
int32_t clamp_srid(int32_t srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
rt_errorstate rt_raster_get_inverse_geotransform_matrix(rt_raster raster, double *gt, double *igt)
Get 6-element array of raster inverse geotransform matrix.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw, yw map point to a xr, yr raster point.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index)
Replace band at provided index with new band.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb, uint32_t wkb_len, const char *srs, uint32_t num_bands, rt_pixtype *pixtype, double *init, double *value, double *nodata, uint8_t *hasnodata, int *width, int *height, double *scale_x, double *scale_y, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, char **options)
Return a raster of the provided geometry.
void rt_band_destroy(rt_band band)
Destroy a raster band.
uint16_t rt_raster_get_num_bands(rt_raster raster)
uint16_t rt_raster_get_height(rt_raster raster)
rt_errorstate rt_raster_iterator(rt_iterator itrset, uint16_t itrcount, rt_extenttype extenttype, rt_raster customextent, rt_pixtype pixtype, uint8_t hasnodata, double nodataval, uint16_t distancex, uint16_t distancey, rt_mask mask, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
uint16_t rt_raster_get_width(rt_raster raster)
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
static void rtpg_setvaluesgv_arg_destroy(rtpg_setvaluesgv_arg arg)
static int rtpg_setvalues_geomval_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static rtpg_setvaluesgv_arg rtpg_setvaluesgv_arg_init()
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)
rtpg_setvaluesgv_geomval gv
struct rtpg_setvaluesgv_geomval_t::@27 pixval