60 uint8_t gflags = g->
gflags;
68 memcpy(&xflags, g->
data,
sizeof(uint64_t));
77 return (
lwflags & (~core_lwflags)) != 0;
84 return 6 *
sizeof(float);
103 static inline uint8_t *
106 uint32_t extra_data_bytes = 0;
108 extra_data_bytes +=
sizeof(uint64_t);
113 return ((uint8_t *)g->
data) + extra_data_bytes;
131 return *((uint32_t*)loc);
134 uint8_t
g2flags(
int has_z,
int has_m,
int is_geodetic)
178 static const intptr_t size_of_gserialized_up_to_data = (intptr_t) & ((
GSERIALIZED *)NULL)->
data;
180 return size_of_gserialized_up_to_data + 8 *
sizeof(float) +
sizeof(uint64_t) +
sizeof(uint32_t);
187 return *((uint32_t*)(ptr));
193 srid = srid | (g->
srid[0] << 16);
194 srid = srid | (g->
srid[1] << 8);
195 srid = srid | (g->
srid[2]);
198 srid = (srid<<11)>>11;
209 LWDEBUGF(3,
"%s called with srid = %d", __func__, srid);
218 g->
srid[0] = (srid & 0x001F0000) >> 16;
219 g->
srid[1] = (srid & 0x0000FF00) >> 8;
220 g->
srid[2] = (srid & 0x000000FF);
230 memcpy(&num, p+4, 4);
235 for ( i = 0; i < num; i++ )
265 void hashlittle2(
const void *key,
size_t length, uint32_t *pc, uint32_t *pb);
271 int32_t pb = 0, pc = 0;
274 uint8_t *b1 = (uint8_t *)g1 + hsz1;
277 size_t bsz1 = sz1 - hsz1;
280 size_t bsz2 = bsz1 +
sizeof(int);
283 memcpy(b2, &srid,
sizeof(
int));
285 memcpy(b2+
sizeof(
int), b1, bsz1);
287 hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
296 uint8_t *ptr = (uint8_t*)(g->
data);
310 return (
const float *)(ptr);
315 uint8_t gflags = g->
gflags;
327 gbox->
xmin = fbox[i++];
328 gbox->
xmax = fbox[i++];
329 gbox->
ymin = fbox[i++];
330 gbox->
ymax = fbox[i++];
335 gbox->
zmin = fbox[i++];
336 gbox->
zmax = fbox[i++];
342 gbox->
zmin = fbox[i++];
343 gbox->
zmax = fbox[i++];
347 gbox->
mmin = fbox[i++];
348 gbox->
mmax = fbox[i++];
364 double *dptr = (
double *)(geometry_start);
365 int32_t *iptr = (int32_t *)(geometry_start);
379 int isempty = (iptr[1] == 0);
384 gbox->
xmin = gbox->
xmax = dptr[i++];
385 gbox->
ymin = gbox->
ymax = dptr[i++];
389 gbox->
zmin = gbox->
zmax = dptr[i++];
393 gbox->
mmin = gbox->
mmax = dptr[i++];
403 int npoints = iptr[1];
442 int ngeoms = iptr[1];
463 gbox->
xmin = gbox->
xmax = dptr[i++];
464 gbox->
ymin = gbox->
ymax = dptr[i++];
468 gbox->
zmin = gbox->
zmax = dptr[i++];
472 gbox->
mmin = gbox->
mmax = dptr[i++];
482 int ngeoms = iptr[1];
534 out_point->
x = dptr[dim++];
535 out_point->
y = dptr[dim++];
539 out_point->
z = dptr[dim++];
543 out_point->
m = dptr[dim];
552 uint32_t isEmpty = (((uint32_t *)geometry_start)[1]) == 0;
558 uint32_t
type = (((uint32_t *)geometry_start)[0]);
560 double *double_array_start = NULL;
565 double_array_start = (
double *)(geometry_start + 2 *
sizeof(uint32_t));
569 lwerror(
"%s is currently not implemented for type %d", __func__,
type);
649 LWDEBUGF(3,
"point size = %d", size);
663 LWDEBUGF(3,
"linestring size = %d", size);
677 LWDEBUGF(3,
"triangle size = %d", size);
693 for (i = 0; i < poly->
nrings; i++)
699 LWDEBUGF(3,
"polygon size = %d", size);
713 LWDEBUGF(3,
"circstring size = %d", size);
727 for (i = 0; i < col->
ngeoms; i++)
731 LWDEBUGF(3,
"lwcollection subgeom(%d) size = %d", i, subsize);
734 LWDEBUGF(3,
"lwcollection size = %d", size);
788 LWDEBUGF(3,
"%s size = %d", __func__, size);
811 lwerror(
"Dimensions mismatch in lwpoint");
813 LWDEBUGF(2,
"%s (%p, %p) called", __func__, point, buf);
818 memcpy(loc, &
type,
sizeof(uint32_t));
819 loc +=
sizeof(uint32_t);
821 memcpy(loc, &(point->
point->
npoints),
sizeof(uint32_t));
822 loc +=
sizeof(uint32_t);
831 return (
size_t)(loc - buf);
844 LWDEBUGF(2,
"%s (%p, %p) called", __func__, line, buf);
847 lwerror(
"Dimensions mismatch in lwline");
854 memcpy(loc, &
type,
sizeof(uint32_t));
855 loc +=
sizeof(uint32_t);
859 loc +=
sizeof(uint32_t);
872 return (
size_t)(loc - buf);
891 memcpy(loc, &
type,
sizeof(uint32_t));
892 loc +=
sizeof(uint32_t);
895 memcpy(loc, &(poly->
nrings),
sizeof(uint32_t));
896 loc +=
sizeof(uint32_t);
899 for (i = 0; i < poly->
nrings; i++)
901 memcpy(loc, &(poly->
rings[i]->
npoints),
sizeof(uint32_t));
902 loc +=
sizeof(uint32_t);
908 memset(loc, 0,
sizeof(uint32_t));
909 loc +=
sizeof(uint32_t);
913 for (i = 0; i < poly->
nrings; i++)
919 lwerror(
"Dimensions mismatch in lwpoly");
926 return (
size_t)(loc - buf);
939 LWDEBUGF(2,
"%s (%p, %p) called", __func__, triangle, buf);
942 lwerror(
"Dimensions mismatch in lwtriangle");
949 memcpy(loc, &
type,
sizeof(uint32_t));
950 loc +=
sizeof(uint32_t);
954 loc +=
sizeof(uint32_t);
965 LWDEBUGF(3,
"%s copied serialized_pointlist (%d bytes)", __func__, ptsize * triangle->
points->
npoints);
967 return (
size_t)(loc - buf);
981 lwerror(
"Dimensions mismatch in lwcircstring");
988 memcpy(loc, &
type,
sizeof(uint32_t));
989 loc +=
sizeof(uint32_t);
993 loc +=
sizeof(uint32_t);
1003 return (
size_t)(loc - buf);
1020 memcpy(loc, &
type,
sizeof(uint32_t));
1021 loc +=
sizeof(uint32_t);
1024 memcpy(loc, &coll->
ngeoms,
sizeof(uint32_t));
1025 loc +=
sizeof(uint32_t);
1028 for (i = 0; i < coll->
ngeoms; i++)
1031 lwerror(
"Dimensions mismatch in lwcollection");
1036 return (
size_t)(loc - buf);
1044 LWDEBUGF(2,
"Input type (%d) %s, hasz: %d hasm: %d",
1047 LWDEBUGF(2,
"LWGEOM(%p) uint8_t(%p)", geom, buf);
1083 uint64_t xflags = 0;
1091 memcpy(buf, &xflags,
sizeof(uint64_t));
1092 return sizeof(uint64_t);
1106 memcpy(loc, &f,
sizeof(
float));
1107 loc +=
sizeof(float);
1110 memcpy(loc, &f,
sizeof(
float));
1111 loc +=
sizeof(float);
1114 memcpy(loc, &f,
sizeof(
float));
1115 loc +=
sizeof(float);
1118 memcpy(loc, &f,
sizeof(
float));
1119 loc +=
sizeof(float);
1124 memcpy(loc, &f,
sizeof(
float));
1125 loc +=
sizeof(float);
1128 memcpy(loc, &f,
sizeof(
float));
1129 loc +=
sizeof(float);
1131 return_size = (size_t)(loc - buf);
1132 LWDEBUGF(4,
"returning size %d", return_size);
1139 memcpy(loc, &f,
sizeof(
float));
1140 loc +=
sizeof(float);
1143 memcpy(loc, &f,
sizeof(
float));
1144 loc +=
sizeof(float);
1151 memcpy(loc, &f,
sizeof(
float));
1152 loc +=
sizeof(float);
1155 memcpy(loc, &f,
sizeof(
float));
1156 loc +=
sizeof(float);
1158 return_size = (size_t)(loc - buf);
1159 LWDEBUGF(4,
"returning size %d", return_size);
1167 size_t expected_size = 0;
1168 size_t return_size = 0;
1169 uint8_t *ptr = NULL;
1214 return_size = ptr - (uint8_t*)g;
1216 if (expected_size != return_size)
1218 lwerror(
"Return size (%lu) not equal to expected size (%lu)!", return_size, expected_size);
1223 *size = return_size;
1238 uint8_t *start_ptr = data_ptr;
1240 uint32_t npoints = 0;
1262 *size = data_ptr - start_ptr;
1269 uint8_t *start_ptr = data_ptr;
1271 uint32_t npoints = 0;
1294 *size = data_ptr - start_ptr;
1301 uint8_t *start_ptr = data_ptr;
1303 uint8_t *ordinate_ptr;
1304 uint32_t nrings = 0;
1318 LWDEBUGF(4,
"nrings = %d", nrings);
1321 ordinate_ptr = data_ptr;
1326 ordinate_ptr += nrings * 4;
1336 for (i = 0; i < nrings; i++)
1338 uint32_t npoints = 0;
1351 *size = ordinate_ptr - start_ptr;
1358 uint8_t *start_ptr = data_ptr;
1360 uint32_t npoints = 0;
1366 triangle->
bbox = NULL;
1382 *size = data_ptr - start_ptr;
1389 uint8_t *start_ptr = data_ptr;
1391 uint32_t npoints = 0;
1397 circstring->
bbox = NULL;
1413 *size = data_ptr - start_ptr;
1421 uint8_t *start_ptr = data_ptr;
1423 uint32_t ngeoms = 0;
1433 collection->
bbox = NULL;
1438 collection->
ngeoms = ngeoms;
1448 collection->
geoms = NULL;
1455 for (i = 0; i < ngeoms; i++)
1467 data_ptr += subsize;
1471 *size = data_ptr - start_ptr;
1520 uint32_t lwtype = 0;
1521 uint8_t *data_ptr = NULL;
1534 data_ptr = (uint8_t*)g->
data;
1539 data_ptr +=
sizeof(uint64_t);
1549 lwerror(
"%s: unable create geometry", __func__);
1551 lwgeom->
type = lwtype;
1564 lwgeom->
bbox = NULL;
1586 size_t box_size = 2 * g_ndims *
sizeof(float);
1591 if (g_ndims != box_ndims)
1608 size_t varsize_out = varsize_in + box_size;
1609 uint8_t *ptr_out, *ptr_in, *ptr;
1611 ptr_out = (uint8_t*)g_out;
1612 ptr = ptr_in = (uint8_t*)g;
1614 memcpy(ptr_out, ptr_in, 8); ptr_out += 8; ptr_in += 8;
1618 memcpy(ptr_out, ptr_in, 8); ptr_out += 8; ptr_in += 8;
1621 ptr_out += box_size;
1622 memcpy(ptr_out, ptr_in, varsize_in - (ptr_in - ptr));
1630 fbox = (
float*)(g_out->
data);
1632 fbox[fbox_pos++] = gbox->
xmin;
1633 fbox[fbox_pos++] = gbox->
xmax;
1634 fbox[fbox_pos++] = gbox->
ymin;
1635 fbox[fbox_pos++] = gbox->
ymax;
1639 fbox[fbox_pos++] = gbox->
zmin;
1640 fbox[fbox_pos++] = gbox->
zmax;
1644 fbox[fbox_pos++] = gbox->
mmin;
1645 fbox[fbox_pos++] = gbox->
mmax;
1659 size_t box_size = 2 * g_ndims *
sizeof(float);
1666 uint8_t *outptr = (uint8_t*)g_out;
1667 uint8_t *inptr = (uint8_t*)g;
1669 memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1673 memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1678 memcpy(outptr, inptr, g_out_size - 8);
1685 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 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 LWCIRCSTRING * lwcircstring_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
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 LWPOLY * lwpoly_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
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 LWGEOM * lwgeom_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
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 LWTRIANGLE * lwtriangle_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
static size_t gserialized2_from_lwcollection_size(const LWCOLLECTION *col)
static size_t gserialized2_from_lwline(const LWLINE *line, uint8_t *buf)
static LWCOLLECTION * lwcollection_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
int gserialized2_has_extended(const GSERIALIZED *g)
Check if a GSERIALIZED has an extended flags section.
static LWPOINT * lwpoint_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
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)
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.
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 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 LWLINE * lwline_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
#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_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
void lwgeom_free(LWGEOM *geom)
#define FLAGS_NDIMS_BOX(flags)
#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)
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...
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
#define SIZE_SET(varsize, len)
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
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)