PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ RASTER_union_transfn()

Datum RASTER_union_transfn ( PG_FUNCTION_ARGS  )

Definition at line 2079 of file rtpg_mapalgebra.c.

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