2068         bool exclude_nodata_value = 
TRUE;
 
 2074         double **value2D = NULL;
 
 2075         int **nodata2D = NULL;
 
 2080         Datum *value1D = NULL;
 
 2081         bool *nodata1D = NULL;
 
 2083         int lbound[2] = {1, 1};
 
 2084         ArrayType *mdArray = NULL;
 
 2091         if (PG_ARGISNULL(0))
 
 2093         pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 
 2097                 PG_FREE_IF_COPY(pgraster, 0);
 
 2098                 elog(ERROR, 
"RASTER_neighborhood: Could not deserialize raster");
 
 2103         if (!PG_ARGISNULL(1))
 
 2104                 bandindex = PG_GETARG_INT32(1);
 
 2106         if (bandindex < 1 || bandindex > num_bands) {
 
 2107                 elog(NOTICE, 
"Invalid band index (must use 1-based). Returning NULL");
 
 2109                 PG_FREE_IF_COPY(pgraster, 0);
 
 2114         x = PG_GETARG_INT32(2);
 
 2118         y = PG_GETARG_INT32(3);
 
 2124                 elog(NOTICE, 
"Invalid value for distancex (must be >= zero). Returning NULL");
 
 2126                 PG_FREE_IF_COPY(pgraster, 0);
 
 2134                 elog(NOTICE, 
"Invalid value for distancey (must be >= zero). Returning NULL");
 
 2136                 PG_FREE_IF_COPY(pgraster, 0);
 
 2142         if (!PG_ARGISNULL(6))
 
 2143                 exclude_nodata_value = PG_GETARG_BOOL(6);
 
 2148                 elog(NOTICE, 
"Could not find band at index %d. Returning NULL", bandindex);
 
 2150                 PG_FREE_IF_COPY(pgraster, 0);
 
 2162                         exclude_nodata_value,
 
 2167                         elog(NOTICE, 
"Could not get the pixel's neighborhood for band at index %d", bandindex);
 
 2171                         PG_FREE_IF_COPY(pgraster, 0);
 
 2188                         elog(NOTICE, 
"Could not get the pixel of band at index %d. Returning NULL", bandindex);
 
 2191                         PG_FREE_IF_COPY(pgraster, 0);
 
 2214         if (npixels == NULL) {
 
 2218                 PG_FREE_IF_COPY(pgraster, 0);
 
 2220                 elog(ERROR, 
"RASTER_neighborhood: Could not reallocate memory for neighborhood");
 
 2223         npixels[
count - 1].
x = _x;
 
 2224         npixels[
count - 1].
y = _y;
 
 2229         if (!exclude_nodata_value || !isnodata) {
 
 2236         PG_FREE_IF_COPY(pgraster, 0);
 
 2241                 npixels, 
count, NULL,
 
 2246                 &(dim[1]), &(dim[0])
 
 2250                 elog(NOTICE, 
"Could not create 2D array of neighborhood");
 
 2255         value1D = palloc(
sizeof(Datum) * dim[0] * dim[1]);
 
 2256         nodata1D = palloc(
sizeof(
bool) * dim[0] * dim[1]);
 
 2258         if (value1D == NULL || nodata1D == NULL) {
 
 2260                 for (i = 0; i < dim[0]; i++) {
 
 2267                 elog(ERROR, 
"RASTER_neighborhood: Could not allocate memory for return 2D array");
 
 2274         for (i = 0; i < dim[0]; i++) {
 
 2276                 for (j = 0; j < dim[1]; j++) {
 
 2277                         nodata1D[k] = (bool) nodata2D[i][j];
 
 2279                                 value1D[k] = Float8GetDatum(value2D[i][j]);
 
 2281                                 value1D[k] = PointerGetDatum(NULL);
 
 2288         for (i = 0; i < dim[0]; i++) {
 
 2296         get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
 
 2298         mdArray = construct_md_array(
 
 2302                 typlen, typbyval, typalign
 
 2308         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,...)