62 uint8_t gflags = g->
gflags;
70 memcpy(&xflags, g->
data,
sizeof(uint64_t));
79 return (
lwflags & (~core_lwflags)) != 0;
86 return 6 *
sizeof(float);
105 static inline uint8_t *
108 uint32_t extra_data_bytes = 0;
110 extra_data_bytes +=
sizeof(uint64_t);
115 return ((uint8_t *)g->
data) + extra_data_bytes;
133 return *((uint32_t*)loc);
136 uint8_t
g2flags(
int has_z,
int has_m,
int is_geodetic)
181 return offsetof(
GSERIALIZED,
data) + 8 *
sizeof(float) +
sizeof(uint64_t) +
sizeof(uint32_t);
188 return *((uint32_t*)(ptr));
194 srid = srid | (g->
srid[0] << 16);
195 srid = srid | (g->
srid[1] << 8);
196 srid = srid | (g->
srid[2]);
199 srid = (srid<<11)>>11;
210 LWDEBUGF(3,
"%s called with srid = %d", __func__, srid);
219 g->
srid[0] = (srid & 0x001F0000) >> 16;
220 g->
srid[1] = (srid & 0x0000FF00) >> 8;
221 g->
srid[2] = (srid & 0x000000FF);
231 memcpy(&num, p+4, 4);
236 for ( i = 0; i < num; i++ )
266 void hashlittle2(
const void *key,
size_t length, uint32_t *pc, uint32_t *pb);
272 int32_t pb = 0, pc = 0;
275 uint8_t *b1 = (uint8_t *)g1 + hsz1;
278 size_t bsz1 = sz1 - hsz1;
281 size_t bsz2 = bsz1 +
sizeof(int);
284 memcpy(b2, &srid,
sizeof(
int));
286 memcpy(b2+
sizeof(
int), b1, bsz1);
288 hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
301 uint8_t *ptr = (uint8_t*)(g->
data);
311 return (
const float *)(ptr);
319 uint8_t gflags = g->
gflags;
329 gbox->
xmin = fbox[i++];
330 gbox->
xmax = fbox[i++];
331 gbox->
ymin = fbox[i++];
332 gbox->
ymax = fbox[i++];
337 gbox->
zmin = fbox[i++];
338 gbox->
zmax = fbox[i++];
344 gbox->
zmin = fbox[i++];
345 gbox->
zmax = fbox[i++];
349 gbox->
mmin = fbox[i++];
350 gbox->
mmax = fbox[i++];
366 double *dptr = (
double *)(geometry_start);
367 int32_t *iptr = (int32_t *)(geometry_start);
381 int isempty = (iptr[1] == 0);
386 gbox->
xmin = gbox->
xmax = dptr[i++];
387 gbox->
ymin = gbox->
ymax = dptr[i++];
391 gbox->
zmin = gbox->
zmax = dptr[i++];
395 gbox->
mmin = gbox->
mmax = dptr[i++];
405 int npoints = iptr[1];
444 int ngeoms = iptr[1];
465 gbox->
xmin = gbox->
xmax = dptr[i++];
466 gbox->
ymin = gbox->
ymax = dptr[i++];
470 gbox->
zmin = gbox->
zmax = dptr[i++];
474 gbox->
mmin = gbox->
mmax = dptr[i++];
484 int ngeoms = iptr[1];
536 out_point->
x = dptr[dim++];
537 out_point->
y = dptr[dim++];
541 out_point->
z = dptr[dim++];
545 out_point->
m = dptr[dim];
554 uint32_t isEmpty = (((uint32_t *)geometry_start)[1]) == 0;
560 uint32_t
type = (((uint32_t *)geometry_start)[0]);
562 double *double_array_start = NULL;
567 double_array_start = (
double *)(geometry_start + 2 *
sizeof(uint32_t));
571 lwerror(
"%s is currently not implemented for type %d", __func__,
type);
651 LWDEBUGF(3,
"point size = %zu", size);
665 LWDEBUGF(3,
"linestring size = %zu", size);
679 LWDEBUGF(3,
"triangle size = %zu", size);
696 for (i = 0; i < poly->
nrings; i++)
702 LWDEBUGF(3,
"polygon size = %zu", size);
716 LWDEBUGF(3,
"circstring size = %zu", size);
730 for (i = 0; i < col->
ngeoms; i++)
734 LWDEBUGF(3,
"lwcollection subgeom(%d) size = %zu", i, subsize);
737 LWDEBUGF(3,
"lwcollection size = %zu", size);
791 LWDEBUGF(3,
"%s size = %zu", __func__, size);
814 lwerror(
"Dimensions mismatch in lwpoint");
816 LWDEBUGF(2,
"%s (%p, %p) called", __func__, point, buf);
821 memcpy(loc, &
type,
sizeof(uint32_t));
822 loc +=
sizeof(uint32_t);
824 memcpy(loc, &(point->
point->
npoints),
sizeof(uint32_t));
825 loc +=
sizeof(uint32_t);
834 return (
size_t)(loc - buf);
847 LWDEBUGF(2,
"%s (%p, %p) called", __func__, line, buf);
850 lwerror(
"Dimensions mismatch in lwline");
857 memcpy(loc, &
type,
sizeof(uint32_t));
858 loc +=
sizeof(uint32_t);
862 loc +=
sizeof(uint32_t);
875 return (
size_t)(loc - buf);
894 memcpy(loc, &
type,
sizeof(uint32_t));
895 loc +=
sizeof(uint32_t);
898 memcpy(loc, &(poly->
nrings),
sizeof(uint32_t));
899 loc +=
sizeof(uint32_t);
902 for (i = 0; i < poly->
nrings; i++)
904 memcpy(loc, &(poly->
rings[i]->
npoints),
sizeof(uint32_t));
905 loc +=
sizeof(uint32_t);
911 memset(loc, 0,
sizeof(uint32_t));
912 loc +=
sizeof(uint32_t);
916 for (i = 0; i < poly->
nrings; i++)
922 lwerror(
"Dimensions mismatch in lwpoly");
924 pasize = (size_t)pa->
npoints * ptsize;
929 return (
size_t)(loc - buf);
942 LWDEBUGF(2,
"%s (%p, %p) called", __func__, triangle, buf);
945 lwerror(
"Dimensions mismatch in lwtriangle");
952 memcpy(loc, &
type,
sizeof(uint32_t));
953 loc +=
sizeof(uint32_t);
957 loc +=
sizeof(uint32_t);
968 LWDEBUGF(3,
"%s copied serialized_pointlist (%d bytes)", __func__, ptsize * triangle->
points->
npoints);
970 return (
size_t)(loc - buf);
984 lwerror(
"Dimensions mismatch in lwcircstring");
991 memcpy(loc, &
type,
sizeof(uint32_t));
992 loc +=
sizeof(uint32_t);
996 loc +=
sizeof(uint32_t);
1006 return (
size_t)(loc - buf);
1023 memcpy(loc, &
type,
sizeof(uint32_t));
1024 loc +=
sizeof(uint32_t);
1027 memcpy(loc, &coll->
ngeoms,
sizeof(uint32_t));
1028 loc +=
sizeof(uint32_t);
1031 for (i = 0; i < coll->
ngeoms; i++)
1034 lwerror(
"Dimensions mismatch in lwcollection");
1039 return (
size_t)(loc - buf);
1047 LWDEBUGF(2,
"Input type (%d) %s, hasz: %d hasm: %d",
1050 LWDEBUGF(2,
"LWGEOM(%p) uint8_t(%p)", geom, buf);
1086 uint64_t xflags = 0;
1094 memcpy(buf, &xflags,
sizeof(uint64_t));
1095 return sizeof(uint64_t);
1114 loc += 4 *
sizeof(float);
1120 loc += 2 *
sizeof(float);
1122 return_size = (size_t)(loc - buf);
1123 LWDEBUGF(4,
"returning size %zu", return_size);
1131 loc += 2 *
sizeof(float);
1138 loc += 2 *
sizeof(float);
1140 return_size = (size_t)(loc - buf);
1141 LWDEBUGF(4,
"returning size %zu", return_size);
1149 size_t expected_size = 0;
1150 size_t return_size = 0;
1151 uint8_t *ptr = NULL;
1196 return_size = ptr - (uint8_t*)g;
1198 assert(expected_size == return_size);
1200 *size = return_size;
1214 uint8_t *start_ptr = data_ptr;
1216 uint32_t npoints = 0;
1238 *size = data_ptr - start_ptr;
1246 uint8_t *start_ptr = data_ptr;
1248 uint32_t npoints = 0;
1271 *size = data_ptr - start_ptr;
1279 uint8_t *start_ptr = data_ptr;
1281 uint8_t *ordinate_ptr;
1282 uint32_t nrings = 0;
1296 LWDEBUGF(4,
"nrings = %d", nrings);
1299 ordinate_ptr = data_ptr;
1304 ordinate_ptr += nrings * 4;
1314 for (i = 0; i < nrings; i++)
1316 uint32_t npoints = 0;
1329 *size = ordinate_ptr - start_ptr;
1337 uint8_t *start_ptr = data_ptr;
1339 uint32_t npoints = 0;
1344 triangle->
srid = srid;
1345 triangle->
bbox = NULL;
1361 *size = data_ptr - start_ptr;
1369 uint8_t *start_ptr = data_ptr;
1371 uint32_t npoints = 0;
1376 circstring->
srid = srid;
1377 circstring->
bbox = NULL;
1393 *size = data_ptr - start_ptr;
1402 uint8_t *start_ptr = data_ptr;
1404 uint32_t ngeoms = 0;
1413 collection->
srid = srid;
1414 collection->
bbox = NULL;
1419 collection->
ngeoms = ngeoms;
1429 collection->
geoms = NULL;
1436 for (i = 0; i < ngeoms; i++)
1448 data_ptr += subsize;
1452 *size = data_ptr - start_ptr;
1502 uint32_t lwtype = 0;
1503 uint8_t *data_ptr = NULL;
1516 data_ptr = (uint8_t*)g->
data;
1521 data_ptr +=
sizeof(uint64_t);
1531 lwerror(
"%s: unable create geometry", __func__);
1533 lwgeom->
type = lwtype;
1546 lwgeom->
bbox = NULL;
1566 size_t box_size = 2 * g_ndims *
sizeof(float);
1571 if (g_ndims != box_ndims)
1588 size_t varsize_out = varsize_in + box_size;
1589 uint8_t *ptr_out, *ptr_in, *ptr;
1591 ptr_out = (uint8_t*)g_out;
1592 ptr = ptr_in = (uint8_t*)g;
1594 memcpy(ptr_out, ptr_in, 8); ptr_out += 8; ptr_in += 8;
1598 memcpy(ptr_out, ptr_in, 8); ptr_out += 8; ptr_in += 8;
1601 ptr_out += box_size;
1602 memcpy(ptr_out, ptr_in, varsize_in - (ptr_in - ptr));
1610 fbox = (
float*)(g_out->
data);
1612 fbox[fbox_pos++] = gbox->
xmin;
1613 fbox[fbox_pos++] = gbox->
xmax;
1614 fbox[fbox_pos++] = gbox->
ymin;
1615 fbox[fbox_pos++] = gbox->
ymax;
1619 fbox[fbox_pos++] = gbox->
zmin;
1620 fbox[fbox_pos++] = gbox->
zmax;
1624 fbox[fbox_pos++] = gbox->
mmin;
1625 fbox[fbox_pos++] = gbox->
mmax;
1639 size_t box_size = 2 * g_ndims *
sizeof(float);
1646 uint8_t *outptr = (uint8_t*)g_out;
1647 uint8_t *inptr = (uint8_t*)g;
1649 memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1653 memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1658 memcpy(outptr, inptr, g_out_size - 8);
1665 memcpy(g_out, g, g_out_size);
size_t gbox_serialized_size(lwflags_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form.
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
static size_t gserialized2_header_size(const GSERIALIZED *g)
static size_t gserialized2_box_size(const GSERIALIZED *g)
static int gserialized2_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
int gserialized2_fast_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and fail if it is not already there.
int32_t gserialized2_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
int gserialized2_is_geodetic(const GSERIALIZED *g)
Check if a GSERIALIZED is a geography.
void gserialized2_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
int gserialized2_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb)
static uint32_t gserialized2_get_uint32_t(const uint8_t *loc)
int32_t gserialized2_hash(const GSERIALIZED *g1)
Returns a hash code for the srid/type/geometry information in the GSERIALIZED.
const float * gserialized2_get_float_box_p(const GSERIALIZED *g, size_t *ndims)
Point into the float box area of the serialization.
static size_t gserialized2_from_gbox(const GBOX *gbox, uint8_t *buf)
static size_t gserialized2_from_lwcircstring_size(const LWCIRCSTRING *curve)
static size_t gserialized2_from_lwpoly_size(const LWPOLY *poly)
uint32_t gserialized2_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
int gserialized2_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized2_peek_first_point(const GSERIALIZED *g, POINT4D *out_point)
static LWGEOM * lwgeom_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
static int lwflags_uses_extended_flags(lwflags_t lwflags)
int gserialized2_ndims(const GSERIALIZED *g)
Return the number of dimensions (2, 3, 4) in a geometry.
LWGEOM * lwgeom_from_gserialized2(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized2_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
uint8_t lwflags_get_g2flags(lwflags_t lwflags)
static LWTRIANGLE * lwtriangle_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
static size_t gserialized2_from_lwcollection(const LWCOLLECTION *coll, uint8_t *buf)
static size_t gserialized2_from_lwgeom_any(const LWGEOM *geom, uint8_t *buf)
int gserialized2_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
static size_t gserialized2_from_lwcircstring(const LWCIRCSTRING *curve, uint8_t *buf)
static LWCIRCSTRING * lwcircstring_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
static size_t gserialized2_is_empty_recurse(const uint8_t *p, int *isempty)
static size_t gserialized2_from_lwpoint_size(const LWPOINT *point)
size_t gserialized2_from_lwgeom_size(const LWGEOM *geom)
Return the memory size a GSERIALIZED will occupy for a given LWGEOM.
static size_t gserialized2_from_lwtriangle_size(const LWTRIANGLE *triangle)
static size_t gserialized2_from_lwpoly(const LWPOLY *poly, uint8_t *buf)
static size_t gserialized2_from_lwtriangle(const LWTRIANGLE *triangle, uint8_t *buf)
static uint8_t * gserialized2_get_geometry_p(const GSERIALIZED *g)
static size_t gserialized2_from_lwcollection_size(const LWCOLLECTION *col)
static size_t gserialized2_from_lwline(const LWLINE *line, uint8_t *buf)
int gserialized2_has_extended(const GSERIALIZED *g)
Check if a GSERIALIZED has an extended flags section.
static size_t gserialized2_from_lwpoint(const LWPOINT *point, uint8_t *buf)
GSERIALIZED * gserialized2_set_gbox(GSERIALIZED *g, GBOX *gbox)
Update the bounding box of a GSERIALIZED, allocating a fresh one if there is not enough space to just...
static void gserialized2_copy_point(double *dptr, lwflags_t flags, POINT4D *out_point)
static LWLINE * lwline_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
int gserialized2_has_m(const GSERIALIZED *g)
Check if a GSERIALIZED has an M ordinate.
GSERIALIZED * gserialized2_drop_gbox(GSERIALIZED *g)
Remove the bounding box from a GSERIALIZED.
GSERIALIZED * gserialized2_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
static LWPOINT * lwpoint_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
uint32_t gserialized2_max_header_size(void)
Returns the size in bytes to read from toast to get the basic information from a geometry: GSERIALIZE...
static LWPOLY * lwpoly_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
static size_t gserialized2_from_extended_flags(lwflags_t lwflags, uint8_t *buf)
static size_t gserialized2_from_any_size(const LWGEOM *geom)
lwflags_t gserialized2_get_lwflags(const GSERIALIZED *g)
Read the flags from a GSERIALIZED and return a standard lwflag integer.
uint8_t g2flags(int has_z, int has_m, int is_geodetic)
static size_t gserialized2_from_lwline_size(const LWLINE *line)
int gserialized2_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
static LWCOLLECTION * lwcollection_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
#define G2FLAGS_SET_Z(gflags, value)
#define G2FLAGS_SET_EXTENDED(gflags, value)
#define G2FLAGS_SET_VERSION(gflags, value)
#define G2FLAGS_NDIMS_BOX(gflags)
#define G2FLAGS_GET_BBOX(gflags)
#define G2FLAG_X_SOLID
Macros for the extended 'flags' uint64_t.
#define G2FLAGS_SET_M(gflags, value)
#define G2FLAGS_GET_GEODETIC(gflags)
#define G2FLAGS_GET_Z(gflags)
#define G2FLAGS_GET_EXTENDED(gflags)
#define G2FLAGS_SET_GEODETIC(gflags, value)
#define G2FLAGS_GET_M(gflags)
#define G2FLAGS_SET_BBOX(gflags, value)
#define G2FLAGS_NDIMS(gflags)
int gserialized_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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.
void lwgeom_free(LWGEOM *geom)
#define FLAGS_NDIMS_BOX(flags)
#define LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
#define FLAGS_GET_BBOX(flags)
#define LWFLAG_Z
Macros for manipulating the 'flags' byte.
#define FLAGS_SET_BBOX(flags, value)
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
#define FLAGS_NDIMS(flags)
#define POLYHEDRALSURFACETYPE
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define FLAGS_GET_M(flags)
#define FLAGS_GET_SOLID(flags)
#define FLAGS_GET_ZM(flags)
#define LWSIZE_SET(varsize, len)
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
#define FLAGS_SET_GEODETIC(flags, value)
void * lwalloc(size_t size)
float next_float_up(double d)
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
#define LW_TRUE
Return types for functions with status returns.
#define FLAGS_SET_M(flags, value)
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_SET_Z(flags, value)
#define FLAGS_SET_SOLID(flags, value)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
float next_float_down(double d)
#define FLAGS_GET_GEODETIC(flags)
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...
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
#define LWDEBUGF(level, msg,...)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static size_t ptarray_point_size(const POINTARRAY *pa)
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)