33 #include <utils/builtins.h>
34 #include "utils/lsyscache.h"
35 #include "utils/array.h"
36 #include "catalog/pg_type.h"
57 uint16 width = 0, height = 0;
58 double ipx = 0, ipy = 0, scalex = 0, scaley = 0, skewx = 0, skewy = 0;
64 elog(ERROR,
"RASTER_makeEmpty: ST_MakeEmptyRaster requires 9 args");
69 width = PG_GETARG_UINT16(0);
72 height = PG_GETARG_UINT16(1);
75 ipx = PG_GETARG_FLOAT8(2);
78 ipy = PG_GETARG_FLOAT8(3);
81 scalex = PG_GETARG_FLOAT8(4);
84 scaley = PG_GETARG_FLOAT8(5);
87 skewx = PG_GETARG_FLOAT8(6);
90 skewy = PG_GETARG_FLOAT8(7);
93 srid = PG_GETARG_INT32(8);
96 width, height, ipx, ipy, scalex, scaley,
113 SET_VARSIZE(pgraster, pgraster->
size);
114 PG_RETURN_POINTER(pgraster);
127 int maxbandindex = 0;
129 int lastnumbands = 0;
131 text *text_pixtype = NULL;
132 char *char_pixtype = NULL;
142 struct addbandarg *arg = NULL;
162 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
167 PG_FREE_IF_COPY(pgraster, 0);
168 elog(ERROR,
"RASTER_addBand: Could not deserialize raster");
174 array = PG_GETARG_ARRAYTYPE_P(1);
175 etype = ARR_ELEMTYPE(array);
176 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
178 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
182 PG_FREE_IF_COPY(pgraster, 0);
183 elog(ERROR,
"RASTER_addBand: Invalid argument for addbandargset");
188 arg = (
struct addbandarg *) palloc(
sizeof(
struct addbandarg) * n);
191 PG_FREE_IF_COPY(pgraster, 0);
192 elog(ERROR,
"RASTER_addBand: Could not allocate memory for addbandarg");
202 for (i = 0; i < n; i++) {
203 if (nulls[i])
continue;
208 tup = (HeapTupleHeader) DatumGetPointer(e[i]);
212 PG_FREE_IF_COPY(pgraster, 0);
213 elog(ERROR,
"RASTER_addBand: Invalid argument for addbandargset");
219 arg[i].append =
TRUE;
220 tupv = GetAttributeByName(tup,
"index", &isnull);
222 arg[i].index = DatumGetInt32(tupv);
223 arg[i].append =
FALSE;
227 if (!arg[i].append && arg[i].index < 1) {
230 PG_FREE_IF_COPY(pgraster, 0);
231 elog(ERROR,
"RASTER_addBand: Invalid argument for addbandargset. Invalid band index (must be 1-based) for addbandarg of index %d", i);
237 tupv = GetAttributeByName(tup,
"pixeltype", &isnull);
241 PG_FREE_IF_COPY(pgraster, 0);
242 elog(ERROR,
"RASTER_addBand: Invalid argument for addbandargset. Pixel type cannot be NULL for addbandarg of index %d", i);
245 text_pixtype = (text *) DatumGetPointer(tupv);
246 if (text_pixtype == NULL) {
249 PG_FREE_IF_COPY(pgraster, 0);
250 elog(ERROR,
"RASTER_addBand: Invalid argument for addbandargset. Pixel type cannot be NULL for addbandarg of index %d", i);
257 if (arg[i].pixtype ==
PT_END) {
260 PG_FREE_IF_COPY(pgraster, 0);
261 elog(ERROR,
"RASTER_addBand: Invalid argument for addbandargset. Invalid pixel type for addbandarg of index %d", i);
266 arg[i].initialvalue = 0;
267 tupv = GetAttributeByName(tup,
"initialvalue", &isnull);
269 arg[i].initialvalue = DatumGetFloat8(tupv);
272 arg[i].hasnodata =
FALSE;
273 arg[i].nodatavalue = 0;
274 tupv = GetAttributeByName(tup,
"nodataval", &isnull);
276 arg[i].hasnodata =
TRUE;
277 arg[i].nodatavalue = DatumGetFloat8(tupv);
283 for (i = 0; i < n; i++) {
284 if (nulls[i])
continue;
287 maxbandindex = lastnumbands + 1;
290 if (!arg[i].append) {
291 if (arg[i].index > maxbandindex) {
292 elog(NOTICE,
"Band index for addbandarg of index %d exceeds possible value. Adding band at index %d", i, maxbandindex);
293 arg[i].index = maxbandindex;
298 arg[i].index = maxbandindex;
300 POSTGIS_RT_DEBUGF(4,
"new band (index, pixtype, initialvalue, hasnodata, nodatavalue) = (%d, %s, %f, %s, %f)",
304 arg[i].hasnodata ?
"TRUE" :
"FALSE",
310 arg[i].pixtype, arg[i].initialvalue,
311 arg[i].hasnodata, arg[i].nodatavalue,
316 if (numbands == lastnumbands || bandindex == -1) {
319 PG_FREE_IF_COPY(pgraster, 0);
320 elog(ERROR,
"RASTER_addBand: Could not add band defined by addbandarg of index %d to raster", i);
324 lastnumbands = numbands;
332 PG_FREE_IF_COPY(pgraster, 0);
336 SET_VARSIZE(pgrtn, pgrtn->
size);
337 PG_RETURN_POINTER(pgrtn);
354 bool appendband =
FALSE;
372 if (!PG_ARGISNULL(0)) {
373 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
378 PG_FREE_IF_COPY(pgraster, 0);
379 elog(ERROR,
"RASTER_addBandRasterArray: Could not deserialize destination raster");
391 PG_RETURN_POINTER(pgraster);
398 if (!PG_ARGISNULL(2))
399 srcnband = PG_GETARG_INT32(2);
401 elog(NOTICE,
"Invalid band index for source rasters (must be 1-based). Returning original raster");
404 PG_RETURN_POINTER(pgraster);
412 if (!PG_ARGISNULL(3)) {
413 dstnband = PG_GETARG_INT32(3);
417 elog(NOTICE,
"Invalid band index for destination raster (must be 1-based). Returning original raster");
420 PG_RETURN_POINTER(pgraster);
433 if (dstnumbands < 1) {
438 dstnband = dstnumbands + 1;
439 else if (dstnband > dstnumbands) {
440 elog(NOTICE,
"Band index provided for destination raster is greater than the number of bands in the raster. Bands will be appended");
442 dstnband = dstnumbands + 1;
450 array = PG_GETARG_ARRAYTYPE_P(1);
451 etype = ARR_ELEMTYPE(array);
452 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
454 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
463 for (i = 0; i < n; i++) {
464 if (nulls[i])
continue;
474 if (pgraster != NULL)
475 PG_FREE_IF_COPY(pgraster, 0);
476 elog(ERROR,
"RASTER_addBandRasterArray: Could not deserialize source raster at index %d", i + 1);
484 if (srcnband > srcnumbands - 1) {
485 elog(NOTICE,
"Invalid band index for source raster at index %d. Returning original raster", i + 1);
491 PG_RETURN_POINTER(pgraster);
508 if (pgraster != NULL)
509 PG_FREE_IF_COPY(pgraster, 0);
510 elog(ERROR,
"RASTER_addBandRasterArray: Could not create raster from source raster at index %d", i + 1);
523 elog(NOTICE,
"Could not add band from source raster at index %d to destination raster. Returning original raster", i + 1);
527 if (pgraster != NULL)
528 PG_RETURN_POINTER(pgraster);
541 if (pgraster != NULL)
542 PG_FREE_IF_COPY(pgraster, 0);
546 SET_VARSIZE(pgrtn, pgrtn->
size);
547 PG_RETURN_POINTER(pgrtn);
566 int appendband =
FALSE;
567 char *outdbfile = NULL;
568 int *srcnband = NULL;
570 int allbands =
FALSE;
571 int hasnodata =
FALSE;
572 double nodataval = 0.;
575 char *authname = NULL;
576 char *authcode = NULL;
583 double ogt[6] = {0.};
589 if (!PG_ARGISNULL(0)) {
590 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
595 PG_FREE_IF_COPY(pgraster, 0);
596 elog(ERROR,
"RASTER_addBandOutDB: Cannot deserialize destination raster");
604 if (!PG_ARGISNULL(1))
605 dstnband = PG_GETARG_INT32(1);
610 if (PG_ARGISNULL(2)) {
611 elog(NOTICE,
"Out-db raster file not provided. Returning original raster");
612 if (pgraster != NULL) {
614 PG_RETURN_POINTER(pgraster);
621 if (!strlen(outdbfile)) {
622 elog(NOTICE,
"Out-db raster file not provided. Returning original raster");
623 if (pgraster != NULL) {
625 PG_RETURN_POINTER(pgraster);
633 if (!PG_ARGISNULL(3)) {
645 array = PG_GETARG_ARRAYTYPE_P(3);
646 etype = ARR_ELEMTYPE(array);
647 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
654 if (pgraster != NULL) {
656 PG_FREE_IF_COPY(pgraster, 0);
658 elog(ERROR,
"RASTER_addBandOutDB: Invalid data type for band indexes");
663 deconstruct_array(array, etype, typlen, typbyval, typalign, &e, &nulls, &numsrcnband);
665 srcnband = palloc(
sizeof(
int) * numsrcnband);
666 if (srcnband == NULL) {
667 if (pgraster != NULL) {
669 PG_FREE_IF_COPY(pgraster, 0);
671 elog(ERROR,
"RASTER_addBandOutDB: Cannot allocate memory for band indexes");
675 for (i = 0, j = 0; i < numsrcnband; i++) {
676 if (nulls[i])
continue;
680 srcnband[j] = DatumGetInt16(e[i]);
683 srcnband[j] = DatumGetInt32(e[i]);
689 if (j < numsrcnband) {
690 srcnband = repalloc(srcnband,
sizeof(
int) * j);
691 if (srcnband == NULL) {
692 if (pgraster != NULL) {
694 PG_FREE_IF_COPY(pgraster, 0);
696 elog(ERROR,
"RASTER_addBandOutDB: Cannot reallocate memory for band indexes");
707 if (!PG_ARGISNULL(4)) {
709 nodataval = PG_GETARG_FLOAT8(4);
721 elog(NOTICE,
"Invalid band index %d for adding bands. Using band index 1", dstnband);
724 else if (numbands > 0 && dstnband > numbands) {
725 elog(NOTICE,
"Invalid band index %d for adding bands. Using band index %d", dstnband, numbands);
726 dstnband = numbands + 1;
730 dstnband = numbands + 1;
736 if (hdsOut == NULL) {
737 if (pgraster != NULL) {
739 PG_FREE_IF_COPY(pgraster, 0);
741 elog(ERROR,
"RASTER_addBandOutDB: Cannot open out-db file with GDAL");
746 if (GDALGetGeoTransform(hdsOut, ogt) != CE_None) {
759 elog(ERROR,
"RASTER_addBandOutDB: Cannot create new raster");
767 strcmp(authname,
"EPSG") == 0 &&
773 elog(INFO,
"Unknown SRS auth name and code from out-db file. Defaulting SRID of new raster to %d",
SRID_UNKNOWN);
776 elog(INFO,
"Cannot get SRS auth name and code from out-db file. Defaulting SRID of new raster to %d",
SRID_UNKNOWN);
794 if (pgraster != NULL)
795 PG_FREE_IF_COPY(pgraster, 0);
796 elog(ERROR,
"RASTER_addBandOutDB: Cannot test alignment of out-db file");
800 elog(WARNING,
"The in-db representation of the out-db raster is not aligned. Band data may be incorrect");
804 numsrcnband = GDALGetRasterCount(hdsOut);
807 srcnband = palloc(
sizeof(
int) * numsrcnband);
808 if (srcnband == NULL) {
811 if (pgraster != NULL)
812 PG_FREE_IF_COPY(pgraster, 0);
813 elog(ERROR,
"RASTER_addBandOutDB: Cannot allocate memory for band indexes");
817 for (i = 0, j = 1; i < numsrcnband; i++, j++)
824 for (i = 0, j = dstnband - 1; i < numsrcnband; i++, j++) {
829 hasnodata, nodataval,
830 srcnband[i], outdbfile,
836 if (pgraster != NULL)
837 PG_FREE_IF_COPY(pgraster, 0);
838 elog(ERROR,
"RASTER_addBandOutDB: Cannot create new out-db band");
846 if (pgraster != NULL)
847 PG_FREE_IF_COPY(pgraster, 0);
848 elog(ERROR,
"RASTER_addBandOutDB: Cannot add new out-db band to raster");
855 if (pgraster != NULL)
856 PG_FREE_IF_COPY(pgraster, 0);
860 SET_VARSIZE(pgrtn, pgrtn->
size);
861 PG_RETURN_POINTER(pgrtn);
877 int oldtorastnumbands = 0;
878 int newtorastnumbands = 0;
879 int newbandindex = 0;
882 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
883 pgto = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
887 PG_FREE_IF_COPY(pgto, 0);
888 elog(ERROR,
"RASTER_copyBand: Could not deserialize first raster");
893 if (!PG_ARGISNULL(1)) {
894 pgfrom = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
899 PG_FREE_IF_COPY(pgfrom, 1);
900 PG_FREE_IF_COPY(pgto, 0);
901 elog(ERROR,
"RASTER_copyBand: Could not deserialize second raster");
910 fromband = PG_GETARG_INT32(2);
913 toindex = oldtorastnumbands + 1;
915 toindex = PG_GETARG_INT32(3);
920 fromband - 1, toindex - 1
924 if (newtorastnumbands == oldtorastnumbands || newbandindex == -1) {
925 elog(NOTICE,
"RASTER_copyBand: Could not add band to raster. "
926 "Returning original raster."
931 PG_FREE_IF_COPY(pgfrom, 1);
937 PG_FREE_IF_COPY(pgto, 0);
938 if (!pgrtn) PG_RETURN_NULL();
940 SET_VARSIZE(pgrtn, pgrtn->
size);
941 PG_RETURN_POINTER(pgrtn);
950 FuncCallContext *funcctx;
983 struct tile_arg_t *arg1 = NULL;
984 struct tile_arg_t *arg2 = NULL;
986 if (SRF_IS_FIRSTCALL()) {
987 MemoryContext oldcontext;
1003 funcctx = SRF_FIRSTCALL_INIT();
1006 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1009 if (PG_ARGISNULL(0)) {
1010 MemoryContextSwitchTo(oldcontext);
1011 SRF_RETURN_DONE(funcctx);
1015 arg1 = palloc(
sizeof(
struct tile_arg_t));
1017 MemoryContextSwitchTo(oldcontext);
1018 elog(ERROR,
"RASTER_tile: Could not allocate memory for arguments");
1019 SRF_RETURN_DONE(funcctx);
1022 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
1024 if (!arg1->raster.raster) {
1026 errcode(ERRCODE_OUT_OF_MEMORY),
1027 errmsg(
"Could not deserialize raster")
1030 PG_FREE_IF_COPY(pgraster, 0);
1031 MemoryContextSwitchTo(oldcontext);
1032 SRF_RETURN_DONE(funcctx);
1049 if (PG_ARGISNULL(1)) {
1050 elog(NOTICE,
"Width cannot be NULL. Returning NULL");
1053 PG_FREE_IF_COPY(pgraster, 0);
1054 MemoryContextSwitchTo(oldcontext);
1055 SRF_RETURN_DONE(funcctx);
1057 arg1->tile.width = PG_GETARG_INT32(1);
1058 if (arg1->tile.width < 1) {
1059 elog(NOTICE,
"Width must be greater than zero. Returning NULL");
1062 PG_FREE_IF_COPY(pgraster, 0);
1063 MemoryContextSwitchTo(oldcontext);
1064 SRF_RETURN_DONE(funcctx);
1068 if (PG_ARGISNULL(2)) {
1069 elog(NOTICE,
"Height cannot be NULL. Returning NULL");
1072 PG_FREE_IF_COPY(pgraster, 0);
1073 MemoryContextSwitchTo(oldcontext);
1074 SRF_RETURN_DONE(funcctx);
1076 arg1->tile.height = PG_GETARG_INT32(2);
1077 if (arg1->tile.height < 1) {
1078 elog(NOTICE,
"Height must be greater than zero. Returning NULL");
1081 PG_FREE_IF_COPY(pgraster, 0);
1082 MemoryContextSwitchTo(oldcontext);
1083 SRF_RETURN_DONE(funcctx);
1087 if (numbands && !PG_ARGISNULL(3)) {
1088 array = PG_GETARG_ARRAYTYPE_P(3);
1089 etype = ARR_ELEMTYPE(array);
1090 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1099 PG_FREE_IF_COPY(pgraster, 0);
1100 MemoryContextSwitchTo(oldcontext);
1101 elog(ERROR,
"RASTER_tile: Invalid data type for band indexes");
1102 SRF_RETURN_DONE(funcctx);
1106 deconstruct_array(array, etype, typlen, typbyval, typalign, &e, &nulls, &(arg1->numbands));
1108 arg1->nbands = palloc(
sizeof(
int) * arg1->numbands);
1109 if (arg1->nbands == NULL) {
1112 PG_FREE_IF_COPY(pgraster, 0);
1113 MemoryContextSwitchTo(oldcontext);
1114 elog(ERROR,
"RASTER_tile: Could not allocate memory for band indexes");
1115 SRF_RETURN_DONE(funcctx);
1118 for (i = 0, j = 0; i < arg1->numbands; i++) {
1119 if (nulls[i])
continue;
1123 arg1->nbands[j] = DatumGetInt16(e[i]) - 1;
1126 arg1->nbands[j] = DatumGetInt32(e[i]) - 1;
1133 if (j < arg1->numbands) {
1134 arg1->nbands = repalloc(arg1->nbands,
sizeof(
int) * j);
1135 if (arg1->nbands == NULL) {
1138 PG_FREE_IF_COPY(pgraster, 0);
1139 MemoryContextSwitchTo(oldcontext);
1140 elog(ERROR,
"RASTER_tile: Could not reallocate memory for band indexes");
1141 SRF_RETURN_DONE(funcctx);
1148 for (i = 0; i < arg1->numbands; i++) {
1150 elog(NOTICE,
"Band at index %d not found in raster", arg1->nbands[i] + 1);
1152 pfree(arg1->nbands);
1154 PG_FREE_IF_COPY(pgraster, 0);
1155 MemoryContextSwitchTo(oldcontext);
1156 SRF_RETURN_DONE(funcctx);
1161 arg1->numbands = numbands;
1164 arg1->nbands = palloc(
sizeof(
int) * arg1->numbands);
1166 if (arg1->nbands == NULL) {
1169 PG_FREE_IF_COPY(pgraster, 0);
1170 MemoryContextSwitchTo(oldcontext);
1171 elog(ERROR,
"RASTER_dumpValues: Could not allocate memory for pixel values");
1172 SRF_RETURN_DONE(funcctx);
1175 for (i = 0; i < arg1->numbands; i++) {
1176 arg1->nbands[i] = i;
1183 if (!PG_ARGISNULL(4)) {
1184 arg1->pad.pad = PG_GETARG_BOOL(4) ? 1 : 0;
1186 if (arg1->pad.pad && !PG_ARGISNULL(5)) {
1187 arg1->pad.hasnodata = 1;
1188 arg1->pad.nodataval = PG_GETARG_FLOAT8(5);
1191 arg1->pad.hasnodata = 0;
1192 arg1->pad.nodataval = 0;
1197 arg1->pad.hasnodata = 0;
1198 arg1->pad.nodataval = 0;
1208 arg1->tile.nx = ceil(arg1->raster.width / (
double) arg1->tile.width);
1209 arg1->tile.ny = ceil(arg1->raster.height / (
double) arg1->tile.height);
1210 POSTGIS_RT_DEBUGF(4,
"# of tiles (x, y) = (%d, %d)", arg1->tile.nx, arg1->tile.ny);
1213 funcctx->user_fctx = arg1;
1216 funcctx->max_calls = (arg1->tile.nx * arg1->tile.ny);
1218 MemoryContextSwitchTo(oldcontext);
1222 funcctx = SRF_PERCALL_SETUP();
1224 call_cntr = funcctx->call_cntr;
1225 max_calls = funcctx->max_calls;
1226 arg2 = funcctx->user_fctx;
1229 if (call_cntr < max_calls) {
1236 double nodataval = 0;
1262 ty = call_cntr / arg2->tile.nx;
1263 tx = call_cntr % arg2->tile.nx;
1267 if (!arg2->pad.pad) {
1268 if (ty + 1 == arg2->tile.ny)
1270 if (tx + 1 == arg2->tile.nx)
1275 rx = tx * arg2->tile.width;
1276 ry = ty * arg2->tile.height;
1281 width = arg2->tile.width;
1282 height = arg2->tile.height;
1288 width = arg2->raster.width - rx;
1291 height = arg2->raster.height - ry;
1303 if (arg2->numbands) pfree(arg2->nbands);
1305 elog(ERROR,
"RASTER_tile: Could not compute the coordinates of the upper-left corner of the output tile");
1306 SRF_RETURN_DONE(funcctx);
1312 len = arg2->tile.width;
1313 if (rx + arg2->tile.width >= arg2->raster.width)
1314 len = arg2->raster.width - rx;
1318 for (i = 0; i < arg2->numbands; i++) {
1322 if (_band == NULL) {
1323 int nband = arg2->nbands[i] + 1;
1326 pfree(arg2->nbands);
1328 elog(ERROR,
"RASTER_tile: Could not get band %d from source raster",
nband);
1329 SRF_RETURN_DONE(funcctx);
1336 else if (arg2->pad.pad && arg2->pad.hasnodata) {
1338 nodataval = arg2->pad.nodataval;
1348 pfree(arg2->nbands);
1350 elog(ERROR,
"RASTER_tile: Could not add new band to output tile");
1351 SRF_RETURN_DONE(funcctx);
1357 pfree(arg2->nbands);
1359 elog(ERROR,
"RASTER_tile: Could not get newly added band from output tile");
1360 SRF_RETURN_DONE(funcctx);
1370 for (j = 0; j < arg2->tile.height; j++) {
1373 if (k >= arg2->raster.height) {
1382 pfree(arg2->nbands);
1384 elog(ERROR,
"RASTER_tile: Could not get pixel line from source raster");
1385 SRF_RETURN_DONE(funcctx);
1391 pfree(arg2->nbands);
1393 elog(ERROR,
"RASTER_tile: Could not set pixel line of output tile");
1394 SRF_RETURN_DONE(funcctx);
1406 hasnodata, nodataval,
1413 pfree(arg2->nbands);
1415 elog(ERROR,
"RASTER_tile: Could not create new offline band for output tile");
1416 SRF_RETURN_DONE(funcctx);
1423 pfree(arg2->nbands);
1425 elog(ERROR,
"RASTER_tile: Could not add new offline band to output tile");
1426 SRF_RETURN_DONE(funcctx);
1435 if (arg2->numbands) pfree(arg2->nbands);
1437 SRF_RETURN_DONE(funcctx);
1440 SET_VARSIZE(pgtile, pgtile->
size);
1441 SRF_RETURN_NEXT(funcctx, PointerGetDatum(pgtile));
1446 if (arg2->numbands) pfree(arg2->nbands);
1448 SRF_RETURN_DONE(funcctx);
1480 if (PG_ARGISNULL(0))
1482 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1486 PG_FREE_IF_COPY(pgraster, 0);
1487 elog(ERROR,
"RASTER_band: Could not deserialize raster");
1492 if (PG_ARGISNULL(1)) {
1493 elog(NOTICE,
"Band number(s) not provided. Returning original raster");
1499 array = PG_GETARG_ARRAYTYPE_P(1);
1500 etype = ARR_ELEMTYPE(array);
1501 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1509 PG_FREE_IF_COPY(pgraster, 0);
1510 elog(ERROR,
"RASTER_band: Invalid data type for band number(s)");
1515 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
1518 bandNums = palloc(
sizeof(
uint32_t) * n);
1519 for (i = 0, j = 0; i < n; i++) {
1520 if (nulls[i])
continue;
1524 idx = (
uint32_t) DatumGetInt16(e[i]);
1527 idx = (
uint32_t) DatumGetInt32(e[i]);
1532 if (idx > numBands || idx < 1) {
1533 elog(NOTICE,
"Invalid band index (must use 1-based). Returning original raster");
1538 bandNums[j] = idx - 1;
1543 if (skip || j < 1) {
1553 PG_FREE_IF_COPY(pgraster, 0);
1555 elog(ERROR,
"RASTER_band: Could not create new raster");
1565 SET_VARSIZE(pgrast, pgrast->
size);
1566 PG_RETURN_POINTER(pgrast);
1569 PG_RETURN_POINTER(pgraster);
#define SRID_UNKNOWN
Unknown SRID value.
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
int rt_util_gdal_register_all(int force_register_all)
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.
const char * rt_band_get_ext_path(rt_band band)
Return band's external path (only valid when rt_band_is_offline returns non-zero).
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
rt_errorstate rt_band_set_pixel_line(rt_band band, int x, int y, void *vals, uint32_t len)
Set values of multiple pixels.
void rt_band_destroy(rt_band band)
Destroy a raster band.
uint16_t rt_raster_get_num_bands(rt_raster raster)
uint16_t rt_raster_get_height(rt_raster raster)
rt_band rt_band_new_offline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t bandNum, const char *path)
Create an out-db rt_band.
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands' external band number (only valid when rt_band_is_offline returns non-zero).
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums, int count)
Construct a new rt_raster from an existing rt_raster and an array of band numbers.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
const char * rt_pixtype_name(rt_pixtype pixtype)
rt_band rt_band_new_offline_from_path(uint16_t width, uint16_t height, int hasnodata, double nodataval, uint8_t bandNum, const char *path, int force)
Create an out-db rt_band from path.
uint16_t rt_raster_get_width(rt_raster raster)
rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode)
Get auth name and code.
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
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.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
char * text_to_cstring(const text *textptr)
PG_FUNCTION_INFO_V1(RASTER_makeEmpty)
Make a new raster with no bands.
Datum RASTER_tile(PG_FUNCTION_ARGS)
Datum RASTER_addBand(PG_FUNCTION_ARGS)
Datum RASTER_band(PG_FUNCTION_ARGS)
Datum RASTER_makeEmpty(PG_FUNCTION_ARGS)
Datum RASTER_copyBand(PG_FUNCTION_ARGS)
Datum RASTER_addBandOutDB(PG_FUNCTION_ARGS)
Datum RASTER_addBandRasterArray(PG_FUNCTION_ARGS)
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)