From c062e145fe6e203cb37b0d4717c714ed41251b01 Mon Sep 17 00:00:00 2001 From: David Blasby Date: Wed, 27 Feb 2002 00:38:12 +0000 Subject: [PATCH] minor bug in geometry_to_text() for BOX3D only types fixed. git-svn-id: http://svn.osgeo.org/postgis/trunk@126 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis.h | 2 +- postgis_inout.c | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/postgis.h b/postgis.h index d181eaf5c..b85aceced 100644 --- a/postgis.h +++ b/postgis.h @@ -360,7 +360,7 @@ void deparse_hex(unsigned char str, unsigned char *result); char *geometry_to_text(GEOMETRY *geometry); - +BOX3D *parse_box3d(char *str); //exposed to psql diff --git a/postgis_inout.c b/postgis_inout.c index af5de2b89..43f504e10 100644 --- a/postgis_inout.c +++ b/postgis_inout.c @@ -498,15 +498,16 @@ char *scan_to_same_level(char *str) * * */ -PG_FUNCTION_INFO_V1(box3d_in); -Datum box3d_in(PG_FUNCTION_ARGS) + +BOX3D *parse_box3d(char *str) { - char *str = PG_GETARG_CSTRING(0); + BOX3D *bbox = (BOX3D *) palloc(sizeof(BOX3D)); bool junk_bool; bool okay; int npoints; + //verify that there are exactly two points //strip leading spaces @@ -518,7 +519,7 @@ Datum box3d_in(PG_FUNCTION_ARGS) { elog(ERROR,"BOX3D parser - doesnt start with BOX3D"); pfree(bbox); - PG_RETURN_NULL(); + return NULL; } if ((npoints = numb_points_in_list(str)) != 2) @@ -526,7 +527,7 @@ Datum box3d_in(PG_FUNCTION_ARGS) //printf("npoints in this bbox is %i, should be 2\n",npoints); elog(ERROR,"BOX3D parser - number of points should be exactly 2"); pfree(bbox); - PG_RETURN_NULL(); + return NULL; } //want to parse two points, and dont care if they are 2d or 3d @@ -535,7 +536,7 @@ Datum box3d_in(PG_FUNCTION_ARGS) { elog(ERROR,"box3d: couldnt parse: '%s'\n",str); pfree(bbox); - PG_RETURN_NULL() ; + return NULL; } @@ -553,7 +554,20 @@ Datum box3d_in(PG_FUNCTION_ARGS) swap ( &bbox->LLB.z , &bbox->URT.z ) ; } - PG_RETURN_POINTER(bbox); + return bbox; +} + +PG_FUNCTION_INFO_V1(box3d_in); +Datum box3d_in(PG_FUNCTION_ARGS) +{ + char *str = PG_GETARG_CSTRING(0); + BOX3D *bbox ; + + bbox = parse_box3d(str); + if (bbox != NULL) + PG_RETURN_POINTER(bbox); + else + PG_RETURN_NULL(); } /* @@ -1472,7 +1486,7 @@ Datum geometry_in(PG_FUNCTION_ARGS) { - mybox = (BOX3D*) DatumGetPointer( DirectFunctionCall1(box3d_in,PointerGetDatum(str))); + mybox = parse_box3d(str); if (mybox == NULL) PG_RETURN_NULL() ; @@ -1489,9 +1503,6 @@ Datum geometry_in(PG_FUNCTION_ARGS) pfree(mybox); PG_RETURN_POINTER(geometry); - - - } @@ -1758,7 +1769,7 @@ char *geometry_to_text(GEOMETRY *geometry) { mem_size = MAX_DIGS_DOUBLE*6+5+2+4+5+1; pfree(result); - result = (char *) palloc(size); //double digits+ "BOX3D"+ "()" + commas +null + result = (char *) palloc(mem_size); //double digits+ "BOX3D"+ "()" + commas +null sprintf(result, "BOX3D(%.15g %.15g %.15g,%.15g %.15g %.15g)", geometry->bvol.LLB.x,geometry->bvol.LLB.y,geometry->bvol.LLB.z, geometry->bvol.URT.x,geometry->bvol.URT.y,geometry->bvol.URT.z); -- 2.40.0