1196 double nodataval = 0;
1210 HeapTupleHeader tup;
1216 unsigned char *wkb = NULL;
1224 if (PG_ARGISNULL(0))
1226 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
1231 PG_FREE_IF_COPY(pgraster, 0);
1232 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not deserialize raster");
1244 if (PG_ARGISNULL(1)) {
1245 elog(NOTICE,
"Band index cannot be NULL. Value must be 1-based. Returning original raster");
1247 PG_RETURN_POINTER(pgraster);
1250 nband = PG_GETARG_INT32(1);
1251 if (nband < 1 || nband > numbands) {
1252 elog(NOTICE,
"Band index is invalid. Value must be 1-based. Returning original raster");
1254 PG_RETURN_POINTER(pgraster);
1265 if (PG_ARGISNULL(2)) {
1266 elog(NOTICE,
"No values to set. Returning original raster");
1268 PG_RETURN_POINTER(pgraster);
1271 array = PG_GETARG_ARRAYTYPE_P(2);
1272 etype = ARR_ELEMTYPE(array);
1273 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1278 typlen, typbyval, typalign,
1283 elog(NOTICE,
"No values to set. Returning original raster");
1285 PG_RETURN_POINTER(pgraster);
1292 PG_FREE_IF_COPY(pgraster, 0);
1293 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not intialize argument structure");
1298 if (arg->
gv == NULL) {
1301 PG_FREE_IF_COPY(pgraster, 0);
1302 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not allocate memory for geomval array");
1308 for (i = 0; i < n; i++) {
1318 tup = (HeapTupleHeader) DatumGetPointer(e[i]);
1322 PG_FREE_IF_COPY(pgraster, 0);
1323 elog(ERROR,
"RASTER_setPixelValuesGeomval: Invalid argument for geomval at index %d", i);
1329 tupv = GetAttributeByName(tup,
"geom", &isnull);
1331 elog(NOTICE,
"First argument (geom) of geomval at index %d is NULL. Skipping", i);
1340 PG_FREE_IF_COPY(pgraster, 0);
1341 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not deserialize geometry of geomval at index %d", i);
1347 elog(NOTICE,
"First argument (geom) of geomval at index %d is an empty geometry. Skipping", i);
1353 elog(NOTICE,
"Geometry provided for geomval at index %d does not have the same SRID as the raster: %d. Returning original raster", i, srid);
1356 PG_RETURN_POINTER(pgraster);
1401 PG_FREE_IF_COPY(pgraster, 0);
1402 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not rasterize geometry of geomval at index %d", i);
1411 tupv = GetAttributeByName(tup,
"val", &isnull);
1413 elog(NOTICE,
"Second argument (val) of geomval at index %d is NULL. Treating as NODATA", i);
1425 if (arg->
gv == NULL) {
1428 PG_FREE_IF_COPY(pgraster, 0);
1429 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not reallocate memory for geomval array");
1435 if (!PG_ARGISNULL(3))
1441 POSTGIS_RT_DEBUG(3,
"keepnodata = TRUE and band is NODATA. Not doing anything");
1444 else if (allpoint == arg->
ngv) {
1445 double igt[6] = {0};
1454 POSTGIS_RT_DEBUG(3,
"all geometries are points, using direct to pixel method");
1460 for (i = 0; i < arg->
ngv; i++) {
1465 for (j = 0; j < coll->
ngeoms; j++) {
1472 PG_FREE_IF_COPY(pgraster, 0);
1473 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not process coordinates of point");
1479 (xy[0] < 0 || xy[0] >= width) ||
1480 (xy[1] < 0 || xy[1] >= height)
1482 elog(NOTICE,
"Point is outside raster extent. Skipping");
1490 PG_FREE_IF_COPY(pgraster, 0);
1491 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not get pixel value");
1508 PG_FREE_IF_COPY(pgraster, 0);
1509 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not set pixel value");
1523 if (itrset == NULL) {
1526 PG_FREE_IF_COPY(pgraster, 0);
1527 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not allocate memory for iterator arguments");
1537 for (i = 0, j = 1; i < arg->
ngv; i++, j++) {
1539 itrset[j].
nband = 0;
1545 itrset, arg->
ngv + 1,
1548 hasnodata, nodataval,
1560 PG_FREE_IF_COPY(pgraster, 0);
1561 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not run raster iterator function");
1567 if (_band == NULL) {
1571 PG_FREE_IF_COPY(pgraster, 0);
1572 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not get band from working raster");
1577 if (_band == NULL) {
1581 PG_FREE_IF_COPY(pgraster, 0);
1582 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not replace band in output raster");
1594 PG_FREE_IF_COPY(pgraster, 0);
1601 SET_VARSIZE(pgrtn, pgrtn->
size);
1602 PG_RETURN_POINTER(pgrtn);
int32_t gserialized_get_srid(const GSERIALIZED *s)
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 *s)
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.
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
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.
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::@21 pixval