152 text *formattext = NULL;
154 char **options = NULL;
155 text *optiontext = NULL;
171 uint8_t *gdal = NULL;
172 uint64_t gdal_size = 0;
174 uint64_t result_size = 0;
179 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
180 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
184 PG_FREE_IF_COPY(pgraster, 0);
185 elog(ERROR,
"RASTER_asGDALRaster: Could not deserialize raster");
190 if (PG_ARGISNULL(1)) {
191 elog(NOTICE,
"Format must be provided");
193 PG_FREE_IF_COPY(pgraster, 0);
197 formattext = PG_GETARG_TEXT_P(1);
198 format = text_to_cstring(formattext);
204 if (!PG_ARGISNULL(2)) {
206 array = PG_GETARG_ARRAYTYPE_P(2);
207 etype = ARR_ELEMTYPE(array);
208 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
215 PG_FREE_IF_COPY(pgraster, 0);
216 elog(ERROR,
"RASTER_asGDALRaster: Invalid data type for options");
221 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
225 options = (
char **) palloc(
sizeof(
char *) * (n + 1));
226 if (options == NULL) {
228 PG_FREE_IF_COPY(pgraster, 0);
229 elog(ERROR,
"RASTER_asGDALRaster: Could not allocate memory for options");
234 for (i = 0, j = 0; i < n; i++) {
235 if (nulls[i])
continue;
240 optiontext = (text *) DatumGetPointer(e[i]);
241 if (NULL == optiontext)
break;
242 option = text_to_cstring(optiontext);
250 if (strlen(option)) {
251 options[j] = (
char *) palloc(
sizeof(
char) * (strlen(option) + 1));
252 strcpy(options[j], option);
259 options = repalloc(options, (j + 1) *
sizeof(
char *));
277 srid = PG_GETARG_INT32(3);
283 if (NULL != options) {
284 for (i = j - 1; i >= 0; i--) pfree(options[i]);
288 PG_FREE_IF_COPY(pgraster, 0);
289 elog(ERROR,
"RASTER_asGDALRaster: Could not find srtext for SRID (%d)", srid);
301 if (NULL != options) {
302 for (i = j - 1; i >= 0; i--) pfree(options[i]);
305 if (NULL != srs) pfree(srs);
307 PG_FREE_IF_COPY(pgraster, 0);
310 elog(ERROR,
"RASTER_asGDALRaster: Could not allocate and generate GDAL raster");
313 POSTGIS_RT_DEBUGF(3,
"RASTER_asGDALRaster: GDAL raster generated with %d bytes", (
int) gdal_size);
316 result_size = gdal_size + VARHDRSZ;
317 result = (bytea *) palloc(result_size);
319 elog(ERROR,
"RASTER_asGDALRaster: Insufficient virtual memory for GDAL raster");
322 SET_VARSIZE(
result, result_size);
323 memcpy(VARDATA(
result), gdal, VARSIZE_ANY_EXHDR(
result));
328 POSTGIS_RT_DEBUG(3,
"RASTER_asGDALRaster: Returning pointer to GDAL raster");
329 PG_RETURN_POINTER(
result);
char result[OUT_DOUBLE_BUFFER_SIZE]
#define SRID_UNKNOWN
Unknown SRID value.
int32_t clamp_srid(int32_t srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
uint8_t * rt_raster_to_gdal(rt_raster raster, const char *srs, char *format, char **options, uint64_t *gdalsize)
Return formatted GDAL raster from raster.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
char * rtpg_getSR(int32_t srid)
char * rtpg_trim(const char *input)
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)