PostGIS  2.1.10dev-r@@SVN_REVISION@@
static LWPOLY* lwpoly_from_gserialized_buffer ( uint8_t *  data_ptr,
uint8_t  g_flags,
size_t *  g_size 
)
static

Definition at line 1043 of file g_serialized.c.

References LWPOLY::bbox, LWPOLY::flags, FLAGS_GET_M, FLAGS_GET_Z, FLAGS_NDIMS, lw_get_uint32_t(), lwalloc(), LWDEBUGF, LWPOLY::nrings, POLYGONTYPE, ptarray_construct_reference_data(), LWPOLY::rings, LWPOLY::srid, SRID_UNKNOWN, and LWPOLY::type.

Referenced by lwgeom_from_gserialized_buffer().

1044 {
1045  uint8_t *start_ptr = data_ptr;
1046  LWPOLY *poly;
1047  uint8_t *ordinate_ptr;
1048  uint32_t nrings = 0;
1049  int i = 0;
1050 
1051  assert(data_ptr);
1052 
1053  poly = (LWPOLY*)lwalloc(sizeof(LWPOLY));
1054  poly->srid = SRID_UNKNOWN; /* Default */
1055  poly->bbox = NULL;
1056  poly->type = POLYGONTYPE;
1057  poly->flags = g_flags;
1058 
1059  data_ptr += 4; /* Skip past the polygontype. */
1060  nrings = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */
1061  poly->nrings = nrings;
1062  LWDEBUGF(4, "nrings = %d", nrings);
1063  data_ptr += 4; /* Skip past the nrings. */
1064 
1065  ordinate_ptr = data_ptr; /* Start the ordinate pointer. */
1066  if ( nrings > 0)
1067  {
1068  poly->rings = (POINTARRAY**)lwalloc( sizeof(POINTARRAY*) * nrings );
1069  ordinate_ptr += nrings * 4; /* Move past all the npoints values. */
1070  if ( nrings % 2 ) /* If there is padding, move past that too. */
1071  ordinate_ptr += 4;
1072  }
1073  else /* Empty polygon */
1074  {
1075  poly->rings = NULL;
1076  }
1077 
1078  for ( i = 0; i < nrings; i++ )
1079  {
1080  uint32_t npoints = 0;
1081 
1082  /* Read in the number of points. */
1083  npoints = lw_get_uint32_t(data_ptr);
1084  data_ptr += 4;
1085 
1086  /* Make a point array for the ring, and move the ordinate pointer past the ring ordinates. */
1087  poly->rings[i] = ptarray_construct_reference_data(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), npoints, ordinate_ptr);
1088 
1089  ordinate_ptr += sizeof(double) * FLAGS_NDIMS(g_flags) * npoints;
1090  }
1091 
1092  if ( g_size )
1093  *g_size = ordinate_ptr - start_ptr;
1094 
1095  return poly;
1096 }
#define POLYGONTYPE
Definition: liblwgeom.h:62
GBOX * bbox
Definition: liblwgeom.h:409
uint32_t lw_get_uint32_t(const uint8_t *loc)
Definition: lwgeom_api.c:534
uint8_t type
Definition: liblwgeom.h:407
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
POINTARRAY * ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist)
Construct a new POINTARRAY, referencing to the data from ptlist.
Definition: ptarray.c:280
POINTARRAY ** rings
Definition: liblwgeom.h:413
int nrings
Definition: liblwgeom.h:411
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
int32_t srid
Definition: liblwgeom.h:410
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
tuple g_size
Definition: genraster.py:42
uint8_t flags
Definition: liblwgeom.h:408
void * lwalloc(size_t size)
Definition: lwutil.c:175
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:118

Here is the call graph for this function:

Here is the caller graph for this function: