44 uint8_t gflags = g->
gflags;
68 return 6 *
sizeof(float);
76 return *((uint32_t*)loc);
79 uint8_t
g1flags(
int has_z,
int has_m,
int is_geodetic)
119 return offsetof(
GSERIALIZED,
data) + 8 *
sizeof(float) +
sizeof(uint32_t);
135 ptr = (uint32_t*)(g->
data);
146 srid = srid | (
s->srid[0] << 16);
147 srid = srid | (
s->srid[1] << 8);
148 srid = srid |
s->srid[2];
151 srid = (srid<<11)>>11;
162 LWDEBUGF(3,
"%s called with srid = %d", __func__, srid);
171 s->srid[0] = (srid & 0x001F0000) >> 16;
172 s->srid[1] = (srid & 0x0000FF00) >> 8;
173 s->srid[2] = (srid & 0x000000FF);
183 memcpy(&num, p+4, 4);
188 for ( i = 0; i < num; i++ )
206 uint8_t *p = (uint8_t*)g;
224 void hashlittle2(
const void *key,
size_t length, uint32_t *pc, uint32_t *pb);
230 int32_t pb = 0, pc = 0;
233 uint8_t *b1 = (uint8_t*)g1 + hsz1;
236 size_t bsz1 = sz1 - hsz1;
239 size_t bsz2 = bsz1 +
sizeof(int);
242 memcpy(b2, &srid,
sizeof(
int));
244 memcpy(b2+
sizeof(
int), b1, bsz1);
246 hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
265 float *fbox = (
float*)(g->
data);
266 gbox->
xmin = fbox[i++];
267 gbox->
xmax = fbox[i++];
268 gbox->
ymin = fbox[i++];
269 gbox->
ymax = fbox[i++];
274 gbox->
zmin = fbox[i++];
275 gbox->
zmax = fbox[i++];
281 gbox->
zmin = fbox[i++];
282 gbox->
zmax = fbox[i++];
286 gbox->
mmin = fbox[i++];
287 gbox->
mmax = fbox[i++];
313 double *dptr = (
double*)(g->
data);
316 int32_t *iptr = (int32_t *)(g->
data);
317 int isempty = (iptr[1] == 0);
322 gbox->
xmin = gbox->
xmax = dptr[i++];
323 gbox->
ymin = gbox->
ymax = dptr[i++];
327 gbox->
zmin = gbox->
zmax = dptr[i++];
331 gbox->
mmin = gbox->
mmax = dptr[i++];
341 double *dptr = (
double*)(g->
data);
342 int32_t *iptr = (int32_t *)(g->
data);
343 int npoints = iptr[1];
382 double *dptr = (
double*)(g->
data);
383 int32_t *iptr = (int32_t *)(g->
data);
384 int ngeoms = iptr[1];
405 gbox->
xmin = gbox->
xmax = dptr[i++];
406 gbox->
ymin = gbox->
ymax = dptr[i++];
410 gbox->
zmin = gbox->
zmax = dptr[i++];
414 gbox->
mmin = gbox->
mmax = dptr[i++];
424 double *dptr = (
double*)(g->
data);
425 int32_t *iptr = (int32_t *)(g->
data);
426 int ngeoms = iptr[1];
478 out_point->
x = dptr[dim++];
479 out_point->
y = dptr[dim++];
483 out_point->
z = dptr[dim++];
487 out_point->
m = dptr[dim];
494 uint8_t *geometry_start = ((uint8_t *)g->
data);
500 uint32_t isEmpty = (((uint32_t *)geometry_start)[1]) == 0;
506 uint32_t
type = (((uint32_t *)geometry_start)[0]);
508 double *double_array_start = NULL;
513 double_array_start = (
double *)(geometry_start + 2 *
sizeof(uint32_t));
517 lwerror(
"%s is currently not implemented for type %d", __func__,
type);
597 LWDEBUGF(3,
"point size = %d", size);
611 LWDEBUGF(3,
"linestring size = %d", size);
625 LWDEBUGF(3,
"triangle size = %d", size);
641 for ( i = 0; i < poly->
nrings; i++ )
647 LWDEBUGF(3,
"polygon size = %d", size);
661 LWDEBUGF(3,
"circstring size = %d", size);
675 for ( i = 0; i < col->
ngeoms; i++ )
679 LWDEBUGF(3,
"lwcollection subgeom(%d) size = %d", i, subsize);
682 LWDEBUGF(3,
"lwcollection size = %d", size);
731 LWDEBUGF(3,
"%s size = %d", __func__, size);
754 lwerror(
"Dimensions mismatch in lwpoint");
756 LWDEBUGF(2,
"%s (%p, %p) called", __func__, point, buf);
761 memcpy(loc, &
type,
sizeof(uint32_t));
762 loc +=
sizeof(uint32_t);
764 memcpy(loc, &(point->
point->
npoints),
sizeof(uint32_t));
765 loc +=
sizeof(uint32_t);
774 return (
size_t)(loc - buf);
787 LWDEBUGF(2,
"%s (%p, %p) called", __func__, line, buf);
790 lwerror(
"Dimensions mismatch in lwline");
797 memcpy(loc, &
type,
sizeof(uint32_t));
798 loc +=
sizeof(uint32_t);
802 loc +=
sizeof(uint32_t);
815 return (
size_t)(loc - buf);
834 memcpy(loc, &
type,
sizeof(uint32_t));
835 loc +=
sizeof(uint32_t);
838 memcpy(loc, &(poly->
nrings),
sizeof(uint32_t));
839 loc +=
sizeof(uint32_t);
842 for ( i = 0; i < poly->
nrings; i++ )
844 memcpy(loc, &(poly->
rings[i]->
npoints),
sizeof(uint32_t));
845 loc +=
sizeof(uint32_t);
851 memset(loc, 0,
sizeof(uint32_t));
852 loc +=
sizeof(uint32_t);
856 for ( i = 0; i < poly->
nrings; i++ )
862 lwerror(
"Dimensions mismatch in lwpoly");
869 return (
size_t)(loc - buf);
882 LWDEBUGF(2,
"%s (%p, %p) called", __func__, triangle, buf);
885 lwerror(
"Dimensions mismatch in lwtriangle");
892 memcpy(loc, &
type,
sizeof(uint32_t));
893 loc +=
sizeof(uint32_t);
897 loc +=
sizeof(uint32_t);
908 LWDEBUGF(3,
"%s copied serialized_pointlist (%d bytes)", __func__, ptsize * triangle->
points->
npoints);
910 return (
size_t)(loc - buf);
924 lwerror(
"Dimensions mismatch in lwcircstring");
931 memcpy(loc, &
type,
sizeof(uint32_t));
932 loc +=
sizeof(uint32_t);
936 loc +=
sizeof(uint32_t);
946 return (
size_t)(loc - buf);
963 memcpy(loc, &
type,
sizeof(uint32_t));
964 loc +=
sizeof(uint32_t);
967 memcpy(loc, &coll->
ngeoms,
sizeof(uint32_t));
968 loc +=
sizeof(uint32_t);
971 for ( i=0; i<coll->
ngeoms; i++ )
974 lwerror(
"Dimensions mismatch in lwcollection");
979 return (
size_t)(loc - buf);
987 LWDEBUGF(2,
"Input type (%d) %s, hasz: %d hasm: %d",
990 LWDEBUGF(2,
"LWGEOM(%p) uint8_t(%p)", geom, buf);
1031 memcpy(loc, &f,
sizeof(
float));
1032 loc +=
sizeof(float);
1035 memcpy(loc, &f,
sizeof(
float));
1036 loc +=
sizeof(float);
1039 memcpy(loc, &f,
sizeof(
float));
1040 loc +=
sizeof(float);
1043 memcpy(loc, &f,
sizeof(
float));
1044 loc +=
sizeof(float);
1049 memcpy(loc, &f,
sizeof(
float));
1050 loc +=
sizeof(float);
1053 memcpy(loc, &f,
sizeof(
float));
1054 loc +=
sizeof(float);
1056 return_size = (size_t)(loc - buf);
1057 LWDEBUGF(4,
"returning size %d", return_size);
1064 memcpy(loc, &f,
sizeof(
float));
1065 loc +=
sizeof(float);
1068 memcpy(loc, &f,
sizeof(
float));
1069 loc +=
sizeof(float);
1076 memcpy(loc, &f,
sizeof(
float));
1077 loc +=
sizeof(float);
1080 memcpy(loc, &f,
sizeof(
float));
1081 loc +=
sizeof(float);
1083 return_size = (size_t)(loc - buf);
1084 LWDEBUGF(4,
"returning size %d", return_size);
1092 size_t expected_size = 0;
1093 size_t return_size = 0;
1094 uint8_t *serialized = NULL;
1095 uint8_t *ptr = NULL;
1117 serialized =
lwalloc(expected_size);
1131 return_size = ptr - serialized;
1133 if ( expected_size != return_size )
1135 lwerror(
"Return size (%d) not equal to expected size (%d)!", return_size, expected_size);
1140 *size = return_size;
1148 g->
size = return_size << 2;
1166 uint8_t *start_ptr = data_ptr;
1168 uint32_t npoints = 0;
1190 *size = data_ptr - start_ptr;
1197 uint8_t *start_ptr = data_ptr;
1199 uint32_t npoints = 0;
1222 *size = data_ptr - start_ptr;
1229 uint8_t *start_ptr = data_ptr;
1231 uint8_t *ordinate_ptr;
1232 uint32_t nrings = 0;
1246 LWDEBUGF(4,
"nrings = %d", nrings);
1249 ordinate_ptr = data_ptr;
1254 ordinate_ptr += nrings * 4;
1264 for ( i = 0; i < nrings; i++ )
1266 uint32_t npoints = 0;
1279 *size = ordinate_ptr - start_ptr;
1286 uint8_t *start_ptr = data_ptr;
1288 uint32_t npoints = 0;
1294 triangle->
bbox = NULL;
1310 *size = data_ptr - start_ptr;
1317 uint8_t *start_ptr = data_ptr;
1319 uint32_t npoints = 0;
1325 circstring->
bbox = NULL;
1341 *size = data_ptr - start_ptr;
1349 uint8_t *start_ptr = data_ptr;
1351 uint32_t ngeoms = 0;
1361 collection->
bbox = NULL;
1366 collection->
ngeoms = ngeoms;
1376 collection->
geoms = NULL;
1383 for ( i = 0; i < ngeoms; i++ )
1395 data_ptr += subsize;
1399 *size = data_ptr - start_ptr;
1448 uint32_t lwtype = 0;
1449 uint8_t *data_ptr = NULL;
1462 data_ptr = (uint8_t*)g->
data;
1469 lwerror(
"%s: unable create geometry", __func__);
1471 lwgeom->
type = lwtype;
1484 lwgeom->
bbox = NULL;
1496 if (!g)
return NULL;
1498 return (
const float *)(g->
data);
1515 size_t box_size = 2 * g_ndims *
sizeof(float);
1520 if ( g_ndims != box_ndims )
1540 memcpy(g_out, g, 8);
1552 fbox = (
float*)(g_out->
data);
1554 fbox[fbox_pos++] = gbox->
xmin;
1555 fbox[fbox_pos++] = gbox->
xmax;
1556 fbox[fbox_pos++] = gbox->
ymin;
1557 fbox[fbox_pos++] = gbox->
ymax;
1561 fbox[fbox_pos++] = gbox->
zmin;
1562 fbox[fbox_pos++] = gbox->
zmax;
1566 fbox[fbox_pos++] = gbox->
mmin;
1567 fbox[fbox_pos++] = gbox->
mmax;
1581 size_t box_size = 2 * g_ndims *
sizeof(float);
1588 uint8_t *outptr = (uint8_t*)g_out;
1589 uint8_t *inptr = (uint8_t*)g;
1591 memcpy(outptr, inptr, 8);
1593 inptr += 8 + box_size;
1595 memcpy(outptr, inptr, g_out_size - 8);
1602 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 void gserialized1_copy_point(double *dptr, lwflags_t flags, POINT4D *out_point)
static size_t gserialized1_from_lwgeom_any(const LWGEOM *geom, uint8_t *buf)
int gserialized1_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
uint8_t g1flags(int has_z, int has_m, int is_geodetic)
int gserialized1_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
int32_t gserialized1_hash(const GSERIALIZED *g1)
Returns a hash code for the srid/type/geometry information in the GSERIALIZED.
int gserialized1_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
static LWCIRCSTRING * lwcircstring_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb)
static size_t gserialized1_from_lwtriangle(const LWTRIANGLE *triangle, uint8_t *buf)
static size_t gserialized1_from_lwcollection_size(const LWCOLLECTION *col)
lwflags_t gserialized1_get_lwflags(const GSERIALIZED *g)
Read the flags from a GSERIALIZED and return a standard lwflag integer.
int32_t gserialized1_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
static size_t gserialized1_from_lwpoint_size(const LWPOINT *point)
int gserialized1_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
uint32_t gserialized1_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
static LWPOLY * lwpoly_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
static size_t gserialized1_from_gbox(const GBOX *gbox, uint8_t *buf)
static size_t gserialized1_from_lwtriangle_size(const LWTRIANGLE *triangle)
static LWGEOM * lwgeom_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
int gserialized1_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
int gserialized1_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
GSERIALIZED * gserialized1_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...
uint32_t gserialized1_max_header_size(void)
Returns the size in bytes to read from toast to get the basic information from a geometry: GSERIALIZE...
LWGEOM * lwgeom_from_gserialized1(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized1_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
static size_t gserialized1_from_lwpoint(const LWPOINT *point, uint8_t *buf)
GSERIALIZED * gserialized1_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
const float * gserialized1_get_float_box_p(const GSERIALIZED *g, size_t *ndims)
Point into the float box area of the serialization.
static uint32_t gserialized1_get_uint32_t(const uint8_t *loc)
static uint32_t gserialized1_header_size(const GSERIALIZED *gser)
int gserialized1_peek_first_point(const GSERIALIZED *g, POINT4D *out_point)
int gserialized1_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
static size_t gserialized1_from_lwcircstring(const LWCIRCSTRING *curve, uint8_t *buf)
static size_t gserialized1_from_lwcollection(const LWCOLLECTION *coll, uint8_t *buf)
static size_t gserialized1_from_lwcircstring_size(const LWCIRCSTRING *curve)
static LWLINE * lwline_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
size_t gserialized1_from_lwgeom_size(const LWGEOM *geom)
Return the memory size a GSERIALIZED will occupy for a given LWGEOM.
uint8_t lwflags_get_g1flags(lwflags_t lwflags)
static size_t gserialized1_from_lwline_size(const LWLINE *line)
static size_t gserialized1_box_size(const GSERIALIZED *g)
static size_t gserialized1_from_lwpoly(const LWPOLY *poly, uint8_t *buf)
static size_t gserialized1_is_empty_recurse(const uint8_t *p, int *isempty)
static LWCOLLECTION * lwcollection_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
void gserialized1_set_srid(GSERIALIZED *s, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
static size_t gserialized1_from_lwpoly_size(const LWPOLY *poly)
GSERIALIZED * gserialized1_drop_gbox(GSERIALIZED *g)
Remove the bounding box from a GSERIALIZED.
static size_t gserialized1_from_lwline(const LWLINE *line, uint8_t *buf)
static int gserialized1_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
static size_t gserialized1_from_any_size(const LWGEOM *geom)
static LWTRIANGLE * lwtriangle_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
static LWPOINT * lwpoint_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
int gserialized1_fast_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and fail if it is not already there.
#define G1FLAGS_SET_SOLID(gflags, value)
#define G1FLAGS_SET_Z(gflags, value)
#define G1FLAGS_GET_M(gflags)
#define G1FLAGS_SET_M(gflags, value)
#define G1FLAGS_GET_SOLID(gflags)
#define G1FLAGS_SET_BBOX(gflags, value)
#define G1FLAGS_NDIMS(gflags)
#define G1FLAGS_GET_BBOX(gflags)
#define G1FLAGS_SET_GEODETIC(gflags, value)
#define G1FLAGS_NDIMS_BOX(gflags)
#define G1FLAGS_GET_GEODETIC(gflags)
#define G1FLAGS_GET_Z(gflags)
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 LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
#define FLAGS_GET_BBOX(flags)
#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)