Construct an rt_raster from a binary WKB representation.
278 {
279 const uint8_t *ptr = wkb;
280 const uint8_t *wkbend = NULL;
282 uint8_t endian = 0;
283 uint16_t version = 0;
284 uint16_t i = 0;
285 uint16_t j = 0;
286
287 assert(NULL != ptr);
288
289
291 rterror(
"rt_raster_from_wkb: wkb size (%" PRIu32
292 ") < min size (%zu)",
294 return NULL;
295 }
296 wkbend = wkb + wkbsize;
297
298 RASTER_DEBUGF(3,
"Parsing header from wkb position %zu (expected 0)",
299 d_binptr_to_pos(ptr, wkbend, wkbsize));
300
302
303
304 endian = *ptr;
305 ptr += 1;
306
307
309 if (version != 0) {
310 rterror(
"rt_raster_from_wkb: WKB version %d unsupported", version);
311 return NULL;
312 }
313
314
316 if (!rast) {
317 rterror(
"rt_raster_from_wkb: Out of memory allocating raster for wkb input");
318 return NULL;
319 }
320
331
332
333 assert(ptr <= wkbend);
334
347 RASTER_DEBUGF(3,
"Parsing raster header finished at wkb position %zu (expected 61)",
348 d_binptr_to_pos(ptr, wkbend, wkbsize));
349
351
352
353 if (!
rast->numBands) {
354
355 if (ptr < wkbend) {
356 rtwarn(
"%zu bytes of WKB remained unparsed", wkbend - ptr);
357 }
358 else if (ptr > wkbend) {
359
360 rtwarn(
"We parsed %zu bytes more then available!", ptr - wkbend);
361 }
362
365 }
366
367
370 rterror(
"rt_raster_from_wkb: Out of memory allocating bands for WKB raster decoding");
372 return NULL;
373 }
374
375
376
377 assert(ptr <= wkbend);
378
379 for (i = 0; i <
rast->numBands; ++i) {
381 d_binptr_to_pos(ptr, wkbend, wkbsize));
382
384 &ptr, wkbend, endian);
385 if (!band) {
386 rterror(
"rt_raster_from_wkb: Error reading WKB form of band %d", i);
389 return NULL;
390 }
391
394 }
395
396
397 if (ptr < wkbend) {
398 rtwarn(
"%zu bytes of WKB remained unparsed", wkbend - ptr);
399 }
400 else if (ptr > wkbend) {
401
402 rtwarn(
"We parsed %zu bytes more then available!", ptr - wkbend);
403 }
404
406}
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,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUGF(level, msg,...)
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
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)