Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying bytea->pcpoint conversion #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pgsql/pc_inout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions pgsql/pointcloud.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't name this function pcpoint_in. pcpoint_in and pcpoint_out are the pcpoint type's input and output functions, respectively. So I'd rather not add a pcpoint_in function that doesn't participate to the type definition.

So I suggest that we name this function PC_PointFromWKB, which is consistent with PostGIS' ST_GeomFromWKB function.

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;
Expand Down Expand Up @@ -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
-------------------------------------------------------------------
Expand Down