PostGIS  2.2.7dev-r@@SVN_REVISION@@
lwout_twkb.h
Go to the documentation of this file.
1 
2 /**********************************************************************
3  *
4  * PostGIS - Spatial Types for PostgreSQL
5  * http://postgis.net
6  * Copyright 2013 Nicklas Avén
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include "liblwgeom_internal.h"
14 #include "lwgeom_log.h"
15 #include <limits.h>
16 #include "bytebuffer.h"
17 
18 /* Maximum number of geometry dimmensions that internal arrays can hold */
19 #define MAX_N_DIMS 4
20 
21 #define MAX_BBOX_SIZE 64
22 #define MAX_SIZE_SIZE 8
23 
24 
29 #define FIRST_BYTE_SET_BBOXES(flag, bool) ((flag) = ((bool) ? (flag) | 0x01 : (flag) & (~0x01)))
30 #define FIRST_BYTE_SET_SIZES(flag, bool) ((flag) = ((bool) ? (flag) | 0x02 : (flag) & (~0x02)))
31 #define FIRST_BYTE_SET_IDLIST(flag, bool) ((flag) = ((bool) ? (flag) | 0x04 : (flag) & (~0x04)))
32 #define FIRST_BYTE_SET_EXTENDED(flag, bool) ((flag) = ((bool) ? (flag) | 0x08 : (flag) & (~0x08)))
33 #define FIRST_BYTE_SET_EMPTY(flag, bool) ((flag) = ((bool) ? (flag) | 0x10 : (flag) & (~0x10)))
34 
35 
42 #define TYPE_PREC_SET_TYPE(flag, type) ((flag) = ((flag) & 0xF0) | (((type) & 0x0F)))
43 #define TYPE_PREC_SET_PREC(flag, prec) ((flag) = ((flag) & 0x0F) | (((prec) & 0x0F) << 4))
44 
45 #define HIGHER_DIM_SET_HASZ(flag, bool) ((flag) = ((bool) ? (flag) | 0x01 : (flag) & (~0x01)))
46 #define HIGHER_DIM_SET_HASM(flag, bool) ((flag) = ((bool) ? (flag) | 0x02 : (flag) & (~0x02)))
47 
48 #define HIGHER_DIM_SET_PRECZ(flag, prec) ((flag) = ((flag) & 0xE3) | (((prec) & 0x07) << 2))
49 #define HIGHER_DIM_SET_PRECM(flag, prec) ((flag) = ((flag) & 0x1F) | (((prec) & 0x07) << 5))
50 
51 typedef struct
52 {
53  /* Options defined at start */
54  uint8_t variant;
55  int8_t prec_xy;
56  int8_t prec_z;
57  int8_t prec_m;
58  float factor[4]; /*What factor to multiply the coordiinates with to get the requested precision*/
59 } TWKB_GLOBALS;
60 
61 typedef struct
62 {
63  uint8_t variant; /*options that change at runtime*/
66  int hasz;
67  int hasm;
68  const int64_t *idlist;
69  int64_t bbox_min[MAX_N_DIMS];
70  int64_t bbox_max[MAX_N_DIMS];
71  int64_t accum_rels[MAX_N_DIMS]; /*Holds the acculmulated relative values*/
72 } TWKB_STATE;
73 
74 static int lwgeom_to_twkb_buf(const LWGEOM *geom, TWKB_GLOBALS *global_values, TWKB_STATE *ts);
75 
76 static int lwpoint_to_twkb_buf(const LWPOINT *line, TWKB_GLOBALS *global_values, TWKB_STATE *ts);
77 static int lwline_to_twkb_buf(const LWLINE *line, TWKB_GLOBALS *global_values, TWKB_STATE *ts);
78 static int lwpoly_to_twkb_buf(const LWPOLY *poly, TWKB_GLOBALS *global_values, TWKB_STATE *ts);
79 static int lwcollection_to_twkb_buf(const LWCOLLECTION *col, TWKB_GLOBALS *global_values, TWKB_STATE *ts);
80 static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *global_values, TWKB_STATE *parent_state);
81 
static int lwgeom_to_twkb_buf(const LWGEOM *geom, TWKB_GLOBALS *global_values, TWKB_STATE *ts)
uint8_t variant
Definition: lwout_twkb.h:54
static int lwcollection_to_twkb_buf(const LWCOLLECTION *col, TWKB_GLOBALS *global_values, TWKB_STATE *ts)
int8_t prec_z
Definition: lwout_twkb.h:56
uint8_t variant
Definition: lwout_twkb.h:63
bytebuffer_t * header_buf
Definition: lwout_twkb.h:64
const int64_t * idlist
Definition: lwout_twkb.h:68
int8_t prec_xy
Definition: lwout_twkb.h:55
static int lwline_to_twkb_buf(const LWLINE *line, TWKB_GLOBALS *global_values, TWKB_STATE *ts)
int8_t prec_m
Definition: lwout_twkb.h:57
static int lwpoly_to_twkb_buf(const LWPOLY *poly, TWKB_GLOBALS *global_values, TWKB_STATE *ts)
static int lwpoint_to_twkb_buf(const LWPOINT *line, TWKB_GLOBALS *global_values, TWKB_STATE *ts)
#define MAX_N_DIMS
Definition: lwout_twkb.h:19
bytebuffer_t * geom_buf
Definition: lwout_twkb.h:65
static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *global_values, TWKB_STATE *parent_state)