PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ RASTER_union_transfn()

Datum RASTER_union_transfn ( PG_FUNCTION_ARGS  )

Definition at line 2073 of file rtpg_mapalgebra.c.

2074 {
2075  MemoryContext aggcontext;
2076  MemoryContext oldcontext;
2077  rtpg_union_arg iwr = NULL;
2078  int skiparg = 0;
2079 
2080  rt_pgraster *pgraster = NULL;
2081  rt_raster raster = NULL;
2082  rt_raster _raster = NULL;
2083  rt_band _band = NULL;
2084  int nband = 1;
2085  int noerr = 1;
2086  int isempty[2] = {0};
2087  int hasband[2] = {0};
2088  int nargs = 0;
2089  double _offset[4] = {0.};
2090  int nbnodata = 0; /* 1 if adding bands */
2091 
2092  int i = 0;
2093  int j = 0;
2094  int k = 0;
2095 
2096  rt_iterator itrset;
2097  char *utypename = NULL;
2098  rtpg_union_type utype = UT_LAST;
2099  rt_pixtype pixtype = PT_END;
2100  int hasnodata = 1;
2101  double nodataval = 0;
2102 
2103  rt_raster iraster = NULL;
2104  rt_band iband = NULL;
2105  int reuserast = 0;
2106  int y = 0;
2107  uint16_t _dim[2] = {0};
2108  void *vals = NULL;
2109  uint16_t nvals = 0;
2110 
2111  POSTGIS_RT_DEBUG(3, "Starting...");
2112 
2113  /* cannot be called directly as this is exclusive aggregate function */
2114  if (!AggCheckCallContext(fcinfo, &aggcontext)) {
2115  elog(ERROR, "RASTER_union_transfn: Cannot be called in a non-aggregate context");
2116  PG_RETURN_NULL();
2117  }
2118 
2119  /* switch to aggcontext */
2120  oldcontext = MemoryContextSwitchTo(aggcontext);
2121 
2122  if (PG_ARGISNULL(0)) {
2123  POSTGIS_RT_DEBUG(3, "Creating state variable");
2124  /* allocate container in aggcontext */
2125  iwr = MemoryContextAlloc(aggcontext, sizeof(struct rtpg_union_arg_t));
2126  if (iwr == NULL) {
2127  MemoryContextSwitchTo(oldcontext);
2128  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for state variable");
2129  PG_RETURN_NULL();
2130  }
2131 
2132  iwr->numband = 0;
2133  iwr->bandarg = NULL;
2134 
2135  skiparg = 0;
2136  }
2137  else {
2138  POSTGIS_RT_DEBUG(3, "State variable already exists");
2139  iwr = (rtpg_union_arg) PG_GETARG_POINTER(0);
2140  skiparg = 1;
2141  }
2142 
2143  /* raster arg is NOT NULL */
2144  if (!PG_ARGISNULL(1)) {
2145  /* deserialize raster */
2146  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2147 
2148  /* Get raster object */
2149  raster = rt_raster_deserialize(pgraster, FALSE);
2150  if (raster == NULL) {
2151 
2153  PG_FREE_IF_COPY(pgraster, 1);
2154 
2155  MemoryContextSwitchTo(oldcontext);
2156  elog(ERROR, "RASTER_union_transfn: Could not deserialize raster");
2157  PG_RETURN_NULL();
2158  }
2159  }
2160 
2161  /* process additional args if needed */
2162  nargs = PG_NARGS();
2163  POSTGIS_RT_DEBUGF(4, "nargs = %d", nargs);
2164  if (nargs > 2) {
2165  POSTGIS_RT_DEBUG(4, "processing additional arguments");
2166 
2167  /* if more than 2 arguments, determine the type of argument 3 */
2168  /* band number, UNION type or unionarg */
2169  if (!PG_ARGISNULL(2)) {
2170  Oid calltype = get_fn_expr_argtype(fcinfo->flinfo, 2);
2171 
2172  switch (calltype) {
2173  /* UNION type */
2174  case TEXTOID: {
2175  int idx = 0;
2176  int numband = 0;
2177 
2178  POSTGIS_RT_DEBUG(4, "Processing arg 3 as UNION type");
2179  nbnodata = 1;
2180 
2181  utypename = text_to_cstring(PG_GETARG_TEXT_P(2));
2182  utype = rtpg_uniontype_index_from_name(rtpg_strtoupper(utypename));
2183  POSTGIS_RT_DEBUGF(4, "Union type: %s", utypename);
2184 
2185  POSTGIS_RT_DEBUGF(4, "iwr->numband: %d", iwr->numband);
2186  /* see if we need to append new bands */
2187  if (raster) {
2188  idx = iwr->numband;
2189  numband = rt_raster_get_num_bands(raster);
2190  POSTGIS_RT_DEBUGF(4, "numband: %d", numband);
2191 
2192  /* only worry about appended bands */
2193  if (numband > iwr->numband)
2194  iwr->numband = numband;
2195  }
2196 
2197  if (!iwr->numband)
2198  iwr->numband = 1;
2199  POSTGIS_RT_DEBUGF(4, "iwr->numband: %d", iwr->numband);
2200  POSTGIS_RT_DEBUGF(4, "numband, idx: %d, %d", numband, idx);
2201 
2202  /* bandarg set. only possible after the first call to function */
2203  if (iwr->bandarg) {
2204  /* only reallocate if new bands need to be added */
2205  if (numband > idx) {
2206  POSTGIS_RT_DEBUG(4, "Reallocating iwr->bandarg");
2207  iwr->bandarg = repalloc(iwr->bandarg, sizeof(struct rtpg_union_band_arg_t) * iwr->numband);
2208  }
2209  /* prevent initial values step happening below */
2210  else
2211  idx = iwr->numband;
2212  }
2213  /* bandarg not set, first call to function */
2214  else {
2215  POSTGIS_RT_DEBUG(4, "Allocating iwr->bandarg");
2216  iwr->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * iwr->numband);
2217  }
2218  if (iwr->bandarg == NULL) {
2219 
2221  if (raster != NULL) {
2223  PG_FREE_IF_COPY(pgraster, 1);
2224  }
2225 
2226  MemoryContextSwitchTo(oldcontext);
2227  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for band information");
2228  PG_RETURN_NULL();
2229  }
2230 
2231  /* set initial values for bands that are "new" */
2232  for (i = idx; i < iwr->numband; i++) {
2233  iwr->bandarg[i].uniontype = utype;
2234  iwr->bandarg[i].nband = i;
2235 
2236  if (
2237  utype == UT_MEAN ||
2238  utype == UT_RANGE
2239  ) {
2240  iwr->bandarg[i].numraster = 2;
2241  }
2242  else
2243  iwr->bandarg[i].numraster = 1;
2244  iwr->bandarg[i].raster = NULL;
2245  }
2246 
2247  break;
2248  }
2249  /* band number */
2250  case INT2OID:
2251  case INT4OID:
2252  if (skiparg)
2253  break;
2254 
2255  POSTGIS_RT_DEBUG(4, "Processing arg 3 as band number");
2256  nband = PG_GETARG_INT32(2);
2257  if (nband < 1) {
2258 
2260  if (raster != NULL) {
2262  PG_FREE_IF_COPY(pgraster, 1);
2263  }
2264 
2265  MemoryContextSwitchTo(oldcontext);
2266  elog(ERROR, "RASTER_union_transfn: Band number must be greater than zero (1-based)");
2267  PG_RETURN_NULL();
2268  }
2269 
2270  iwr->numband = 1;
2271  iwr->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * iwr->numband);
2272  if (iwr->bandarg == NULL) {
2273 
2275  if (raster != NULL) {
2277  PG_FREE_IF_COPY(pgraster, 1);
2278  }
2279 
2280  MemoryContextSwitchTo(oldcontext);
2281  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for band information");
2282  PG_RETURN_NULL();
2283  }
2284 
2285  iwr->bandarg[0].uniontype = UT_LAST;
2286  iwr->bandarg[0].nband = nband - 1;
2287 
2288  iwr->bandarg[0].numraster = 1;
2289  iwr->bandarg[0].raster = NULL;
2290  break;
2291  /* only other type allowed is unionarg */
2292  default:
2293  if (skiparg)
2294  break;
2295 
2296  POSTGIS_RT_DEBUG(4, "Processing arg 3 as unionarg");
2297  if (!rtpg_union_unionarg_process(iwr, PG_GETARG_ARRAYTYPE_P(2))) {
2298 
2300  if (raster != NULL) {
2302  PG_FREE_IF_COPY(pgraster, 1);
2303  }
2304 
2305  MemoryContextSwitchTo(oldcontext);
2306  elog(ERROR, "RASTER_union_transfn: Could not process unionarg");
2307  PG_RETURN_NULL();
2308  }
2309 
2310  break;
2311  }
2312  }
2313 
2314  /* UNION type */
2315  if (nargs > 3 && !PG_ARGISNULL(3)) {
2316  utypename = text_to_cstring(PG_GETARG_TEXT_P(3));
2317  utype = rtpg_uniontype_index_from_name(rtpg_strtoupper(utypename));
2318  iwr->bandarg[0].uniontype = utype;
2319  POSTGIS_RT_DEBUGF(4, "Union type: %s", utypename);
2320 
2321  if (
2322  utype == UT_MEAN ||
2323  utype == UT_RANGE
2324  ) {
2325  iwr->bandarg[0].numraster = 2;
2326  }
2327  }
2328 
2329  /* allocate space for pointers to rt_raster */
2330  for (i = 0; i < iwr->numband; i++) {
2331  POSTGIS_RT_DEBUGF(4, "iwr->bandarg[%d].raster @ %p", i, iwr->bandarg[i].raster);
2332 
2333  /* no need to allocate */
2334  if (iwr->bandarg[i].raster != NULL)
2335  continue;
2336 
2337  POSTGIS_RT_DEBUGF(4, "Allocating space for working rasters of band %d", i);
2338 
2339  iwr->bandarg[i].raster = (rt_raster *) palloc(sizeof(rt_raster) * iwr->bandarg[i].numraster);
2340  if (iwr->bandarg[i].raster == NULL) {
2341 
2343  if (raster != NULL) {
2345  PG_FREE_IF_COPY(pgraster, 1);
2346  }
2347 
2348  MemoryContextSwitchTo(oldcontext);
2349  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for working raster(s)");
2350  PG_RETURN_NULL();
2351  }
2352 
2353  memset(iwr->bandarg[i].raster, 0, sizeof(rt_raster) * iwr->bandarg[i].numraster);
2354 
2355  /* add new working rt_raster but only if working raster already exists */
2356  if (i > 0 && !rt_raster_is_empty(iwr->bandarg[0].raster[0])) {
2357  for (j = 0; j < iwr->bandarg[i].numraster; j++) {
2358  iwr->bandarg[i].raster[j] = rt_raster_clone(iwr->bandarg[0].raster[0], 0); /* shallow clone */
2359  if (iwr->bandarg[i].raster[j] == NULL) {
2360 
2362  if (raster != NULL) {
2364  PG_FREE_IF_COPY(pgraster, 1);
2365  }
2366 
2367  MemoryContextSwitchTo(oldcontext);
2368  elog(ERROR, "RASTER_union_transfn: Could not create working raster");
2369  PG_RETURN_NULL();
2370  }
2371  }
2372  }
2373  }
2374  }
2375  /* only raster, no additional args */
2376  /* only do this if raster isn't empty */
2377  else {
2378  POSTGIS_RT_DEBUG(4, "no additional args, checking input raster");
2379  nbnodata = 1;
2380  if (!rtpg_union_noarg(iwr, raster)) {
2381 
2383  if (raster != NULL) {
2385  PG_FREE_IF_COPY(pgraster, 1);
2386  }
2387 
2388  MemoryContextSwitchTo(oldcontext);
2389  elog(ERROR, "RASTER_union_transfn: Could not check and balance number of bands");
2390  PG_RETURN_NULL();
2391  }
2392  }
2393 
2394  /* init itrset */
2395  itrset = palloc(sizeof(struct rt_iterator_t) * 2);
2396  if (itrset == NULL) {
2397 
2399  if (raster != NULL) {
2401  PG_FREE_IF_COPY(pgraster, 1);
2402  }
2403 
2404  MemoryContextSwitchTo(oldcontext);
2405  elog(ERROR, "RASTER_union_transfn: Could not allocate memory for iterator arguments");
2406  PG_RETURN_NULL();
2407  }
2408 
2409  /* by band to UNION */
2410  for (i = 0; i < iwr->numband; i++) {
2411 
2412  /* by raster */
2413  for (j = 0; j < iwr->bandarg[i].numraster; j++) {
2414  reuserast = 0;
2415 
2416  /* type of union */
2417  utype = iwr->bandarg[i].uniontype;
2418 
2419  /* raster flags */
2420  isempty[0] = rt_raster_is_empty(iwr->bandarg[i].raster[j]);
2421  isempty[1] = rt_raster_is_empty(raster);
2422 
2423  if (!isempty[0])
2424  hasband[0] = rt_raster_has_band(iwr->bandarg[i].raster[j], 0);
2425  if (!isempty[1])
2426  hasband[1] = rt_raster_has_band(raster, iwr->bandarg[i].nband);
2427 
2428  /* determine pixtype, hasnodata and nodataval */
2429  _band = NULL;
2430  if (!isempty[0] && hasband[0])
2431  _band = rt_raster_get_band(iwr->bandarg[i].raster[j], 0);
2432  else if (!isempty[1] && hasband[1])
2433  _band = rt_raster_get_band(raster, iwr->bandarg[i].nband);
2434  else {
2435  pixtype = PT_64BF;
2436  hasnodata = 1;
2437  nodataval = rt_pixtype_get_min_value(pixtype);
2438  }
2439  if (_band != NULL) {
2440  pixtype = rt_band_get_pixtype(_band);
2441  hasnodata = 1;
2442  if (rt_band_get_hasnodata_flag(_band))
2443  rt_band_get_nodata(_band, &nodataval);
2444  else
2445  nodataval = rt_band_get_min_value(_band);
2446  }
2447 
2448  /* UT_MEAN and UT_RANGE require two passes */
2449  /* UT_MEAN: first for UT_COUNT and second for UT_SUM */
2450  if (iwr->bandarg[i].uniontype == UT_MEAN) {
2451  /* first pass, UT_COUNT */
2452  if (j < 1)
2453  utype = UT_COUNT;
2454  else
2455  utype = UT_SUM;
2456  }
2457  /* UT_RANGE: first for UT_MIN and second for UT_MAX */
2458  else if (iwr->bandarg[i].uniontype == UT_RANGE) {
2459  /* first pass, UT_MIN */
2460  if (j < 1)
2461  utype = UT_MIN;
2462  else
2463  utype = UT_MAX;
2464  }
2465 
2466  /* force band settings for UT_COUNT */
2467  if (utype == UT_COUNT) {
2468  pixtype = PT_32BUI;
2469  hasnodata = 0;
2470  nodataval = 0;
2471  }
2472 
2473  POSTGIS_RT_DEBUGF(4, "(pixtype, hasnodata, nodataval) = (%s, %d, %f)", rt_pixtype_name(pixtype), hasnodata, nodataval);
2474 
2475  /* set itrset */
2476  itrset[0].raster = iwr->bandarg[i].raster[j];
2477  itrset[0].nband = 0;
2478  itrset[1].raster = raster;
2479  itrset[1].nband = iwr->bandarg[i].nband;
2480 
2481  /* allow use NODATA to replace missing bands */
2482  if (nbnodata) {
2483  itrset[0].nbnodata = 1;
2484  itrset[1].nbnodata = 1;
2485  }
2486  /* missing bands are not ignored */
2487  else {
2488  itrset[0].nbnodata = 0;
2489  itrset[1].nbnodata = 0;
2490  }
2491 
2492  /* if rasters AND bands are present, use copy approach */
2493  if (!isempty[0] && !isempty[1] && hasband[0] && hasband[1]) {
2494  POSTGIS_RT_DEBUG(3, "using line method");
2495 
2496  /* generate empty out raster */
2498  iwr->bandarg[i].raster[j], raster,
2499  ET_UNION,
2500  &iraster, _offset
2501  ) != ES_NONE) {
2502 
2503  pfree(itrset);
2505  if (raster != NULL) {
2507  PG_FREE_IF_COPY(pgraster, 1);
2508  }
2509 
2510  MemoryContextSwitchTo(oldcontext);
2511  elog(ERROR, "RASTER_union_transfn: Could not create internal raster");
2512  PG_RETURN_NULL();
2513  }
2514  POSTGIS_RT_DEBUGF(4, "_offset = %f, %f, %f, %f",
2515  _offset[0], _offset[1], _offset[2], _offset[3]);
2516 
2517  /* rasters are spatially the same? */
2518  if (
2519  rt_raster_get_width(iwr->bandarg[i].raster[j]) == rt_raster_get_width(iraster) &&
2521  ) {
2522  double igt[6] = {0};
2523  double gt[6] = {0};
2524 
2526  rt_raster_get_geotransform_matrix(iraster, igt);
2527 
2528  reuserast = rt_util_same_geotransform_matrix(gt, igt);
2529  }
2530 
2531  /* use internal raster */
2532  if (!reuserast) {
2533  /* create band of same type */
2535  iraster,
2536  pixtype,
2537  nodataval,
2538  hasnodata, nodataval,
2539  0
2540  ) == -1) {
2541 
2542  pfree(itrset);
2544  rt_raster_destroy(iraster);
2545  if (raster != NULL) {
2547  PG_FREE_IF_COPY(pgraster, 1);
2548  }
2549 
2550  MemoryContextSwitchTo(oldcontext);
2551  elog(ERROR, "RASTER_union_transfn: Could not add new band to internal raster");
2552  PG_RETURN_NULL();
2553  }
2554  iband = rt_raster_get_band(iraster, 0);
2555 
2556  /* copy working raster to output raster */
2557  _dim[0] = rt_raster_get_width(iwr->bandarg[i].raster[j]);
2558  _dim[1] = rt_raster_get_height(iwr->bandarg[i].raster[j]);
2559  for (y = 0; y < _dim[1]; y++) {
2560  POSTGIS_RT_DEBUGF(4, "Getting pixel line of working raster at (x, y, length) = (0, %d, %d)", y, _dim[0]);
2562  _band,
2563  0, y,
2564  _dim[0],
2565  &vals, &nvals
2566  ) != ES_NONE) {
2567 
2568  pfree(itrset);
2570  rt_band_destroy(iband);
2571  rt_raster_destroy(iraster);
2572  if (raster != NULL) {
2574  PG_FREE_IF_COPY(pgraster, 1);
2575  }
2576 
2577  MemoryContextSwitchTo(oldcontext);
2578  elog(ERROR, "RASTER_union_transfn: Could not get pixel line from band of working raster");
2579  PG_RETURN_NULL();
2580  }
2581 
2582  POSTGIS_RT_DEBUGF(4, "Setting pixel line at (x, y, length) = (%d, %d, %d)", (int) _offset[0], (int) _offset[1] + y, nvals);
2584  iband,
2585  (int) _offset[0], (int) _offset[1] + y,
2586  vals, nvals
2587  ) != ES_NONE) {
2588 
2589  pfree(itrset);
2591  rt_band_destroy(iband);
2592  rt_raster_destroy(iraster);
2593  if (raster != NULL) {
2595  PG_FREE_IF_COPY(pgraster, 1);
2596  }
2597 
2598  MemoryContextSwitchTo(oldcontext);
2599  elog(ERROR, "RASTER_union_transfn: Could not set pixel line to band of internal raster");
2600  PG_RETURN_NULL();
2601  }
2602  }
2603  }
2604  else {
2605  rt_raster_destroy(iraster);
2606  iraster = iwr->bandarg[i].raster[j];
2607  iband = rt_raster_get_band(iraster, 0);
2608  }
2609 
2610  /* run iterator for extent of input raster */
2611  noerr = rt_raster_iterator(
2612  itrset, 2,
2613  ET_LAST, NULL,
2614  pixtype,
2615  hasnodata, nodataval,
2616  0, 0,
2617  NULL,
2618  &utype,
2620  &_raster
2621  );
2622  if (noerr != ES_NONE) {
2623 
2624  pfree(itrset);
2626  if (!reuserast) {
2627  rt_band_destroy(iband);
2628  rt_raster_destroy(iraster);
2629  }
2630  if (raster != NULL) {
2632  PG_FREE_IF_COPY(pgraster, 1);
2633  }
2634 
2635  MemoryContextSwitchTo(oldcontext);
2636  elog(ERROR, "RASTER_union_transfn: Could not run raster iterator function");
2637  PG_RETURN_NULL();
2638  }
2639 
2640  /* with iterator raster, copy data to output raster */
2641  _band = rt_raster_get_band(_raster, 0);
2642  _dim[0] = rt_raster_get_width(_raster);
2643  _dim[1] = rt_raster_get_height(_raster);
2644  for (y = 0; y < _dim[1]; y++) {
2645  POSTGIS_RT_DEBUGF(4, "Getting pixel line of iterator raster at (x, y, length) = (0, %d, %d)", y, _dim[0]);
2647  _band,
2648  0, y,
2649  _dim[0],
2650  &vals, &nvals
2651  ) != ES_NONE) {
2652 
2653  pfree(itrset);
2655  if (!reuserast) {
2656  rt_band_destroy(iband);
2657  rt_raster_destroy(iraster);
2658  }
2659  if (raster != NULL) {
2661  PG_FREE_IF_COPY(pgraster, 1);
2662  }
2663 
2664  MemoryContextSwitchTo(oldcontext);
2665  elog(ERROR, "RASTER_union_transfn: Could not get pixel line from band of working raster");
2666  PG_RETURN_NULL();
2667  }
2668 
2669  POSTGIS_RT_DEBUGF(4, "Setting pixel line at (x, y, length) = (%d, %d, %d)", (int) _offset[2], (int) _offset[3] + y, nvals);
2671  iband,
2672  (int) _offset[2], (int) _offset[3] + y,
2673  vals, nvals
2674  ) != ES_NONE) {
2675 
2676  pfree(itrset);
2678  if (!reuserast) {
2679  rt_band_destroy(iband);
2680  rt_raster_destroy(iraster);
2681  }
2682  if (raster != NULL) {
2684  PG_FREE_IF_COPY(pgraster, 1);
2685  }
2686 
2687  MemoryContextSwitchTo(oldcontext);
2688  elog(ERROR, "RASTER_union_transfn: Could not set pixel line to band of internal raster");
2689  PG_RETURN_NULL();
2690  }
2691  }
2692 
2693  /* free _raster */
2694  rt_band_destroy(_band);
2695  rt_raster_destroy(_raster);
2696 
2697  /* replace working raster with output raster */
2698  _raster = iraster;
2699  }
2700  else {
2701  POSTGIS_RT_DEBUG(3, "using pixel method");
2702 
2703  /* pass everything to iterator */
2704  noerr = rt_raster_iterator(
2705  itrset, 2,
2706  ET_UNION, NULL,
2707  pixtype,
2708  hasnodata, nodataval,
2709  0, 0,
2710  NULL,
2711  &utype,
2713  &_raster
2714  );
2715 
2716  if (noerr != ES_NONE) {
2717 
2718  pfree(itrset);
2720  if (raster != NULL) {
2722  PG_FREE_IF_COPY(pgraster, 1);
2723  }
2724 
2725  MemoryContextSwitchTo(oldcontext);
2726  elog(ERROR, "RASTER_union_transfn: Could not run raster iterator function");
2727  PG_RETURN_NULL();
2728  }
2729  }
2730 
2731  /* replace working raster */
2732  if (iwr->bandarg[i].raster[j] != NULL && !reuserast) {
2733  for (k = rt_raster_get_num_bands(iwr->bandarg[i].raster[j]) - 1; k >= 0; k--)
2735  rt_raster_destroy(iwr->bandarg[i].raster[j]);
2736  }
2737  iwr->bandarg[i].raster[j] = _raster;
2738  }
2739 
2740  }
2741 
2742  pfree(itrset);
2743  if (raster != NULL) {
2745  PG_FREE_IF_COPY(pgraster, 1);
2746  }
2747 
2748  /* switch back to local context */
2749  MemoryContextSwitchTo(oldcontext);
2750 
2751  POSTGIS_RT_DEBUG(3, "Finished");
2752 
2753  PG_RETURN_POINTER(iwr);
2754 }
#define FALSE
Definition: dbfopen.c:72
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:489
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:86
rt_pixtype
Definition: librtcore.h:187
@ PT_32BUI
Definition: librtcore.h:196
@ PT_END
Definition: librtcore.h:199
@ PT_64BF
Definition: librtcore.h:198
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_pixel.c:150
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:1375
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:1902
@ ES_NONE
Definition: librtcore.h:182
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:376
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition: rt_raster.c:1568
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:133
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:207
@ ET_UNION
Definition: librtcore.h:204
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1887
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:125
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:3464
int rt_util_same_geotransform_matrix(double *gt1, double *gt2)
Definition: rt_util.c:538
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:710
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:1362
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:385
nband
Definition: pixval.py:53
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:78
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:65
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:69
rt_raster raster
Definition: librtcore.h:2596
uint16_t nband
Definition: librtcore.h:2597
uint8_t nbnodata
Definition: librtcore.h:2598
Struct definitions.
Definition: librtcore.h:2403
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(), 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: