64{
65 bytea *bytea_data;
67 int data_len = 0;
68 VSILFILE *vsifp = NULL;
69 GDALDatasetH hdsSrc;
70 int32_t srid = -1;
71
74
75
76 if (PG_ARGISNULL(0))
77 PG_RETURN_NULL();
78
79
80 bytea_data = (bytea *) PG_GETARG_BYTEA_P(0);
81 data = (uint8_t *) VARDATA(bytea_data);
82 data_len = VARSIZE_ANY_EXHDR(bytea_data);
83
84
85
86 if (!PG_ARGISNULL(1))
88
89
90 vsifp = VSIFileFromMemBuffer(
"/vsimem/in.dat", data, data_len,
FALSE);
91 if (vsifp == NULL) {
92 PG_FREE_IF_COPY(bytea_data, 0);
93 elog(ERROR, "RASTER_fromGDALRaster: Could not load bytea into memory file for use by GDAL");
94 PG_RETURN_NULL();
95 }
96
97
99
100
102 if (hdsSrc == NULL) {
103 VSIFCloseL(vsifp);
104 PG_FREE_IF_COPY(bytea_data, 0);
105 elog(ERROR, "RASTER_fromGDALRaster: Could not open bytea with GDAL. Check that the bytea is of a GDAL supported format");
106 PG_RETURN_NULL();
107 }
108
109#if POSTGIS_DEBUG_LEVEL > 3
110 {
111 GDALDriverH hdrv = GDALGetDatasetDriver(hdsSrc);
112
114 GDALGetDriverShortName(hdrv),
115 GDALGetRasterXSize(hdsSrc),
116 GDALGetRasterYSize(hdsSrc)
117 );
118 }
119#endif
120
121
123
124 GDALClose(hdsSrc);
125 VSIFCloseL(vsifp);
126 PG_FREE_IF_COPY(bytea_data, 0);
127
128 if (raster == NULL) {
129 elog(ERROR, "RASTER_fromGDALRaster: Could not convert GDAL raster to raster");
130 PG_RETURN_NULL();
131 }
132
133
134 if (srid != -1)
136
139 if (!pgraster)
140 PG_RETURN_NULL();
141
142 SET_VARSIZE(pgraster, pgraster->
size);
143 PG_RETURN_POINTER(pgraster);
144}
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...
int rt_util_gdal_register_all(int force_register_all)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
#define POSTGIS_RT_DEBUGF(level, msg,...)