From: Sandro Santilli Date: Thu, 26 Jan 2012 12:59:59 +0000 (+0000) Subject: Implement lwline_from_lwgeom_array (untested) X-Git-Tag: 2.0.0alpha3~65 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ffd5b6675806494382aa8f66800de7a75bc8c8a;p=postgis Implement lwline_from_lwgeom_array (untested) git-svn-id: http://svn.osgeo.org/postgis/trunk@8930 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 30a715536..c8d226f6c 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -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); diff --git a/liblwgeom/lwline.c b/liblwgeom/lwline.c index 24057e445..74e878af1 100644 --- a/liblwgeom/lwline.c +++ b/liblwgeom/lwline.c @@ -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; iflags) ) 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.