]> granicus.if.org Git - postgis/commitdiff
Implement lwline_from_lwgeom_array (untested)
authorSandro Santilli <strk@keybit.net>
Thu, 26 Jan 2012 12:59:59 +0000 (12:59 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 26 Jan 2012 12:59:59 +0000 (12:59 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8930 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/lwline.c

index 30a715536fcbdb10426ca321f969041c833e028e..c8d226f6c690ba6b6a029f55e48ef8275b00fa7e 100644 (file)
@@ -1185,7 +1185,8 @@ extern LWPOINT *lwpoint_make3dz(int srid, double x, double y, double z);
 extern LWPOINT *lwpoint_make3dm(int srid, double x, double y, double m);
 extern LWPOINT *lwpoint_make4d(int srid, double x, double y, double z, double m);
 extern LWPOINT *lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p);
-extern LWLINE *lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points);
+extern LWLINE *lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms);
+extern LWLINE *lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
 extern LWLINE *lwline_from_lwmpoint(int srid, LWMPOINT *mpoint);
 extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
index 24057e445a173ff85961a22052e7aff19ec967ff..74e878af1dacbe3458252765c0555368d3b1aedc 100644 (file)
@@ -141,6 +141,67 @@ lwline_same(const LWLINE *l1, const LWLINE *l2)
        return ptarray_same(l1->points, l2->points);
 }
 
+/*
+ * Construct a LWLINE from an array of point and line geometries
+ * LWLINE dimensions are large enough to host all input dimensions.
+ */
+LWLINE *
+lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
+{
+       int i;
+       int hasz = LW_FALSE;
+       int hasm = LW_FALSE;
+       POINTARRAY *pa;
+       LWLINE *line;
+       POINT4D pt;
+
+       /*
+        * Find output dimensions, check integrity
+        */
+       for (i=0; i<ngeoms; i++)
+       {
+               if ( FLAGS_GET_Z(geoms[i]->flags) ) hasz = LW_TRUE;
+               if ( FLAGS_GET_M(geoms[i]->flags) ) hasm = LW_TRUE;
+               if ( hasz && hasm ) break; /* Nothing more to learn! */
+       }
+
+       /* ngeoms should be a guess about how many points we have in input */
+       pa = ptarray_construct_empty(hasz, hasm, ngeoms);
+       
+       for ( i=0; i < ngeoms; i++ )
+       {
+               LWGEOM *g = geoms[i];
+
+               if ( lwgeom_is_empty(g) ) continue;
+
+               if ( g->type == POINTTYPE )
+               {
+                       lwpoint_getPoint4d_p((LWPOINT*)g, &pt);
+                       ptarray_append_point(pa, &pt, LW_TRUE);
+               }
+               else if ( g->type == LINETYPE )
+               {
+                       ptarray_append_ptarray(pa, ((LWLINE*)g)->points, -1);
+               }
+               else
+               {
+                       ptarray_free(pa);
+                       lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(g->type));
+                       return NULL;
+               }
+       }
+
+       if ( pa->npoints > 0 )
+               line = lwline_construct(srid, NULL, pa);
+       else  {
+               /* Is this really any different from the above ? */
+               ptarray_free(pa);
+               line = lwline_construct_empty(srid, hasz, hasm);
+       }
+       
+       return line;
+}
+
 /*
  * Construct a LWLINE from an array of LWPOINTs
  * LWLINE dimensions are large enough to host all input dimensions.