2267 bool exclude_nodata_value =
TRUE;
2273 double **value2D = NULL;
2274 int **nodata2D = NULL;
2279 Datum *value1D = NULL;
2280 bool *nodata1D = NULL;
2282 int lbound[2] = {1, 1};
2283 ArrayType *mdArray = NULL;
2290 if (PG_ARGISNULL(0))
2292 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2296 PG_FREE_IF_COPY(pgraster, 0);
2297 elog(ERROR,
"RASTER_neighborhood: Could not deserialize raster");
2302 if (!PG_ARGISNULL(1))
2303 bandindex = PG_GETARG_INT32(1);
2305 if (bandindex < 1 || bandindex > num_bands) {
2306 elog(NOTICE,
"Invalid band index (must use 1-based). Returning NULL");
2308 PG_FREE_IF_COPY(pgraster, 0);
2313 x = PG_GETARG_INT32(2);
2317 y = PG_GETARG_INT32(3);
2323 elog(NOTICE,
"Invalid value for distancex (must be >= zero). Returning NULL");
2325 PG_FREE_IF_COPY(pgraster, 0);
2333 elog(NOTICE,
"Invalid value for distancey (must be >= zero). Returning NULL");
2335 PG_FREE_IF_COPY(pgraster, 0);
2341 if (!PG_ARGISNULL(6))
2342 exclude_nodata_value = PG_GETARG_BOOL(6);
2347 elog(NOTICE,
"Could not find band at index %d. Returning NULL", bandindex);
2349 PG_FREE_IF_COPY(pgraster, 0);
2361 exclude_nodata_value,
2366 elog(NOTICE,
"Could not get the pixel's neighborhood for band at index %d", bandindex);
2370 PG_FREE_IF_COPY(pgraster, 0);
2387 elog(NOTICE,
"Could not get the pixel of band at index %d. Returning NULL", bandindex);
2390 PG_FREE_IF_COPY(pgraster, 0);
2413 if (npixels == NULL) {
2417 PG_FREE_IF_COPY(pgraster, 0);
2419 elog(ERROR,
"RASTER_neighborhood: Could not reallocate memory for neighborhood");
2422 npixels[
count - 1].
x = _x;
2423 npixels[
count - 1].
y = _y;
2428 if (!exclude_nodata_value || !isnodata) {
2435 PG_FREE_IF_COPY(pgraster, 0);
2440 npixels,
count, NULL,
2445 &(dim[1]), &(dim[0])
2449 elog(NOTICE,
"Could not create 2D array of neighborhood");
2454 value1D = palloc(
sizeof(Datum) * dim[0] * dim[1]);
2455 nodata1D = palloc(
sizeof(
bool) * dim[0] * dim[1]);
2457 if (value1D == NULL || nodata1D == NULL) {
2459 for (i = 0; i < dim[0]; i++) {
2466 elog(ERROR,
"RASTER_neighborhood: Could not allocate memory for return 2D array");
2473 for (i = 0; i < dim[0]; i++) {
2475 for (j = 0; j < dim[1]; j++) {
2476 nodata1D[k] = (bool) nodata2D[i][j];
2478 value1D[k] = Float8GetDatum(value2D[i][j]);
2480 value1D[k] = PointerGetDatum(NULL);
2487 for (i = 0; i < dim[0]; i++) {
2495 get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
2497 mdArray = construct_md_array(
2501 typlen, typbyval, typalign
2507 PG_RETURN_ARRAYTYPE_P(mdArray);
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
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.
struct rt_pixel_t * rt_pixel
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
void rt_band_destroy(rt_band band)
Destroy a raster band.
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, uint32_t count, rt_mask mask, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
uint32_t rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
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 double distance(double x1, double y1, double x2, double y2)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
#define POSTGIS_RT_DEBUGF(level, msg,...)