1196 double nodataval = 0;
1210 HeapTupleHeader tup;
1223 if (PG_ARGISNULL(0))
1225 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
1230 PG_FREE_IF_COPY(pgraster, 0);
1231 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not deserialize raster");
1243 if (PG_ARGISNULL(1)) {
1244 elog(NOTICE,
"Band index cannot be NULL. Value must be 1-based. Returning original raster");
1246 PG_RETURN_POINTER(pgraster);
1249 nband = PG_GETARG_INT32(1);
1250 if (nband < 1 || nband > numbands) {
1251 elog(NOTICE,
"Band index is invalid. Value must be 1-based. Returning original raster");
1253 PG_RETURN_POINTER(pgraster);
1264 if (PG_ARGISNULL(2)) {
1265 elog(NOTICE,
"No values to set. Returning original raster");
1267 PG_RETURN_POINTER(pgraster);
1270 array = PG_GETARG_ARRAYTYPE_P(2);
1271 etype = ARR_ELEMTYPE(array);
1272 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1277 typlen, typbyval, typalign,
1282 elog(NOTICE,
"No values to set. Returning original raster");
1284 PG_RETURN_POINTER(pgraster);
1291 PG_FREE_IF_COPY(pgraster, 0);
1292 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not intialize argument structure");
1297 if (arg->
gv == NULL) {
1300 PG_FREE_IF_COPY(pgraster, 0);
1301 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not allocate memory for geomval array");
1307 for (i = 0; i < n; i++) {
1317 tup = (HeapTupleHeader) DatumGetPointer(e[i]);
1321 PG_FREE_IF_COPY(pgraster, 0);
1322 elog(ERROR,
"RASTER_setPixelValuesGeomval: Invalid argument for geomval at index %d", i);
1328 tupv = GetAttributeByName(tup,
"geom", &isnull);
1330 elog(NOTICE,
"First argument (geom) of geomval at index %d is NULL. Skipping", i);
1339 PG_FREE_IF_COPY(pgraster, 0);
1340 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not deserialize geometry of geomval at index %d", i);
1346 elog(NOTICE,
"First argument (geom) of geomval at index %d is an empty geometry. Skipping", i);
1352 elog(NOTICE,
"Geometry provided for geomval at index %d does not have the same SRID as the raster: %d. Returning original raster", i, srid);
1355 PG_RETURN_POINTER(pgraster);
1407 PG_FREE_IF_COPY(pgraster, 0);
1408 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not rasterize geometry of geomval at index %d", i);
1417 tupv = GetAttributeByName(tup,
"val", &isnull);
1419 elog(NOTICE,
"Second argument (val) of geomval at index %d is NULL. Treating as NODATA", i);
1431 if (arg->
gv == NULL) {
1434 PG_FREE_IF_COPY(pgraster, 0);
1435 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not reallocate memory for geomval array");
1441 if (!PG_ARGISNULL(3))
1447 POSTGIS_RT_DEBUG(3,
"keepnodata = TRUE and band is NODATA. Not doing anything");
1450 else if (allpoint == arg->
ngv) {
1451 double igt[6] = {0};
1460 POSTGIS_RT_DEBUG(3,
"all geometries are points, using direct to pixel method");
1466 for (i = 0; i < arg->
ngv; i++) {
1471 for (j = 0; j < coll->
ngeoms; j++) {
1478 PG_FREE_IF_COPY(pgraster, 0);
1479 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not process coordinates of point");
1485 (xy[0] < 0 || xy[0] >= width) ||
1486 (xy[1] < 0 || xy[1] >= height)
1488 elog(NOTICE,
"Point is outside raster extent. Skipping");
1496 PG_FREE_IF_COPY(pgraster, 0);
1497 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not get pixel value");
1514 PG_FREE_IF_COPY(pgraster, 0);
1515 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not set pixel value");
1529 if (itrset == NULL) {
1532 PG_FREE_IF_COPY(pgraster, 0);
1533 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not allocate memory for iterator arguments");
1543 for (i = 0, j = 1; i < arg->
ngv; i++, j++) {
1545 itrset[j].
nband = 0;
1551 itrset, arg->
ngv + 1,
1554 hasnodata, nodataval,
1566 PG_FREE_IF_COPY(pgraster, 0);
1567 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not run raster iterator function");
1573 if (_band == NULL) {
1577 PG_FREE_IF_COPY(pgraster, 0);
1578 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not get band from working raster");
1583 if (_band == NULL) {
1587 PG_FREE_IF_COPY(pgraster, 0);
1588 elog(ERROR,
"RASTER_setPixelValuesGeomval: Could not replace band in output raster");
1600 PG_FREE_IF_COPY(pgraster, 0);
1607 SET_VARSIZE(pgrtn, pgrtn->
size);
1608 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::@22 pixval