PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_union_transfn()

Datum RASTER_union_transfn ( PG_FUNCTION_ARGS  )

Definition at line 2114 of file rtpg_mapalgebra.c.

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

References rtpg_union_arg_t::bandarg, ES_NONE, ET_LAST, ET_UNION, FALSE, rt_iterator_t::nband, rtpg_union_band_arg_t::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, 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, and UT_SUM.

Here is the call graph for this function: