PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_union_transfn()

Datum RASTER_union_transfn ( PG_FUNCTION_ARGS  )

Definition at line 2119 of file rtpg_mapalgebra.c.

2120 {
2121  MemoryContext aggcontext;
2122  MemoryContext oldcontext;
2123  rtpg_union_arg iwr = NULL;
2124  int skiparg = 0;
2125 
2126  rt_pgraster *pgraster = NULL;
2127  rt_raster raster = NULL;
2128  rt_raster _raster = NULL;
2129  rt_band _band = NULL;
2130  int nband = 1;
2131  int noerr = 1;
2132  int isempty[2] = {0};
2133  int hasband[2] = {0};
2134  int nargs = 0;
2135  double _offset[4] = {0.};
2136  int nbnodata = 0; /* 1 if adding bands */
2137 
2138  int i = 0;
2139  int j = 0;
2140  int k = 0;
2141 
2142  rt_iterator itrset;
2143  char *utypename = NULL;
2144  rtpg_union_type utype = UT_LAST;
2145  rt_pixtype pixtype = PT_END;
2146  int hasnodata = 1;
2147  double nodataval = 0;
2148 
2149  rt_raster iraster = NULL;
2150  rt_band iband = NULL;
2151  int reuserast = 0;
2152  int y = 0;
2153  uint16_t _dim[2] = {0};
2154  void *vals = NULL;
2155  uint16_t nvals = 0;
2156 
2157  POSTGIS_RT_DEBUG(3, "Starting...");
2158 
2159  /* cannot be called directly as this is exclusive aggregate function */
2160  if (!AggCheckCallContext(fcinfo, &aggcontext)) {
2161  elog(ERROR, "RASTER_union_transfn: Cannot be called in a non-aggregate context");
2162  PG_RETURN_NULL();
2163  }
2164 
2165  /* switch to aggcontext */
2166  oldcontext = MemoryContextSwitchTo(aggcontext);
2167 
2168  if (PG_ARGISNULL(0)) {
2169  POSTGIS_RT_DEBUG(3, "Creating state variable");
2170  /* allocate container in aggcontext */
2171  iwr = palloc(sizeof(struct rtpg_union_arg_t));
2172  if (iwr == NULL) {
2173  MemoryContextSwitchTo(oldcontext);
2174  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for state variable");
2175  PG_RETURN_NULL();
2176  }
2177 
2178  iwr->numband = 0;
2179  iwr->bandarg = NULL;
2180 
2181  skiparg = 0;
2182  }
2183  else {
2184  POSTGIS_RT_DEBUG(3, "State variable already exists");
2185  iwr = (rtpg_union_arg) PG_GETARG_POINTER(0);
2186  skiparg = 1;
2187  }
2188 
2189  /* raster arg is NOT NULL */
2190  if (!PG_ARGISNULL(1)) {
2191  /* deserialize raster */
2192  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2193 
2194  /* Get raster object */
2195  raster = rt_raster_deserialize(pgraster, FALSE);
2196  if (raster == NULL) {
2197 
2199  PG_FREE_IF_COPY(pgraster, 1);
2200 
2201  MemoryContextSwitchTo(oldcontext);
2202  elog(ERROR, "RASTER_union_transfn: Could not deserialize raster");
2203  PG_RETURN_NULL();
2204  }
2205  }
2206 
2207  /* process additional args if needed */
2208  nargs = PG_NARGS();
2209  POSTGIS_RT_DEBUGF(4, "nargs = %d", nargs);
2210  if (nargs > 2) {
2211  POSTGIS_RT_DEBUG(4, "processing additional arguments");
2212 
2213  /* if more than 2 arguments, determine the type of argument 3 */
2214  /* band number, UNION type or unionarg */
2215  if (!PG_ARGISNULL(2)) {
2216  Oid calltype = get_fn_expr_argtype(fcinfo->flinfo, 2);
2217 
2218  switch (calltype) {
2219  /* UNION type */
2220  case TEXTOID: {
2221  int idx = 0;
2222  int numband = 0;
2223 
2224  POSTGIS_RT_DEBUG(4, "Processing arg 3 as UNION type");
2225  nbnodata = 1;
2226 
2227  utypename = text_to_cstring(PG_GETARG_TEXT_P(2));
2228  utype = rtpg_uniontype_index_from_name(rtpg_strtoupper(utypename));
2229  POSTGIS_RT_DEBUGF(4, "Union type: %s", utypename);
2230 
2231  POSTGIS_RT_DEBUGF(4, "iwr->numband: %d", iwr->numband);
2232  /* see if we need to append new bands */
2233  if (raster) {
2234  idx = iwr->numband;
2235  numband = rt_raster_get_num_bands(raster);
2236  POSTGIS_RT_DEBUGF(4, "numband: %d", numband);
2237 
2238  /* only worry about appended bands */
2239  if (numband > iwr->numband)
2240  iwr->numband = numband;
2241  }
2242 
2243  if (!iwr->numband)
2244  iwr->numband = 1;
2245  POSTGIS_RT_DEBUGF(4, "iwr->numband: %d", iwr->numband);
2246  POSTGIS_RT_DEBUGF(4, "numband, idx: %d, %d", numband, idx);
2247 
2248  /* bandarg set. only possible after the first call to function */
2249  if (iwr->bandarg) {
2250  /* only reallocate if new bands need to be added */
2251  if (numband > idx) {
2252  POSTGIS_RT_DEBUG(4, "Reallocating iwr->bandarg");
2253  iwr->bandarg = repalloc(iwr->bandarg, sizeof(struct rtpg_union_band_arg_t) * iwr->numband);
2254  }
2255  /* prevent initial values step happening below */
2256  else
2257  idx = iwr->numband;
2258  }
2259  /* bandarg not set, first call to function */
2260  else {
2261  POSTGIS_RT_DEBUG(4, "Allocating iwr->bandarg");
2262  iwr->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * iwr->numband);
2263  }
2264  if (iwr->bandarg == NULL) {
2265 
2267  if (raster != NULL) {
2269  PG_FREE_IF_COPY(pgraster, 1);
2270  }
2271 
2272  MemoryContextSwitchTo(oldcontext);
2273  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for band information");
2274  PG_RETURN_NULL();
2275  }
2276 
2277  /* set initial values for bands that are "new" */
2278  for (i = idx; i < iwr->numband; i++) {
2279  iwr->bandarg[i].uniontype = utype;
2280  iwr->bandarg[i].nband = i;
2281 
2282  if (
2283  utype == UT_MEAN ||
2284  utype == UT_RANGE
2285  ) {
2286  iwr->bandarg[i].numraster = 2;
2287  }
2288  else
2289  iwr->bandarg[i].numraster = 1;
2290  iwr->bandarg[i].raster = NULL;
2291  }
2292 
2293  break;
2294  }
2295  /* band number */
2296  case INT2OID:
2297  case INT4OID:
2298  if (skiparg)
2299  break;
2300 
2301  POSTGIS_RT_DEBUG(4, "Processing arg 3 as band number");
2302  nband = PG_GETARG_INT32(2);
2303  if (nband < 1) {
2304 
2306  if (raster != NULL) {
2308  PG_FREE_IF_COPY(pgraster, 1);
2309  }
2310 
2311  MemoryContextSwitchTo(oldcontext);
2312  elog(ERROR, "RASTER_union_transfn: Band number must be greater than zero (1-based)");
2313  PG_RETURN_NULL();
2314  }
2315 
2316  iwr->numband = 1;
2317  iwr->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * iwr->numband);
2318  if (iwr->bandarg == NULL) {
2319 
2321  if (raster != NULL) {
2323  PG_FREE_IF_COPY(pgraster, 1);
2324  }
2325 
2326  MemoryContextSwitchTo(oldcontext);
2327  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for band information");
2328  PG_RETURN_NULL();
2329  }
2330 
2331  iwr->bandarg[0].uniontype = UT_LAST;
2332  iwr->bandarg[0].nband = nband - 1;
2333 
2334  iwr->bandarg[0].numraster = 1;
2335  iwr->bandarg[0].raster = NULL;
2336  break;
2337  /* only other type allowed is unionarg */
2338  default:
2339  if (skiparg)
2340  break;
2341 
2342  POSTGIS_RT_DEBUG(4, "Processing arg 3 as unionarg");
2343  if (!rtpg_union_unionarg_process(iwr, PG_GETARG_ARRAYTYPE_P(2))) {
2344 
2346  if (raster != NULL) {
2348  PG_FREE_IF_COPY(pgraster, 1);
2349  }
2350 
2351  MemoryContextSwitchTo(oldcontext);
2352  elog(ERROR, "RASTER_union_transfn: Could not process unionarg");
2353  PG_RETURN_NULL();
2354  }
2355 
2356  break;
2357  }
2358  }
2359 
2360  /* UNION type */
2361  if (nargs > 3 && !PG_ARGISNULL(3)) {
2362  utypename = text_to_cstring(PG_GETARG_TEXT_P(3));
2363  utype = rtpg_uniontype_index_from_name(rtpg_strtoupper(utypename));
2364  iwr->bandarg[0].uniontype = utype;
2365  POSTGIS_RT_DEBUGF(4, "Union type: %s", utypename);
2366 
2367  if (
2368  utype == UT_MEAN ||
2369  utype == UT_RANGE
2370  ) {
2371  iwr->bandarg[0].numraster = 2;
2372  }
2373  }
2374 
2375  /* allocate space for pointers to rt_raster */
2376  for (i = 0; i < iwr->numband; i++) {
2377  POSTGIS_RT_DEBUGF(4, "iwr->bandarg[%d].raster @ %p", i, iwr->bandarg[i].raster);
2378 
2379  /* no need to allocate */
2380  if (iwr->bandarg[i].raster != NULL)
2381  continue;
2382 
2383  POSTGIS_RT_DEBUGF(4, "Allocating space for working rasters of band %d", i);
2384 
2385  iwr->bandarg[i].raster = (rt_raster *) palloc(sizeof(rt_raster) * iwr->bandarg[i].numraster);
2386  if (iwr->bandarg[i].raster == NULL) {
2387 
2389  if (raster != NULL) {
2391  PG_FREE_IF_COPY(pgraster, 1);
2392  }
2393 
2394  MemoryContextSwitchTo(oldcontext);
2395  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for working raster(s)");
2396  PG_RETURN_NULL();
2397  }
2398 
2399  memset(iwr->bandarg[i].raster, 0, sizeof(rt_raster) * iwr->bandarg[i].numraster);
2400 
2401  /* add new working rt_raster but only if working raster already exists */
2402  if (i > 0 && !rt_raster_is_empty(iwr->bandarg[0].raster[0])) {
2403  for (j = 0; j < iwr->bandarg[i].numraster; j++) {
2404  iwr->bandarg[i].raster[j] = rt_raster_clone(iwr->bandarg[0].raster[0], 0); /* shallow clone */
2405  if (iwr->bandarg[i].raster[j] == NULL) {
2406 
2408  if (raster != NULL) {
2410  PG_FREE_IF_COPY(pgraster, 1);
2411  }
2412 
2413  MemoryContextSwitchTo(oldcontext);
2414  elog(ERROR, "RASTER_union_transfn: Could not create working raster");
2415  PG_RETURN_NULL();
2416  }
2417  }
2418  }
2419  }
2420  }
2421  /* only raster, no additional args */
2422  /* only do this if raster isn't empty */
2423  else {
2424  POSTGIS_RT_DEBUG(4, "no additional args, checking input raster");
2425  nbnodata = 1;
2426  if (!rtpg_union_noarg(iwr, raster)) {
2427 
2429  if (raster != NULL) {
2431  PG_FREE_IF_COPY(pgraster, 1);
2432  }
2433 
2434  MemoryContextSwitchTo(oldcontext);
2435  elog(ERROR, "RASTER_union_transfn: Could not check and balance number of bands");
2436  PG_RETURN_NULL();
2437  }
2438  }
2439 
2440  /* init itrset */
2441  itrset = palloc(sizeof(struct rt_iterator_t) * 2);
2442  if (itrset == NULL) {
2443 
2445  if (raster != NULL) {
2447  PG_FREE_IF_COPY(pgraster, 1);
2448  }
2449 
2450  MemoryContextSwitchTo(oldcontext);
2451  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for iterator arguments");
2452  PG_RETURN_NULL();
2453  }
2454 
2455  /* by band to UNION */
2456  for (i = 0; i < iwr->numband; i++) {
2457 
2458  /* by raster */
2459  for (j = 0; j < iwr->bandarg[i].numraster; j++) {
2460  reuserast = 0;
2461 
2462  /* type of union */
2463  utype = iwr->bandarg[i].uniontype;
2464 
2465  /* raster flags */
2466  isempty[0] = rt_raster_is_empty(iwr->bandarg[i].raster[j]);
2467  isempty[1] = rt_raster_is_empty(raster);
2468 
2469  if (!isempty[0])
2470  hasband[0] = rt_raster_has_band(iwr->bandarg[i].raster[j], 0);
2471  if (!isempty[1])
2472  hasband[1] = rt_raster_has_band(raster, iwr->bandarg[i].nband);
2473 
2474  /* determine pixtype, hasnodata and nodataval */
2475  _band = NULL;
2476  if (!isempty[0] && hasband[0])
2477  _band = rt_raster_get_band(iwr->bandarg[i].raster[j], 0);
2478  else if (!isempty[1] && hasband[1])
2479  _band = rt_raster_get_band(raster, iwr->bandarg[i].nband);
2480  else {
2481  pixtype = PT_64BF;
2482  hasnodata = 1;
2483  nodataval = rt_pixtype_get_min_value(pixtype);
2484  }
2485  if (_band != NULL) {
2486  pixtype = rt_band_get_pixtype(_band);
2487  hasnodata = 1;
2488  if (rt_band_get_hasnodata_flag(_band))
2489  rt_band_get_nodata(_band, &nodataval);
2490  else
2491  nodataval = rt_band_get_min_value(_band);
2492  }
2493 
2494  /* UT_MEAN and UT_RANGE require two passes */
2495  /* UT_MEAN: first for UT_COUNT and second for UT_SUM */
2496  if (iwr->bandarg[i].uniontype == UT_MEAN) {
2497  /* first pass, UT_COUNT */
2498  if (j < 1)
2499  utype = UT_COUNT;
2500  else
2501  utype = UT_SUM;
2502  }
2503  /* UT_RANGE: first for UT_MIN and second for UT_MAX */
2504  else if (iwr->bandarg[i].uniontype == UT_RANGE) {
2505  /* first pass, UT_MIN */
2506  if (j < 1)
2507  utype = UT_MIN;
2508  else
2509  utype = UT_MAX;
2510  }
2511 
2512  /* force band settings for UT_COUNT */
2513  if (utype == UT_COUNT) {
2514  pixtype = PT_32BUI;
2515  hasnodata = 0;
2516  nodataval = 0;
2517  }
2518 
2519  POSTGIS_RT_DEBUGF(4, "(pixtype, hasnodata, nodataval) = (%s, %d, %f)", rt_pixtype_name(pixtype), hasnodata, nodataval);
2520 
2521  /* set itrset */
2522  itrset[0].raster = iwr->bandarg[i].raster[j];
2523  itrset[0].nband = 0;
2524  itrset[1].raster = raster;
2525  itrset[1].nband = iwr->bandarg[i].nband;
2526 
2527  /* allow use NODATA to replace missing bands */
2528  if (nbnodata) {
2529  itrset[0].nbnodata = 1;
2530  itrset[1].nbnodata = 1;
2531  }
2532  /* missing bands are not ignored */
2533  else {
2534  itrset[0].nbnodata = 0;
2535  itrset[1].nbnodata = 0;
2536  }
2537 
2538  /* if rasters AND bands are present, use copy approach */
2539  if (!isempty[0] && !isempty[1] && hasband[0] && hasband[1]) {
2540  POSTGIS_RT_DEBUG(3, "using line method");
2541 
2542  /* generate empty out raster */
2544  iwr->bandarg[i].raster[j], raster,
2545  ET_UNION,
2546  &iraster, _offset
2547  ) != ES_NONE) {
2548 
2549  pfree(itrset);
2551  if (raster != NULL) {
2553  PG_FREE_IF_COPY(pgraster, 1);
2554  }
2555 
2556  MemoryContextSwitchTo(oldcontext);
2557  elog(ERROR, "RASTER_union_transfn: Could not create internal raster");
2558  PG_RETURN_NULL();
2559  }
2560  POSTGIS_RT_DEBUGF(4, "_offset = %f, %f, %f, %f",
2561  _offset[0], _offset[1], _offset[2], _offset[3]);
2562 
2563  /* rasters are spatially the same? */
2564  if (
2565  rt_raster_get_width(iwr->bandarg[i].raster[j]) == rt_raster_get_width(iraster) &&
2567  ) {
2568  double igt[6] = {0};
2569  double gt[6] = {0};
2570 
2572  rt_raster_get_geotransform_matrix(iraster, igt);
2573 
2574  reuserast = rt_util_same_geotransform_matrix(gt, igt);
2575  }
2576 
2577  /* use internal raster */
2578  if (!reuserast) {
2579  /* create band of same type */
2581  iraster,
2582  pixtype,
2583  nodataval,
2584  hasnodata, nodataval,
2585  0
2586  ) == -1) {
2587 
2588  pfree(itrset);
2590  rt_raster_destroy(iraster);
2591  if (raster != NULL) {
2593  PG_FREE_IF_COPY(pgraster, 1);
2594  }
2595 
2596  MemoryContextSwitchTo(oldcontext);
2597  elog(ERROR, "RASTER_union_transfn: Could not add new band to internal raster");
2598  PG_RETURN_NULL();
2599  }
2600  iband = rt_raster_get_band(iraster, 0);
2601 
2602  /* copy working raster to output raster */
2603  _dim[0] = rt_raster_get_width(iwr->bandarg[i].raster[j]);
2604  _dim[1] = rt_raster_get_height(iwr->bandarg[i].raster[j]);
2605  for (y = 0; y < _dim[1]; y++) {
2606  POSTGIS_RT_DEBUGF(4, "Getting pixel line of working raster at (x, y, length) = (0, %d, %d)", y, _dim[0]);
2608  _band,
2609  0, y,
2610  _dim[0],
2611  &vals, &nvals
2612  ) != ES_NONE) {
2613 
2614  pfree(itrset);
2616  rt_band_destroy(iband);
2617  rt_raster_destroy(iraster);
2618  if (raster != NULL) {
2620  PG_FREE_IF_COPY(pgraster, 1);
2621  }
2622 
2623  MemoryContextSwitchTo(oldcontext);
2624  elog(ERROR, "RASTER_union_transfn: Could not get pixel line from band of working raster");
2625  PG_RETURN_NULL();
2626  }
2627 
2628  POSTGIS_RT_DEBUGF(4, "Setting pixel line at (x, y, length) = (%d, %d, %d)", (int) _offset[0], (int) _offset[1] + y, nvals);
2630  iband,
2631  (int) _offset[0], (int) _offset[1] + y,
2632  vals, nvals
2633  ) != ES_NONE) {
2634 
2635  pfree(itrset);
2637  rt_band_destroy(iband);
2638  rt_raster_destroy(iraster);
2639  if (raster != NULL) {
2641  PG_FREE_IF_COPY(pgraster, 1);
2642  }
2643 
2644  MemoryContextSwitchTo(oldcontext);
2645  elog(ERROR, "RASTER_union_transfn: Could not set pixel line to band of internal raster");
2646  PG_RETURN_NULL();
2647  }
2648  }
2649  }
2650  else {
2651  rt_raster_destroy(iraster);
2652  iraster = iwr->bandarg[i].raster[j];
2653  iband = rt_raster_get_band(iraster, 0);
2654  }
2655 
2656  /* run iterator for extent of input raster */
2657  noerr = rt_raster_iterator(
2658  itrset, 2,
2659  ET_LAST, NULL,
2660  pixtype,
2661  hasnodata, nodataval,
2662  0, 0,
2663  NULL,
2664  &utype,
2666  &_raster
2667  );
2668  if (noerr != ES_NONE) {
2669 
2670  pfree(itrset);
2672  if (!reuserast) {
2673  rt_band_destroy(iband);
2674  rt_raster_destroy(iraster);
2675  }
2676  if (raster != NULL) {
2678  PG_FREE_IF_COPY(pgraster, 1);
2679  }
2680 
2681  MemoryContextSwitchTo(oldcontext);
2682  elog(ERROR, "RASTER_union_transfn: Could not run raster iterator function");
2683  PG_RETURN_NULL();
2684  }
2685 
2686  /* with iterator raster, copy data to output raster */
2687  _band = rt_raster_get_band(_raster, 0);
2688  _dim[0] = rt_raster_get_width(_raster);
2689  _dim[1] = rt_raster_get_height(_raster);
2690  for (y = 0; y < _dim[1]; y++) {
2691  POSTGIS_RT_DEBUGF(4, "Getting pixel line of iterator raster at (x, y, length) = (0, %d, %d)", y, _dim[0]);
2693  _band,
2694  0, y,
2695  _dim[0],
2696  &vals, &nvals
2697  ) != ES_NONE) {
2698 
2699  pfree(itrset);
2701  if (!reuserast) {
2702  rt_band_destroy(iband);
2703  rt_raster_destroy(iraster);
2704  }
2705  if (raster != NULL) {
2707  PG_FREE_IF_COPY(pgraster, 1);
2708  }
2709 
2710  MemoryContextSwitchTo(oldcontext);
2711  elog(ERROR, "RASTER_union_transfn: Could not get pixel line from band of working raster");
2712  PG_RETURN_NULL();
2713  }
2714 
2715  POSTGIS_RT_DEBUGF(4, "Setting pixel line at (x, y, length) = (%d, %d, %d)", (int) _offset[2], (int) _offset[3] + y, nvals);
2717  iband,
2718  (int) _offset[2], (int) _offset[3] + y,
2719  vals, nvals
2720  ) != ES_NONE) {
2721 
2722  pfree(itrset);
2724  if (!reuserast) {
2725  rt_band_destroy(iband);
2726  rt_raster_destroy(iraster);
2727  }
2728  if (raster != NULL) {
2730  PG_FREE_IF_COPY(pgraster, 1);
2731  }
2732 
2733  MemoryContextSwitchTo(oldcontext);
2734  elog(ERROR, "RASTER_union_transfn: Could not set pixel line to band of internal raster");
2735  PG_RETURN_NULL();
2736  }
2737  }
2738 
2739  /* free _raster */
2740  rt_band_destroy(_band);
2741  rt_raster_destroy(_raster);
2742 
2743  /* replace working raster with output raster */
2744  _raster = iraster;
2745  }
2746  else {
2747  POSTGIS_RT_DEBUG(3, "using pixel method");
2748 
2749  /* pass everything to iterator */
2750  noerr = rt_raster_iterator(
2751  itrset, 2,
2752  ET_UNION, NULL,
2753  pixtype,
2754  hasnodata, nodataval,
2755  0, 0,
2756  NULL,
2757  &utype,
2759  &_raster
2760  );
2761 
2762  if (noerr != ES_NONE) {
2763 
2764  pfree(itrset);
2766  if (raster != NULL) {
2768  PG_FREE_IF_COPY(pgraster, 1);
2769  }
2770 
2771  MemoryContextSwitchTo(oldcontext);
2772  elog(ERROR, "RASTER_union_transfn: Could not run raster iterator function");
2773  PG_RETURN_NULL();
2774  }
2775  }
2776 
2777  /* replace working raster */
2778  if (iwr->bandarg[i].raster[j] != NULL && !reuserast) {
2779  for (k = rt_raster_get_num_bands(iwr->bandarg[i].raster[j]) - 1; k >= 0; k--)
2781  rt_raster_destroy(iwr->bandarg[i].raster[j]);
2782  }
2783  iwr->bandarg[i].raster[j] = _raster;
2784  }
2785 
2786  }
2787 
2788  pfree(itrset);
2789  if (raster != NULL) {
2791  PG_FREE_IF_COPY(pgraster, 1);
2792  }
2793 
2794  /* switch back to local context */
2795  MemoryContextSwitchTo(oldcontext);
2796 
2797  POSTGIS_RT_DEBUG(3, "Finished");
2798 
2799  PG_RETURN_POINTER(iwr);
2800 }
#define FALSE
Definition: dbfopen.c:168
int rt_raster_generate_new_band(rt_raster raster, rt_pixtype pixtype, double initialvalue, uint32_t hasnodata, double nodatavalue, int index)
Generate a new inline band and add it to a raster.
Definition: rt_raster.c:485
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:674
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
rt_pixtype
Definition: librtcore.h:185
@ PT_32BUI
Definition: librtcore.h:194
@ PT_END
Definition: librtcore.h:197
@ PT_64BF
Definition: librtcore.h:196
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_pixel.c:148
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_raster.c:1347
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
Definition: rt_band.c:1745
@ ES_NONE
Definition: librtcore.h:180
rt_errorstate rt_band_set_pixel_line(rt_band band, int x, int y, void *vals, uint32_t len)
Set values of multiple pixels.
Definition: rt_band.c:853
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:340
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition: rt_raster.c:1540
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
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.
@ ET_LAST
Definition: librtcore.h:205
@ ET_UNION
Definition: librtcore.h:202
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:631
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
Definition: rt_raster.c:3361
int rt_util_same_geotransform_matrix(double *gt1, double *gt2)
Definition: rt_util.c:489
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:706
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
rt_errorstate rt_band_get_pixel_line(rt_band band, int x, int y, uint16_t len, void **vals, uint16_t *nvals)
Get values of multiple pixels.
Definition: rt_band.c:1137
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1334
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
nband
Definition: pixval.py:52
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
gt
Definition: window.py:77
char * text_to_cstring(const text *textptr)
char * rtpg_strtoupper(char *str)
static rtpg_union_type rtpg_uniontype_index_from_name(const char *cutype)
static void rtpg_union_arg_destroy(rtpg_union_arg arg)
struct rtpg_union_arg_t * rtpg_union_arg
static int rtpg_union_unionarg_process(rtpg_union_arg arg, ArrayType *array)
static int rtpg_union_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
rtpg_union_type
@ UT_MIN
@ UT_MEAN
@ UT_COUNT
@ UT_LAST
@ UT_SUM
@ UT_MAX
@ UT_RANGE
static int rtpg_union_noarg(rtpg_union_arg arg, rt_raster raster)
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rtpostgis.h:61
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
rt_raster raster
Definition: librtcore.h:2443
uint16_t nband
Definition: librtcore.h:2444
uint8_t nbnodata
Definition: librtcore.h:2445
Struct definitions.
Definition: librtcore.h:2250
rtpg_union_band_arg bandarg
rtpg_union_type uniontype

