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);
297 uint8_t *ptr = (uint8_t*)(g->
data);
311 return (
const float *)(ptr);
316 uint8_t gflags = g->
gflags;
328 gbox->
xmin = fbox[i++];
329 gbox->
xmax = fbox[i++];
330 gbox->
ymin = fbox[i++];
331 gbox->
ymax = fbox[i++];
336 gbox->
zmin = fbox[i++];
337 gbox->
zmax = fbox[i++];
343 gbox->
zmin = fbox[i++];
344 gbox->
zmax = fbox[i++];
348 gbox->
mmin = fbox[i++];
349 gbox->
mmax = fbox[i++];
365 double *dptr = (
double *)(geometry_start);
366 int32_t *iptr = (int32_t *)(geometry_start);
380 int isempty = (iptr[1] == 0);
385 gbox->
xmin = gbox->
xmax = dptr[i++];
386 gbox->
ymin = gbox->
ymax = dptr[i++];
390 gbox->
zmin = gbox->
zmax = dptr[i++];
394 gbox->
mmin = gbox->
mmax = dptr[i++];
404 int npoints = iptr[1];
443 int ngeoms = iptr[1];
464 gbox->
xmin = gbox->
xmax = dptr[i++];
465 gbox->
ymin = gbox->
ymax = dptr[i++];
469 gbox->
zmin = gbox->
zmax = dptr[i++];
473 gbox->
mmin = gbox->
mmax = dptr[i++];
483 int ngeoms = iptr[1];
535 out_point->
x = dptr[dim++];
536 out_point->
y = dptr[dim++];
540 out_point->
z = dptr[dim++];
544 out_point->
m = dptr[dim];
553 uint32_t isEmpty = (((uint32_t *)geometry_start)[1]) == 0;
559 uint32_t
type = (((uint32_t *)geometry_start)[0]);
561 double *double_array_start = NULL;
566 double_array_start = (
double *)(geometry_start + 2 *
sizeof(uint32_t));
570 lwerror(
"%s is currently not implemented for type %d", __func__,
type);
650 LWDEBUGF(3,
"point size = %d", size);
664 LWDEBUGF(3,
"linestring size = %d", size);
678 LWDEBUGF(3,
"triangle size = %d", size);
695 for (i = 0; i < poly->
nrings; i++)
701 LWDEBUGF(3,
"polygon size = %d", size);
715 LWDEBUGF(3,
"circstring size = %d", size);
729 for (i = 0; i < col->
ngeoms; i++)
733 LWDEBUGF(3,
"lwcollection subgeom(%d) size = %d", i, subsize);
736 LWDEBUGF(3,
"lwcollection size = %d", size);
790 LWDEBUGF(3,
"%s size = %d", __func__, size);
813 lwerror(
"Dimensions mismatch in lwpoint");
815 LWDEBUGF(2,
"%s (%p, %p) called", __func__, point, buf);
820 memcpy(loc, &
type,
sizeof(uint32_t));
821 loc +=
sizeof(uint32_t);
823 memcpy(loc, &(point->
point->
npoints),
sizeof(uint32_t));
824 loc +=
sizeof(uint32_t);
833 return (
size_t)(loc - buf);
846 LWDEBUGF(2,
"%s (%p, %p) called", __func__, line, buf);
849 lwerror(
"Dimensions mismatch in lwline");
856 memcpy(loc, &
type,
sizeof(uint32_t));
857 loc +=
sizeof(uint32_t);
861 loc +=
sizeof(uint32_t);
874 return (
size_t)(loc - buf);
893 memcpy(loc, &
type,
sizeof(uint32_t));
894 loc +=
sizeof(uint32_t);
897 memcpy(loc, &(poly->
nrings),
sizeof(uint32_t));
898 loc +=
sizeof(uint32_t);
901 for (i = 0; i < poly->
nrings; i++)
903 memcpy(loc, &(poly->
rings[i]->
npoints),
sizeof(uint32_t));
904 loc +=
sizeof(uint32_t);
910 memset(loc, 0,
sizeof(uint32_t));
911 loc +=
sizeof(uint32_t);
915 for (i = 0; i < poly->
nrings; i++)
921 lwerror(
"Dimensions mismatch in lwpoly");
928 return (
size_t)(loc - buf);
941 LWDEBUGF(2,
"%s (%p, %p) called", __func__, triangle, buf);
944 lwerror(
"Dimensions mismatch in lwtriangle");
951 memcpy(loc, &
type,
sizeof(uint32_t));
952 loc +=
sizeof(uint32_t);
956 loc +=
sizeof(uint32_t);
967 LWDEBUGF(3,
"%s copied serialized_pointlist (%d bytes)", __func__, ptsize * triangle->
points->
npoints);
969 return (
size_t)(loc - buf);
983 lwerror(
"Dimensions mismatch in lwcircstring");
990 memcpy(loc, &
type,
sizeof(uint32_t));
991 loc +=
sizeof(uint32_t);
995 loc +=
sizeof(uint32_t);
1005 return (
size_t)(loc - buf);
1022 memcpy(loc, &
type,
sizeof(uint32_t));
1023 loc +=
sizeof(uint32_t);
1026 memcpy(loc, &coll->
ngeoms,
sizeof(uint32_t));
1027 loc +=
sizeof(uint32_t);
1030 for (i = 0; i < coll->
ngeoms; i++)
1033 lwerror(
"Dimensions mismatch in lwcollection");
1038 return (
size_t)(loc - buf);
1046 LWDEBUGF(2,
"Input type (%d) %s, hasz: %d hasm: %d",
1049 LWDEBUGF(2,
"LWGEOM(%p) uint8_t(%p)", geom, buf);
1085 uint64_t xflags = 0;
1093 memcpy(buf, &xflags,
sizeof(uint64_t));
1094 return sizeof(uint64_t);
1113 loc += 4 *
sizeof(float);
1119 loc += 2 *
sizeof(float);
1121 return_size = (size_t)(loc - buf);
1122 LWDEBUGF(4,
"returning size %d", return_size);
1130 loc += 2 *
sizeof(float);
1137 loc += 2 *
sizeof(float);
1139 return_size = (size_t)(loc - buf);
1140 LWDEBUGF(4,
"returning size %d", return_size);
1148 size_t expected_size = 0;
1149 size_t return_size = 0;
1150 uint8_t *ptr = NULL;
1195 return_size = ptr - (uint8_t*)g;
1197 assert(expected_size == return_size);
1199 *size = return_size;
1213 uint8_t *start_ptr = data_ptr;
1215 uint32_t npoints = 0;
1237 *size = data_ptr - start_ptr;
1245 uint8_t *start_ptr = data_ptr;
1247 uint32_t npoints = 0;
1270 *size = data_ptr - start_ptr;
1278 uint8_t *start_ptr = data_ptr;
1280 uint8_t *ordinate_ptr;
1281 uint32_t nrings = 0;
1295 LWDEBUGF(4,
"nrings = %d", nrings);
1298 ordinate_ptr = data_ptr;
1303 ordinate_ptr += nrings * 4;
1313 for (i = 0; i < nrings; i++)
1315 uint32_t npoints = 0;
1328 *size = ordinate_ptr - start_ptr;
1336 uint8_t *start_ptr = data_ptr;
1338 uint32_t npoints = 0;
1343 triangle->
srid = srid;
1344 triangle->
bbox = NULL;
1360 *size = data_ptr - start_ptr;
1368 uint8_t *start_ptr = data_ptr;
1370 uint32_t npoints = 0;
1375 circstring->
srid = srid;
1376 circstring->
bbox = NULL;
1392 *size = data_ptr - start_ptr;
1401 uint8_t *start_ptr = data_ptr;
1403 uint32_t ngeoms = 0;
1412 collection->
srid = srid;
1413 collection->
bbox = NULL;
1418 collection->
ngeoms = ngeoms;
1428 collection->
geoms = NULL;
1435 for (i = 0; i < ngeoms; i++)
1447 data_ptr += subsize;
1451 *size = data_ptr - start_ptr;
1501 uint32_t lwtype = 0;
1502 uint8_t *data_ptr = NULL;
1515 data_ptr = (uint8_t*)g->
data;
1520 data_ptr +=
sizeof(uint64_t);
1530 lwerror(
"%s: unable create geometry", __func__);
1532 lwgeom->
type = lwtype;
1545 lwgeom->
bbox = NULL;
1565 size_t box_size = 2 * g_ndims *
sizeof(float);
1570 if (g_ndims != box_ndims)
1587 size_t varsize_out = varsize_in + box_size;
1588 uint8_t *ptr_out, *ptr_in, *ptr;
1590 ptr_out = (uint8_t*)g_out;
1591 ptr = ptr_in = (uint8_t*)g;
1593 memcpy(ptr_out, ptr_in, 8); ptr_out += 8; ptr_in += 8;
1597 memcpy(ptr_out, ptr_in, 8); ptr_out += 8; ptr_in += 8;
1600 ptr_out += box_size;
1601 memcpy(ptr_out, ptr_in, varsize_in - (ptr_in - ptr));
1609 fbox = (
float*)(g_out->
data);
1611 fbox[fbox_pos++] = gbox->
xmin;
1612 fbox[fbox_pos++] = gbox->
xmax;
1613 fbox[fbox_pos++] = gbox->
ymin;
1614 fbox[fbox_pos++] = gbox->
ymax;
1618 fbox[fbox_pos++] = gbox->
zmin;
1619 fbox[fbox_pos++] = gbox->
zmax;
1623 fbox[fbox_pos++] = gbox->
mmin;
1624 fbox[fbox_pos++] = gbox->
mmax;
1638 size_t box_size = 2 * g_ndims *
sizeof(float);
1645 uint8_t *outptr = (uint8_t*)g_out;
1646 uint8_t *inptr = (uint8_t*)g;
1648 memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1652 memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1657 memcpy(outptr, inptr, g_out_size - 8);
1664 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 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)