Index: lwgeom/lwgeom_functions_basic.c
===================================================================
--- lwgeom/lwgeom_functions_basic.c	(revision 2708)
+++ lwgeom/lwgeom_functions_basic.c	(working copy)
@@ -2494,24 +2494,10 @@
 {
 	PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	BOX2DFLOAT4 box;
-	POINT2D *pts = lwalloc(sizeof(POINT2D)*5);
-	POINTARRAY *pa[1];
-	LWPOLY *poly;
 	int SRID;
 	PG_LWGEOM *result;
 	uchar *ser;
 
-	if (lwgeom_getType(geom->type) == POINTTYPE ||
-            (lwgeom_getType(geom->type) == MULTIPOINTTYPE && lwgeom_getnumgeometries(SERIALIZED_FORM(geom)) == 1))
-	{
-		int srid = lwgeom_getsrid(SERIALIZED_FORM(geom));
-		LWPOINT* point = lwgeom_getpoint(SERIALIZED_FORM(geom), 0);
-		LWPOINT* envelope = lwpoint_construct(srid, NULL, point->point);
-		ser = lwpoint_serialize(envelope);
-		result = PG_LWGEOM_construct(ser, srid, 0);
-	PG_RETURN_POINTER(result);
-	}
-
 	/* get bounding box  */
 	if ( ! getbox2d_p(SERIALIZED_FORM(geom), &box) )
 	{
@@ -2522,27 +2508,52 @@
 	/* get geometry SRID */
 	SRID = lwgeom_getsrid(SERIALIZED_FORM(geom));
 
-	PG_FREE_IF_COPY(geom, 0);
+	if (lwgeom_getType(geom->type) == POINTTYPE ||
+	    lwgeom_getType(geom->type) == LINETYPE)
+	{
+		LWGEOM* lwgeom = lwgeom_deserialize(SERIALIZED_FORM(geom));
+		LWPOINT* envelope = lwgeom_clone(lwgeom);
+		ser = lwgeom_serialize(envelope);
+	}
+	else if (lwgeom_getType(geom->type) == MULTIPOINTTYPE &&
+	         lwgeom_getnumgeometries(SERIALIZED_FORM(geom)) == 1)
+	{
+		LWPOINT* point = lwgeom_getpoint(SERIALIZED_FORM(geom), 0);
+		LWPOINT* envelope = lwpoint_clone(point);
+		ser = lwgeom_serialize(envelope);
+	}
+	else if (lwgeom_getType(geom->type) == MULTILINETYPE &&
+	         lwgeom_getnumgeometries(SERIALIZED_FORM(geom)) == 1)
+	{
+		LWLINE* line = lwgeom_getline(SERIALIZED_FORM(geom), 0);
+		LWLINE* envelope = lwpoint_clone(line);
+		ser = lwgeom_serialize(envelope);
+	}
+	else
+	{
+		POINT2D *pts = lwalloc(sizeof(POINT2D)*5);
+		POINTARRAY *pa;
+		LWPOLY *poly;
+		
+		/* Assign coordinates to POINT2D array */
+		pts[0].x = box.xmin; pts[0].y = box.ymin;
+		pts[1].x = box.xmin; pts[1].y = box.ymax;
+		pts[2].x = box.xmax; pts[2].y = box.ymax;
+		pts[3].x = box.xmax; pts[3].y = box.ymin;
+		pts[4].x = box.xmin; pts[4].y = box.ymin;
 
-	/* Assign coordinates to POINT2D array */
-	pts[0].x = box.xmin; pts[0].y = box.ymin;
-	pts[1].x = box.xmin; pts[1].y = box.ymax;
-	pts[2].x = box.xmax; pts[2].y = box.ymax;
-	pts[3].x = box.xmax; pts[3].y = box.ymin;
-	pts[4].x = box.xmin; pts[4].y = box.ymin;
+		/* Construct point array */
+		pa = pointArray_construct(pts, 0, 0, 5);
 
-	/* Construct point array */
-	pa[0] = lwalloc(sizeof(POINTARRAY));
-	pa[0]->serialized_pointlist = (uchar *)pts;
-	TYPE_SETZM(pa[0]->dims, 0, 0);
-	pa[0]->npoints = 5;
+		/* Construct polygon  */
+		poly = lwpoly_construct(SRID, box2d_clone(&box), 1, &pa);
 
-	/* Construct polygon  */
-	poly = lwpoly_construct(SRID, box2d_clone(&box), 1, pa);
+		/* Serialize polygon */
+		ser = lwpoly_serialize(poly);
+	}
+			
+	PG_FREE_IF_COPY(geom, 0);
 
-	/* Serialize polygon */
-	ser = lwpoly_serialize(poly);
-
 	/* Construct PG_LWGEOM  */
 	result = PG_LWGEOM_construct(ser, SRID, 1);
 
