PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ rt_band_new_offline()

rt_band rt_band_new_offline ( uint16_t  width,
uint16_t  height,
rt_pixtype  pixtype,
uint32_t  hasnodata,
double  nodataval,
uint8_t  bandNum,
const char *  path 
)

Create an out-db rt_band.

Parameters
width: number of pixel columns
height: number of pixel rows
pixtype: pixel type for the band
hasnodata: indicates if the band has nodata value
nodataval: the nodata value, will be appropriately truncated to fit the pixtype size.
bandNum: 0-based band number in the external file to associate this band with.
path: NULL-terminated path string pointing to the file containing band data. The string will NOT be copied, ownership is left to caller which is responsible to keep it allocated for the whole lifetime of the returned rt_band.
Returns
an rt_band, or 0 on failure

Definition at line 124 of file rt_band.c.

129 {
130 rt_band band = NULL;
131 int pathlen = 0;
132
133 assert(NULL != path);
134
135 band = rtalloc(sizeof(struct rt_band_t));
136 if (band == NULL) {
137 rterror("rt_band_new_offline: Out of memory allocating rt_band");
138 return NULL;
139 }
140
141 RASTER_DEBUGF(3, "Created rt_band @ %p with pixtype %s",
142 band, rt_pixtype_name(pixtype)
143 );
144
145 band->pixtype = pixtype;
146 band->offline = 1;
147 band->width = width;
148 band->height = height;
149 band->hasnodata = hasnodata ? 1 : 0;
150 band->nodataval = 0;
151 band->isnodata = FALSE; /* we don't know if the offline band is NODATA */
152 band->ownsdata = 0; /* offline, flag is useless as all offline data cache is owned internally */
153 band->raster = NULL;
154
155 /* properly set nodataval as it may need to be constrained to the data type */
156 if (hasnodata && rt_band_set_nodata(band, nodataval, NULL) != ES_NONE) {
157 rterror("rt_band_new_offline: Could not set NODATA value");
158 rt_band_destroy(band);
159 return NULL;
160 }
161
162 band->data.offline.bandNum = bandNum;
163
164 /* memory for data.offline.path is managed internally */
165 pathlen = strlen(path);
166 band->data.offline.path = rtalloc(sizeof(char) * (pathlen + 1));
167 if (band->data.offline.path == NULL) {
168 rterror("rt_band_new_offline: Out of memory allocating offline path");
169 rt_band_destroy(band);
170 return NULL;
171 }
172 memcpy(band->data.offline.path, path, pathlen);
173 band->data.offline.path[pathlen] = '\0';
174
175 band->data.offline.mem = NULL;
176
177 return band;
178}
#define FALSE
Definition dbfopen.c:168
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:171
#define RASTER_DEBUGF(level, msg,...)
Definition librtcore.h:299
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition rt_pixel.c:110
@ ES_NONE
Definition librtcore.h:180
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition rt_band.c:733
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition rt_band.c:340

References ES_NONE, FALSE, RASTER_DEBUGF, rt_band_destroy(), rt_band_set_nodata(), rt_pixtype_name(), rtalloc(), and rterror().

Referenced by convert_raster(), RASTER_tile(), rt_band_duplicate(), rt_band_new_offline_from_path(), and test_band_metadata().

Here is the call graph for this function:
Here is the caller graph for this function: