From: Regina Obe Date: Wed, 16 Mar 2011 20:23:49 +0000 (+0000) Subject: sort of take care of multilinestrings -- doesn't work for multilinestrings with close... X-Git-Tag: 2.0.0alpha1~1888 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02c354beb2b2ee06e4dafc2673e98f357a89fa8d;p=postgis sort of take care of multilinestrings -- doesn't work for multilinestrings with closed linestrings so that's next up to correct. git-svn-id: http://svn.osgeo.org/postgis/trunk@6914 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwout_x3d.c b/liblwgeom/lwout_x3d.c index f585936f7..60eb4c96d 100644 --- a/liblwgeom/lwout_x3d.c +++ b/liblwgeom/lwout_x3d.c @@ -181,6 +181,38 @@ asx3d3_line_coords(const LWLINE *line, char *output, int precision, int opts) return (ptr-output); } +/* Calculate the coordIndex property of the IndexedLineSet for the multilinestring */ +static size_t +asx3d3_mline_coordindex(const LWCOLLECTION *mgeom, char *output) +{ + char *ptr=output; + LWLINE *geom; + int i, j, k; + POINTARRAY *pa; + int np; + + ptr += sprintf(ptr, ""); + j = 0; + for (i=0; i < mgeom->ngeoms; i++) + { + geom = (LWLINE *) mgeom->geoms[i]; + pa = geom->points; + np = pa->npoints - 1; + for(k=0; k < np ; k++){ + if (k) { + ptr += sprintf(ptr, " "); + } + ptr += sprintf(ptr, "%d", (j + k)); + } + if (i < (mgeom->ngeoms - 1) ){ + ptr += sprintf(ptr, " -1 "); //separator for each subgeom + } + j += k; + } + return (ptr-output); +} + +/* Return the linestring as an X3D LineSet */ static char * asx3d3_line(const LWLINE *line, char *srs, int precision, int opts, const char *defid) { @@ -193,7 +225,7 @@ asx3d3_line(const LWLINE *line, char *srs, int precision, int opts, const char * return output; } - +/* Compute the string space needed for the IndexedFaceSet representation of the polygon **/ static size_t asx3d3_poly_size(const LWPOLY *poly, char *srs, int precision, int opts, const char *defid) { @@ -202,10 +234,6 @@ asx3d3_poly_size(const LWPOLY *poly, char *srs, int precision, int opts, const int i; size = ( sizeof("") + (defidlen*3) ) * 2 + 6 * (poly->nrings - 1); - //size += ( sizeof("//") + (defidlen*2) ) * 2 * (poly->nrings - 1); - //size += ( sizeof("") + (defidlen*2) ) * poly->nrings; - //if (srs) size += strlen(srs) + sizeof(" srsName=.."); - //if (IS_DIMS(opts)) size += sizeof(" srsDimension='x'") * poly->nrings; for (i=0; inrings; i++) size += pointArray_X3Dsize(poly->rings[i], precision); @@ -213,6 +241,7 @@ asx3d3_poly_size(const LWPOLY *poly, char *srs, int precision, int opts, const return size; } +/** Compute the X3D coordinates of the polygon **/ static size_t asx3d3_poly_buf(const LWPOLY *poly, char *srs, char *output, int precision, int opts, int is_patch, const char *defid) { @@ -327,15 +356,13 @@ asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision { int type = col->type; char *ptr, *x3dtype, *coordIndex; - int i, size; + int i; //int numvertices; LWGEOM *subgeom; POINTARRAY *pa; ptr = output; x3dtype=""; - //numvertices = lwcollection_count_vertices(col)*col->ngeoms*20; - //size = 1000; coordIndex = lwalloc(1000); for (i=0; ingeoms; i++){ @@ -349,7 +376,9 @@ asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision } else if (type == MULTILINETYPE) { x3dtype = "IndexedLineSet"; - ptr += sprintf(ptr, "<%s %s coordIndex='%s'>", x3dtype, defid, coordIndex); + ptr += sprintf(ptr, "<%s %s coordIndex='", x3dtype, defid); + ptr += asx3d3_mline_coordindex(col, ptr); + ptr += sprintf(ptr, "'>"); } else if (type == MULTIPOLYGONTYPE) { x3dtype = "IndexedFaceSet";