]> granicus.if.org Git - postgis/commitdiff
Fill in coordIndex for multipolygons
authorRegina Obe <lr@pcorp.us>
Fri, 18 Mar 2011 21:13:54 +0000 (21:13 +0000)
committerRegina Obe <lr@pcorp.us>
Fri, 18 Mar 2011 21:13:54 +0000 (21:13 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@6938 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwout_x3d.c

index 0010b91eb17183c294406fbdea2fd08d2f52f0e0..e405c9a219b63af306a2f24b5dd60dff5c9f43a1 100644 (file)
@@ -221,6 +221,38 @@ asx3d3_mline_coordindex(const LWMLINE *mgeom, char *output)
        return (ptr-output);\r
 }\r
 \r
+/* Calculate the coordIndex property of the IndexedLineSet for a multipolygon \r
+    This is not ideal -- would be really nice to just share this function with psurf, \r
+    but I'm not smart enough to do that yet*/\r
+static size_t\r
+asx3d3_mpoly_coordindex(const LWMPOLY *psur, char *output)\r
+{\r
+       char *ptr=output;\r
+       LWPOLY *patch;\r
+       int i, j, k, si;\r
+       POINTARRAY *pa;\r
+       int np;\r
+       \r
+       ptr += sprintf(ptr, "");\r
+       j = 0;\r
+       for (i=0; i<psur->ngeoms; i++)\r
+       {\r
+               patch = (LWPOLY *) psur->geoms[i];\r
+               np = patch->rings[0]->npoints - 1;\r
+           for(k=0; k < np ; k++){\r
+               if (k) {\r
+                   ptr += sprintf(ptr, " ");    \r
+               }\r
+               ptr += sprintf(ptr, "%d", (j + k));\r
+           }\r
+           if (i < (psur->ngeoms - 1) ){\r
+               ptr += sprintf(ptr, " -1 "); //separator for each subgeom\r
+           }\r
+           j += k;\r
+       }\r
+       return (ptr-output);\r
+}\r
+\r
 /* Return the linestring as an X3D LineSet */\r
 static char *\r
 asx3d3_line(const LWLINE *line, char *srs, int precision, int opts, const char *defid)\r
@@ -364,20 +396,14 @@ static size_t
 asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision, int opts, const char *defid)\r
 {\r
        int type = col->type;\r
-       char *ptr, *x3dtype, *coordIndex;\r
+       char *ptr, *x3dtype;\r
        int i;\r
-       //int numvertices;\r
        LWGEOM *subgeom;\r
        POINTARRAY *pa;\r
 \r
        ptr = output;\r
        x3dtype="";\r
-       coordIndex = lwalloc(1000);\r
 \r
-       for (i=0; i<col->ngeoms; i++){\r
-               /** TODO: This is wrong, but haven't quite figured out how to correct. Involves ring order and bunch of other stuff **/\r
-               coordIndex += sprintf(coordIndex, "-1 ");\r
-       }\r
                        \r
        if      (type == MULTIPOINTTYPE) {\r
                x3dtype = "PointSet";\r
@@ -391,7 +417,9 @@ asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision
        }\r
        else if (type == MULTIPOLYGONTYPE) {\r
                x3dtype = "IndexedFaceSet";\r
-               ptr += sprintf(ptr, "<%s %s coordIndex='%s'>", x3dtype, defid, coordIndex);\r
+               ptr += sprintf(ptr, "<%s %s coordIndex='", x3dtype, defid);\r
+               ptr += asx3d3_mpoly_coordindex(col,ptr);\r
+               ptr += sprintf(ptr, "'>");\r
        }\r
 \r
        ptr += sprintf(ptr, "<Coordinate point='");\r