References rtpg_union_arg_t::bandarg, ES_NONE, ET_LAST, ET_UNION, FALSE, window::gt, rt_iterator_t::nband, rtpg_union_band_arg_t::nband, pixval::nband, rt_iterator_t::nbnodata, rtpg_union_arg_t::numband, rtpg_union_band_arg_t::numraster, POSTGIS_RT_DEBUG, POSTGIS_RT_DEBUGF, PT_32BUI, PT_64BF, PT_END, rt_iterator_t::raster, rtpg_union_band_arg_t::raster, rtrowdump::raster, rt_band_destroy(), rt_band_get_hasnodata_flag(), rt_band_get_min_value(), rt_band_get_nodata(), rt_band_get_pixel_line(), rt_band_get_pixtype(), rt_band_set_pixel_line(), rt_pixtype_get_min_value(), rt_pixtype_name(), rt_raster_clone(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_from_two_rasters(), rt_raster_generate_new_band(), rt_raster_get_band(), rt_raster_get_geotransform_matrix(), rt_raster_get_height(), rt_raster_get_num_bands(), rt_raster_get_width(), rt_raster_has_band(), rt_raster_is_empty(), rt_raster_iterator(), rt_util_same_geotransform_matrix(), rtpg_strtoupper(), rtpg_union_arg_destroy(), rtpg_union_callback(), rtpg_union_noarg(), rtpg_union_unionarg_process(), rtpg_uniontype_index_from_name(), text_to_cstring(), rtpg_union_band_arg_t::uniontype, UT_COUNT, UT_LAST, UT_MAX, UT_MEAN, UT_MIN, UT_RANGE, UT_SUM, and pixval::y.

Here is the call graph for this function: