Construct an rt_raster from a binary WKB representation.
276 {
277 const uint8_t *ptr = wkb;
278 const uint8_t *wkbend = NULL;
280 uint8_t endian = 0;
281 uint16_t version = 0;
282 uint16_t i = 0;
283 uint16_t j = 0;
284
285 assert(NULL != ptr);
286
287
289 rterror(
"rt_raster_from_wkb: wkb size (%d) < min size (%d)",
291 return NULL;
292 }
293 wkbend = wkb + wkbsize;
294
295 RASTER_DEBUGF(3,
"Parsing header from wkb position %d (expected 0)",
296 d_binptr_to_pos(ptr, wkbend, wkbsize));
297
299
300
301 endian = *ptr;
302 ptr += 1;
303
304
306 if (version != 0) {
307 rterror(
"rt_raster_from_wkb: WKB version %d unsupported", version);
308 return NULL;
309 }
310
311
313 if (!rast) {
314 rterror(
"rt_raster_from_wkb: Out of memory allocating raster for wkb input");
315 return NULL;
316 }
317
328
329
330 assert(ptr <= wkbend);
331
344 RASTER_DEBUGF(3,
"Parsing raster header finished at wkb position %d (expected 61)",
345 d_binptr_to_pos(ptr, wkbend, wkbsize));
346
348
349
350 if (!
rast->numBands) {
351
352 if (ptr < wkbend) {
353 rtwarn(
"%d bytes of WKB remained unparsed", wkbend - ptr);
354 }
355 else if (ptr > wkbend) {
356
357 rtwarn(
"We parsed %d bytes more then available!", ptr - wkbend);
358 }
359
362 }
363
364
367 rterror(
"rt_raster_from_wkb: Out of memory allocating bands for WKB raster decoding");
369 return NULL;
370 }
371
372
373
374 assert(ptr <= wkbend);
375
376 for (i = 0; i <
rast->numBands; ++i) {
378 d_binptr_to_pos(ptr, wkbend, wkbsize));
379
381 &ptr, wkbend, endian);
382 if (!band) {
383 rterror(
"rt_raster_from_wkb: Error reading WKB form of band %d", i);
386 return NULL;
387 }
388
391 }
392
393
394 if (ptr < wkbend) {
395 rtwarn(
"%d bytes of WKB remained unparsed", wkbend - ptr);
396 }
397 else if (ptr > wkbend) {
398
399 rtwarn(
"We parsed %d bytes more then available!", ptr - wkbend);
400 }
401
403}
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...
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUGF(level, msg,...)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
void rtwarn(const char *fmt,...)
void rt_band_destroy(rt_band band)
Destroy a raster band.
struct rt_raster_t * rt_raster
Types definitions.
double read_float64(const uint8_t **from, uint8_t littleEndian)
int32_t read_int32(const uint8_t **from, uint8_t littleEndian)
uint16_t read_uint16(const uint8_t **from, uint8_t littleEndian)
#define CHECK_BINPTR_POSITION(ptr, end, size, pos)
static rt_band rt_band_from_wkb(uint16_t width, uint16_t height, const uint8_t **ptr, const uint8_t *end, uint8_t littleEndian)