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);
#define SRID_UNKNOWN
Unknown SRID value.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
int rt_util_gdal_register_all(int force_register_all)
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
uint16_t rt_raster_get_num_bands(rt_raster raster)
uint16_t rt_raster_get_height(rt_raster raster)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
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.
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
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)
#define POSTGIS_RT_DEBUG(level, msg)