From d0095755b4d84dd6cbeab512f8ccd15b9610c2b4 Mon Sep 17 00:00:00 2001 From: Regina Obe Date: Fri, 18 Mar 2011 21:13:54 +0000 Subject: [PATCH] Fill in coordIndex for multipolygons git-svn-id: http://svn.osgeo.org/postgis/trunk@6938 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/lwout_x3d.c | 44 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/liblwgeom/lwout_x3d.c b/liblwgeom/lwout_x3d.c index 0010b91eb..e405c9a21 100644 --- a/liblwgeom/lwout_x3d.c +++ b/liblwgeom/lwout_x3d.c @@ -221,6 +221,38 @@ asx3d3_mline_coordindex(const LWMLINE *mgeom, char *output) return (ptr-output); } +/* Calculate the coordIndex property of the IndexedLineSet for a multipolygon + This is not ideal -- would be really nice to just share this function with psurf, + but I'm not smart enough to do that yet*/ +static size_t +asx3d3_mpoly_coordindex(const LWMPOLY *psur, char *output) +{ + char *ptr=output; + LWPOLY *patch; + int i, j, k, si; + POINTARRAY *pa; + int np; + + ptr += sprintf(ptr, ""); + j = 0; + for (i=0; ingeoms; i++) + { + patch = (LWPOLY *) psur->geoms[i]; + np = patch->rings[0]->npoints - 1; + for(k=0; k < np ; k++){ + if (k) { + ptr += sprintf(ptr, " "); + } + ptr += sprintf(ptr, "%d", (j + k)); + } + if (i < (psur->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) @@ -364,20 +396,14 @@ static size_t asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision, int opts, const char *defid) { int type = col->type; - char *ptr, *x3dtype, *coordIndex; + char *ptr, *x3dtype; int i; - //int numvertices; LWGEOM *subgeom; POINTARRAY *pa; ptr = output; x3dtype=""; - coordIndex = lwalloc(1000); - for (i=0; ingeoms; i++){ - /** TODO: This is wrong, but haven't quite figured out how to correct. Involves ring order and bunch of other stuff **/ - coordIndex += sprintf(coordIndex, "-1 "); - } if (type == MULTIPOINTTYPE) { x3dtype = "PointSet"; @@ -391,7 +417,9 @@ asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision } else if (type == MULTIPOLYGONTYPE) { x3dtype = "IndexedFaceSet"; - ptr += sprintf(ptr, "<%s %s coordIndex='%s'>", x3dtype, defid, coordIndex); + ptr += sprintf(ptr, "<%s %s coordIndex='", x3dtype, defid); + ptr += asx3d3_mpoly_coordindex(col,ptr); + ptr += sprintf(ptr, "'>"); } ptr += sprintf(ptr, "