153 text *formattext = NULL;
155 char **options = NULL;
156 text *optiontext = NULL;
173 uint64_t gdal_size = 0;
174 bytea *result = NULL;
175 uint64_t result_size = 0;
180 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
181 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
185 PG_FREE_IF_COPY(pgraster, 0);
186 elog(ERROR,
"RASTER_asGDALRaster: Could not deserialize raster");
191 if (PG_ARGISNULL(1)) {
192 elog(NOTICE,
"Format must be provided");
194 PG_FREE_IF_COPY(pgraster, 0);
198 formattext = PG_GETARG_TEXT_P(1);
205 if (!PG_ARGISNULL(2)) {
207 array = PG_GETARG_ARRAYTYPE_P(2);
208 etype = ARR_ELEMTYPE(array);
209 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
216 PG_FREE_IF_COPY(pgraster, 0);
217 elog(ERROR,
"RASTER_asGDALRaster: Invalid data type for options");
222 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
226 options = (
char **) palloc(
sizeof(
char *) * (n + 1));
227 if (options == NULL) {
229 PG_FREE_IF_COPY(pgraster, 0);
230 elog(ERROR,
"RASTER_asGDALRaster: Could not allocate memory for options");
235 for (i = 0, j = 0; i < n; i++) {
236 if (nulls[i])
continue;
241 optiontext = (text *) DatumGetPointer(e[i]);
242 if (NULL == optiontext)
break;
251 if (strlen(option)) {
252 options[j] = (
char *) palloc(
sizeof(
char) * (strlen(option) + 1));
253 strcpy(options[j], option);
260 options = repalloc(options, (j + 1) *
sizeof(
char *));
278 srid = PG_GETARG_INT32(3);
284 if (NULL != options) {
285 for (i = j - 1; i >= 0; i--) pfree(options[i]);
289 PG_FREE_IF_COPY(pgraster, 0);
290 elog(ERROR,
"RASTER_asGDALRaster: Could not find srtext for SRID (%d)", srid);
302 if (NULL != options) {
303 for (i = j - 1; i >= 0; i--) pfree(options[i]);
306 if (NULL != srs) pfree(srs);
308 PG_FREE_IF_COPY(pgraster, 0);
311 elog(ERROR,
"RASTER_asGDALRaster: Could not allocate and generate GDAL raster");
314 POSTGIS_RT_DEBUGF(3,
"RASTER_asGDALRaster: GDAL raster generated with %d bytes", (
int) gdal_size);
317 result_size = gdal_size + VARHDRSZ;
318 result = (bytea *) palloc(result_size);
319 if (NULL == result) {
320 elog(ERROR,
"RASTER_asGDALRaster: Insufficient virtual memory for GDAL raster");
323 SET_VARSIZE(result, result_size);
324 memcpy(VARDATA(result), gdal, VARSIZE(result) - VARHDRSZ);
329 POSTGIS_RT_DEBUG(3,
"RASTER_asGDALRaster: Returning pointer to GDAL raster");
330 PG_RETURN_POINTER(result);
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
#define SRID_UNKNOWN
Unknown SRID value.
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 * text_to_cstring(const text *textptr)
char * rtpg_getSR(int srid)
char * rtpg_trim(const char *input)
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)