From f4b6a31db318ce14b930dd2091801e802c6bb60a Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 30 Jan 2013 14:08:04 -0800 Subject: [PATCH] Fix astext output for point --- libpc/pc_point.c | 1 + libpc/stringbuffer.c | 4 +- pgsql/.gitignore | 1 + pgsql/expected/pointcloud.out | 8 ++++ pgsql/pc_pgsql.c | 4 +- pgsql/results/pointcloud.out | 70 ----------------------------------- pgsql/sql/pointcloud.sql | 2 + 7 files changed, 16 insertions(+), 74 deletions(-) create mode 100644 pgsql/.gitignore delete mode 100644 pgsql/results/pointcloud.out diff --git a/libpc/pc_point.c b/libpc/pc_point.c index ab61b6d..0f9088f 100644 --- a/libpc/pc_point.c +++ b/libpc/pc_point.c @@ -176,6 +176,7 @@ pc_point_to_string(const PCPOINT *pt) } stringbuffer_aprintf(sb, "%g", pc_point_get_double_by_index(pt, i)); } + stringbuffer_append(sb, " )"); str = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return str; diff --git a/libpc/stringbuffer.c b/libpc/stringbuffer.c index 52ae0f0..dc2a977 100644 --- a/libpc/stringbuffer.c +++ b/libpc/stringbuffer.c @@ -152,8 +152,8 @@ stringbuffer_getstringcopy(stringbuffer_t *s) { size_t size = (s->str_end - s->str_start) + 1; char *str = malloc(size); - memcpy(str, s->str_start, size); - str[size - 1] = '\0'; + memcpy(str, s->str_start, size-1); + str[size-1] = '\0'; return str; } diff --git a/pgsql/.gitignore b/pgsql/.gitignore new file mode 100644 index 0000000..12363aa --- /dev/null +++ b/pgsql/.gitignore @@ -0,0 +1 @@ +regression.* diff --git a/pgsql/expected/pointcloud.out b/pgsql/expected/pointcloud.out index 031cfd8..c85ab51 100644 --- a/pgsql/expected/pointcloud.out +++ b/pgsql/expected/pointcloud.out @@ -67,4 +67,12 @@ SELECT Sum(PC_Get(pt, 'y')) FROM pt_test; 0.09 (1 row) +SELECT PC_AsText(pt) FROM pt_test; + pc_astext +----------------------------- + ( 1 : 0.01, 0.02, 0.03, 4 ) + ( 1 : 0.02, 0.03, 0.03, 5 ) + ( 1 : 0.03, 0.04, 0.03, 6 ) +(3 rows) + DROP TABLE pt_test; diff --git a/pgsql/pc_pgsql.c b/pgsql/pc_pgsql.c index 523943e..67d93ef 100644 --- a/pgsql/pc_pgsql.c +++ b/pgsql/pc_pgsql.c @@ -284,8 +284,8 @@ pc_patch_serialize(const PCPATCH *pcpch) /* Compress uncompressed patches before saving */ patch = pc_patch_compress(pcpch); - /* Allocate */ - serpch_size = sizeof(SERIALIZED_PATCH) - 1 + patch->datasize; + /* Allocate: size(int4) + pcid(int4) + npoints(int4) + box(4*float8) + data(?) */ + serpch_size = 4+4+4+4*8+patch->datasize; serpch = palloc(serpch_size); /* Copy */ diff --git a/pgsql/results/pointcloud.out b/pgsql/results/pointcloud.out deleted file mode 100644 index 031cfd8..0000000 --- a/pgsql/results/pointcloud.out +++ /dev/null @@ -1,70 +0,0 @@ -CREATE EXTENSION pointcloud; -INSERT INTO pointcloud_formats (pcid, srid, schema) -VALUES (1, 0, -' - - - 1 - 4 - X coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. - X - int32_t - 0.01 - - - 2 - 4 - Y coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. - Y - int32_t - 0.01 - - - 3 - 4 - Z coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. - Z - int32_t - 0.01 - - - 4 - 2 - The intensity value is the integer representation of the pulse return magnitude. This value is optional and system specific. However, it should always be included if available. - Intensity - uint16_t - 1 - - - - - - - - - - 4326 - -' -); -CREATE TABLE pt_test ( - pt PCPOINT -); -INSERT INTO pt_test (pt) VALUES ('00000000010000000100000002000000030004'); -INSERT INTO pt_test (pt) VALUES ('00000000010000000200000003000000030005'); -INSERT INTO pt_test (pt) VALUES ('00000000010000000300000004000000030006'); -SELECT PC_Get(pt, 'Intensity') FROM pt_test; - pc_get --------- - 4 - 5 - 6 -(3 rows) - -SELECT Sum(PC_Get(pt, 'y')) FROM pt_test; - sum ------- - 0.09 -(1 row) - -DROP TABLE pt_test; diff --git a/pgsql/sql/pointcloud.sql b/pgsql/sql/pointcloud.sql index ddd2a07..dfd3d8e 100644 --- a/pgsql/sql/pointcloud.sql +++ b/pgsql/sql/pointcloud.sql @@ -60,4 +60,6 @@ INSERT INTO pt_test (pt) VALUES ('00000000010000000300000004000000030006'); SELECT PC_Get(pt, 'Intensity') FROM pt_test; SELECT Sum(PC_Get(pt, 'y')) FROM pt_test; +SELECT PC_AsText(pt) FROM pt_test; + DROP TABLE pt_test;