void test_point_geometry_bytes(const PCSCHEMA *s, size_t expectedgeomwkbsize, const char *pthexbytes, const char *expectedgeomhexbytes) { /* point byte: endianness (1 = NDR, 0 = XDR) uint32: pcid (key to POINTCLOUD_SCHEMAS) uchar[]: data (interpret relative to pcid) */ /* geometry byte: endianness (1 = NDR, 0 = XDR) uint32: point type (XYZ=01000080, XYM=01000040, XY=01000000, XYZM=010000C0) double[]: XY(Z?)(M?) coordinates */ PCPOINT *pt; uint8_t *ptwkb, *geomwkb; char *geomhexbytes; size_t pthexsize, geomwkbsize; pthexsize = strlen(pthexbytes); ptwkb = pc_bytes_from_hexbytes(pthexbytes, pthexsize); pt = pc_point_from_wkb(s, ptwkb, pthexsize/2); CU_ASSERT_PTR_NOT_NULL(pt); geomwkb = pc_point_to_geometry_wkb(pt, &geomwkbsize); CU_ASSERT_EQUAL(geomwkbsize,expectedgeomwkbsize); geomhexbytes = pc_hexbytes_from_bytes(geomwkb,geomwkbsize); CU_ASSERT_STRING_EQUAL(geomhexbytes, expectedgeomhexbytes); pcfree(geomhexbytes); pcfree(geomwkb); pc_point_free(pt); pcfree(ptwkb); }
Datum pcpoint_as_bytea(PG_FUNCTION_ARGS) { SERIALIZED_POINT *serpt = PG_GETARG_SERPOINT_P(0); uint8 *bytes; size_t bytes_size; bytea *wkb; size_t wkb_size; PCSCHEMA *schema = pc_schema_from_pcid(serpt->pcid, fcinfo); PCPOINT *pt = pc_point_deserialize(serpt, schema); if ( ! pt ) PG_RETURN_NULL(); bytes = pc_point_to_geometry_wkb(pt, &bytes_size); wkb_size = VARHDRSZ + bytes_size; wkb = palloc(wkb_size); memcpy(VARDATA(wkb), bytes, bytes_size); SET_VARSIZE(wkb, wkb_size); pc_point_free(pt); pfree(bytes); PG_RETURN_BYTEA_P(wkb); }