]> granicus.if.org Git - postgis/commitdiff
sort of take care of multilinestrings -- doesn't work for multilinestrings with close...
authorRegina Obe <lr@pcorp.us>
Wed, 16 Mar 2011 20:23:49 +0000 (20:23 +0000)
committerRegina Obe <lr@pcorp.us>
Wed, 16 Mar 2011 20:23:49 +0000 (20:23 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@6914 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwout_x3d.c

index f585936f7cb4e2ce552f3036923a15cb516a901a..60eb4c96d607d1d41eb01b9255a374ba24867772 100644 (file)
@@ -181,6 +181,38 @@ asx3d3_line_coords(const LWLINE *line, char *output, int precision, int opts)
        return (ptr-output);\r
 }\r
 \r
+/* Calculate the coordIndex property of the IndexedLineSet for the multilinestring */\r
+static size_t\r
+asx3d3_mline_coordindex(const LWCOLLECTION *mgeom, char *output)\r
+{\r
+       char *ptr=output;\r
+       LWLINE *geom;\r
+       int i, j, k;\r
+       POINTARRAY *pa;\r
+       int np;\r
+       \r
+       ptr += sprintf(ptr, "");\r
+       j = 0;\r
+       for (i=0; i < mgeom->ngeoms; i++)\r
+       {\r
+               geom = (LWLINE *) mgeom->geoms[i];\r
+               pa = geom->points;\r
+               np = pa->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 < (mgeom->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
 {\r
@@ -193,7 +225,7 @@ asx3d3_line(const LWLINE *line, char *srs, int precision, int opts, const char *
        return output;\r
 }\r
 \r
-\r
+/* Compute the string space needed for the IndexedFaceSet representation of the polygon **/\r
 static size_t\r
 asx3d3_poly_size(const LWPOLY *poly,  char *srs, int precision, int opts, const char *defid)\r
 {\r
@@ -202,10 +234,6 @@ asx3d3_poly_size(const LWPOLY *poly,  char *srs, int precision, int opts, const
        int i;\r
 \r
        size = ( sizeof("<IndexedFaceSet></IndexedFaceSet>") + (defidlen*3) ) * 2 + 6 * (poly->nrings - 1);\r
-       //size += ( sizeof("<interior><LinearRing>//") + (defidlen*2) ) * 2 * (poly->nrings - 1);\r
-       //size += ( sizeof("<posList></posList>") + (defidlen*2) ) * poly->nrings;\r
-       //if (srs)     size += strlen(srs) + sizeof(" srsName=..");\r
-       //if (IS_DIMS(opts)) size += sizeof(" srsDimension='x'") * poly->nrings;\r
 \r
        for (i=0; i<poly->nrings; i++)\r
                size += pointArray_X3Dsize(poly->rings[i], precision);\r
@@ -213,6 +241,7 @@ asx3d3_poly_size(const LWPOLY *poly,  char *srs, int precision, int opts, const
        return size;\r
 }\r
 \r
+/** Compute the X3D coordinates of the polygon **/\r
 static size_t\r
 asx3d3_poly_buf(const LWPOLY *poly, char *srs, char *output, int precision, int opts, int is_patch, const char *defid)\r
 {\r
@@ -327,15 +356,13 @@ asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision
 {\r
        int type = col->type;\r
        char *ptr, *x3dtype, *coordIndex;\r
-       int i, size;\r
+       int i;\r
        //int numvertices;\r
        LWGEOM *subgeom;\r
        POINTARRAY *pa;\r
 \r
        ptr = output;\r
        x3dtype="";\r
-       //numvertices = lwcollection_count_vertices(col)*col->ngeoms*20;\r
-       //size = 1000;\r
        coordIndex = lwalloc(1000);\r
 \r
        for (i=0; i<col->ngeoms; i++){\r
@@ -349,7 +376,9 @@ asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision
        }\r
        else if (type == MULTILINETYPE) {\r
                x3dtype = "IndexedLineSet";\r
-               ptr += sprintf(ptr, "<%s %s coordIndex='%s'>", x3dtype, defid, coordIndex);\r
+               ptr += sprintf(ptr, "<%s %s coordIndex='", x3dtype, defid);\r
+               ptr += asx3d3_mline_coordindex(col, ptr);\r
+               ptr += sprintf(ptr, "'>");\r
        }\r
        else if (type == MULTIPOLYGONTYPE) {\r
                x3dtype = "IndexedFaceSet";\r