62{
63 bytea *bytea_data;
65 int data_len = 0;
66 VSILFILE *vsifp = NULL;
67 GDALDatasetH hdsSrc;
68 int32_t srid = -1;
69
72
73
74 if (PG_ARGISNULL(0))
75 PG_RETURN_NULL();
76
77
78 bytea_data = (bytea *) PG_GETARG_BYTEA_P(0);
79 data = (uint8_t *) VARDATA(bytea_data);
80 data_len = VARSIZE_ANY_EXHDR(bytea_data);
81
82
83
84 if (!PG_ARGISNULL(1))
86
87
88 vsifp = VSIFileFromMemBuffer(
"/vsimem/in.dat", data, data_len,
FALSE);
89 if (vsifp == NULL) {
90 PG_FREE_IF_COPY(bytea_data, 0);
91 elog(ERROR, "RASTER_fromGDALRaster: Could not load bytea into memory file for use by GDAL");
92 PG_RETURN_NULL();
93 }
94
95
97
98
100 if (hdsSrc == NULL) {
101 VSIFCloseL(vsifp);
102 PG_FREE_IF_COPY(bytea_data, 0);
103 elog(ERROR, "RASTER_fromGDALRaster: Could not open bytea with GDAL. Check that the bytea is of a GDAL supported format");
104 PG_RETURN_NULL();
105 }
106
107#if POSTGIS_DEBUG_LEVEL > 3
108 {
109 GDALDriverH hdrv = GDALGetDatasetDriver(hdsSrc);
110
112 GDALGetDriverShortName(hdrv),
113 GDALGetRasterXSize(hdsSrc),
114 GDALGetRasterYSize(hdsSrc)
115 );
116 }
117#endif
118
119
121
122 GDALClose(hdsSrc);
123 VSIFCloseL(vsifp);
124 PG_FREE_IF_COPY(bytea_data, 0);
125
126 if (raster == NULL) {
127 elog(ERROR, "RASTER_fromGDALRaster: Could not convert GDAL raster to raster");
128 PG_RETURN_NULL();
129 }
130
131
132 if (srid != -1)
134
137 if (!pgraster)
138 PG_RETURN_NULL();
139
140 SET_VARSIZE(pgraster, pgraster->
size);
141 PG_RETURN_POINTER(pgraster);
142}
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,...)