diff --git a/pgsql/pc_inout.c b/pgsql/pc_inout.c index 9eafc480..0b41b656 100644 --- a/pgsql/pc_inout.c +++ b/pgsql/pc_inout.c @@ -13,6 +13,7 @@ /* In/out functions */ Datum pcpoint_in(PG_FUNCTION_ARGS); +Datum pcpoint_in_bytea(PG_FUNCTION_ARGS); Datum pcpoint_out(PG_FUNCTION_ARGS); Datum pcpatch_in(PG_FUNCTION_ARGS); Datum pcpatch_out(PG_FUNCTION_ARGS); @@ -88,6 +89,33 @@ Datum pcpoint_in(PG_FUNCTION_ARGS) else PG_RETURN_NULL(); } + +PG_FUNCTION_INFO_V1(pcpoint_in_bytea); +Datum pcpoint_in_bytea(PG_FUNCTION_ARGS) +{ + bytea *bytes = PG_GETARG_BYTEA_P(0); + size_t wkblen = VARSIZE(bytes) - VARHDRSZ; + uint8 *wkb = VARDATA(bytes); + + SERIALIZED_POINT *serpt = NULL; + + /* non-Hex-encoded binary */ + + PCPOINT *pt; + PCSCHEMA *schema; + uint32 pcid; + pcid = pc_wkb_get_pcid(wkb); + schema = pc_schema_from_pcid(pcid, fcinfo); + pt = pc_point_from_wkb(schema, wkb, wkblen); + + pcid_consistent(pt->schema->pcid, pcid); + serpt = pc_point_serialize(pt); + pc_point_free(pt); + + if ( serpt ) PG_RETURN_POINTER(serpt); + else PG_RETURN_NULL(); +} + PG_FUNCTION_INFO_V1(pcpoint_out); Datum pcpoint_out(PG_FUNCTION_ARGS) { diff --git a/pgsql/pointcloud.sql.in b/pgsql/pointcloud.sql.in index d0a1d788..3c91f5b5 100644 --- a/pgsql/pointcloud.sql.in +++ b/pgsql/pointcloud.sql.in @@ -186,6 +186,10 @@ CREATE OR REPLACE FUNCTION pcpoint_in(cstring) RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in' LANGUAGE 'c' IMMUTABLE STRICT; +CREATE OR REPLACE FUNCTION pcpoint_in(bytea) + RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in_bytea' + LANGUAGE 'c' IMMUTABLE STRICT; + CREATE OR REPLACE FUNCTION pcpoint_out(pcpoint) RETURNS cstring AS 'MODULE_PATHNAME', 'pcpoint_out' LANGUAGE 'c' IMMUTABLE STRICT; @@ -225,6 +229,9 @@ CREATE OR REPLACE FUNCTION PC_AsBinary(p pcpoint) RETURNS bytea AS 'MODULE_PATHNAME', 'pcpoint_as_bytea' LANGUAGE 'c' IMMUTABLE STRICT; +CREATE CAST (bytea as pcpoint) WITH FUNCTION pcpoint_in(bytea) AS ASSIGNMENT; + + ------------------------------------------------------------------- -- PCPATCH -------------------------------------------------------------------