]> granicus.if.org Git - postgis/commitdiff
Multilinestring working even for closed multilinestrings. Still need to fix polygon...
authorRegina Obe <lr@pcorp.us>
Wed, 16 Mar 2011 22:15:22 +0000 (22:15 +0000)
committerRegina Obe <lr@pcorp.us>
Wed, 16 Mar 2011 22:15:22 +0000 (22:15 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@6915 b70326c6-7e19-0410-871a-916f4a2858ee

doc/reference_output.xml
liblwgeom/lwout_x3d.c

index 8f45d1adbaa46cae30208b3fd2621920bcdb5574..d8d0167a67219cc5ac7a868c05c490ab7fbbc031 100644 (file)
@@ -915,7 +915,11 @@ SELECT ST_AsGML(3, ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0
       <Shape>
        <Appearance>
             <Material emissiveColor='0 0 1'/>   
-       </Appearance> <IndexedFaceSet  coordIndex='0 1 2 3 -1 4 5 6 7 -1 8 9 10 11 -1 12 13 14 15 -1 16 17 18 19 -1 20 21 22 23'><Coordinate point='0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 1 1 1 1 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1' /></IndexedFaceSet></Shape>
+       </Appearance> 
+       <IndexedFaceSet  coordIndex='0 1 2 3 -1 4 5 6 7 -1 8 9 10 11 -1 12 13 14 15 -1 16 17 18 19 -1 20 21 22 23'>
+            <Coordinate point='0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 1 1 1 1 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1' />
+      </IndexedFaceSet>
+      </Shape>
     </Transform>
   </Scene>
 </X3D>]]></programlisting>
@@ -939,6 +943,19 @@ SELECT ST_AsGML(3, ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0
                --------
 <![CDATA[<IndexedTriangleSet  index='0 1 2 3 4 5'><Coordinate point='0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 0'/></IndexedTriangleSet>]]></programlisting>
          </refsection>
+         <refsection>
+               <title>Example: Closed multilinestring (the boundary of a polygon with holes)</title>
+               <programlisting><![CDATA[SELECT ST_AsX3D(
+                   ST_GeomFromEWKT('MULTILINESTRING((20 0 10,16 -12 10,0 -16 10,-12 -12 10,-20 0 10,-12 16 10,0 24 10,16 16 10,20 0 10),
+  (12 0 10,8 8 10,0 12 10,-8 8 10,-8 0 10,-8 -4 10,0 -8 10,8 -4 10,12 0 10))') 
+) As x3dfrag;]]>
+
+               x3dfrag
+               --------
+<![CDATA[<IndexedLineSet  coordIndex='0 1 2 3 4 5 6 7 0 -1 8 9 10 11 12 13 14 15 8'>
+    <Coordinate point='20 0 10 16 -12 10 0 -16 10 -12 -12 10 -20 0 10 -12 16 10 0 24 10 16 16 10 12 0 10 8 8 10 0 12 10 -8 8 10 -8 0 10 -8 -4 10 0 -8 10 8 -4 10 ' />
+ </IndexedLineSet>]]></programlisting>
+         </refsection>
        </refentry>
 
        <refentry id="ST_GeoHash">
index 60eb4c96d607d1d41eb01b9255a374ba24867772..0010b91eb17183c294406fbdea2fd08d2f52f0e0 100644 (file)
@@ -36,7 +36,7 @@ static char *asx3d3_psurface(const LWPSURFACE *psur, char *srs, int precision, i
 static char *asx3d3_tin(const LWTIN *tin, char *srs, int precision, int opts, const char *defid);\r
 static size_t asx3d3_collection_size(const LWCOLLECTION *col, char *srs, int precision, int opts, const char *defid);\r
 static char *asx3d3_collection(const LWCOLLECTION *col, char *srs, int precision, int opts, const char *defid);\r
-static size_t pointArray_toX3D3(POINTARRAY *pa, char *buf, int precision, int opts, int type);\r
+static size_t pointArray_toX3D3(POINTARRAY *pa, char *buf, int precision, int opts, int is_closed);\r
 \r
 static size_t pointArray_X3Dsize(POINTARRAY *pa, int precision);\r
 \r
@@ -113,7 +113,7 @@ asx3d3_point_buf(const LWPOINT *point, char *srs, char *output, int precision, i
        //ptr += sprintf(ptr, "%s", defid);\r
        \r
        //ptr += sprintf(ptr, "<%spos>", defid);\r
-       ptr += pointArray_toX3D3(point->point, ptr, precision, opts, point->type);\r
+       ptr += pointArray_toX3D3(point->point, ptr, precision, opts, 0);\r
        //ptr += sprintf(ptr, "</%spos></%sPoint>", defid, defid);\r
 \r
        return (ptr-output);\r
@@ -163,7 +163,7 @@ asx3d3_line_buf(const LWLINE *line, char *srs, char *output, int precision, int
 \r
 \r
        ptr += sprintf(ptr, "<Coordinate point='");\r
-       ptr += pointArray_toX3D3(line->points, ptr, precision, opts, line->type);\r
+       ptr += pointArray_toX3D3(line->points, ptr, precision, opts, lwline_is_closed(line));\r
 \r
        ptr += sprintf(ptr, "' />");\r
 \r
@@ -177,17 +177,17 @@ asx3d3_line_coords(const LWLINE *line, char *output, int precision, int opts)
        char *ptr=output;\r
        \r
        ptr += sprintf(ptr, "");\r
-       ptr += pointArray_toX3D3(line->points, ptr, precision, opts, line->type);\r
+       ptr += pointArray_toX3D3(line->points, ptr, precision, opts, lwline_is_closed(line));\r
        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
+asx3d3_mline_coordindex(const LWMLINE *mgeom, char *output)\r
 {\r
        char *ptr=output;\r
        LWLINE *geom;\r
-       int i, j, k;\r
+       int i, j, k, si;\r
        POINTARRAY *pa;\r
        int np;\r
        \r
@@ -197,17 +197,26 @@ asx3d3_mline_coordindex(const LWCOLLECTION *mgeom, char *output)
        {\r
                geom = (LWLINE *) mgeom->geoms[i];\r
                pa = geom->points;\r
-               np = pa->npoints - 1;\r
+               np = pa->npoints;\r
+               si = j; //start index of first point of linestring\r
                for(k=0; k < np ; k++){\r
             if (k) {\r
                 ptr += sprintf(ptr, " ");    \r
             }\r
-            ptr += sprintf(ptr, "%d", (j + k));\r
+            /** if the linestring is closed, we put the start point index \r
+            *   for the last vertex to denote use first point\r
+            *    and don't increment the index **/\r
+            if (!lwline_is_closed(geom) || k < (np -1) ){\r
+                ptr += sprintf(ptr, "%d", j);\r
+                j += 1;\r
+            }\r
+            else { \r
+                ptr += sprintf(ptr,"%d", si);\r
+            }\r
                }\r
                if (i < (mgeom->ngeoms - 1) ){\r
-                               ptr += sprintf(ptr, " -1 "); //separator for each subgeom\r
+                   ptr += sprintf(ptr, " -1 "); //separator for each linestring\r
                }\r
-               j += k;\r
        }\r
        return (ptr-output);\r
 }\r
@@ -250,10 +259,10 @@ asx3d3_poly_buf(const LWPOLY *poly, char *srs, char *output, int precision, int
        int dimension=2;\r
 \r
        if (FLAGS_GET_Z(poly->flags)) dimension = 3;\r
-       ptr += pointArray_toX3D3(poly->rings[0], ptr, precision, opts, poly->type);\r
+       ptr += pointArray_toX3D3(poly->rings[0], ptr, precision, opts, 1);\r
        for (i=1; i<poly->nrings; i++)\r
        {\r
-               ptr += pointArray_toX3D3(poly->rings[i], ptr, precision, opts, poly->type);\r
+               ptr += pointArray_toX3D3(poly->rings[i], ptr, precision, opts,1);\r
                ptr += sprintf(ptr, " ");\r
        }\r
        return (ptr-output);\r
@@ -289,7 +298,7 @@ static size_t
 asx3d3_triangle_buf(const LWTRIANGLE *triangle, char *srs, char *output, int precision, int opts, const char *defid)\r
 {\r
        char *ptr=output;\r
-       ptr += pointArray_toX3D3(triangle->points, ptr, precision, opts, triangle->type);\r
+       ptr += pointArray_toX3D3(triangle->points, ptr, precision, opts, 1);\r
 \r
        return (ptr-output);\r
 }\r
@@ -704,7 +713,7 @@ asx3d3_collection(const LWCOLLECTION *col, char *srs, int precision, int opts, c
 /* In X3D3, coordinates are separated by a space separator\r
  */\r
 static size_t\r
-pointArray_toX3D3(POINTARRAY *pa, char *output, int precision, int opts, int type)\r
+pointArray_toX3D3(POINTARRAY *pa, char *output, int precision, int opts, int is_closed)\r
 {\r
        int i;\r
        char *ptr;\r
@@ -719,7 +728,7 @@ pointArray_toX3D3(POINTARRAY *pa, char *output, int precision, int opts, int typ
                for (i=0; i<pa->npoints; i++)\r
                {\r
                        /** Only output the point if it is not the last point of a closed object or it is a non-closed type **/\r
-                       if (!(type == POLYGONTYPE || type == TRIANGLETYPE) || i < (pa->npoints - 1) ){\r
+                       if ( !is_closed || i < (pa->npoints - 1) ){\r
                                POINT2D pt;\r
                                getPoint2d_p(pa, i, &pt);\r
        \r
@@ -745,7 +754,7 @@ pointArray_toX3D3(POINTARRAY *pa, char *output, int precision, int opts, int typ
                for (i=0; i<pa->npoints; i++)\r
                {\r
                        /** Only output the point if it is not the last point of a closed object or it is a non-closed type **/\r
-                       if (!(type == POLYGONTYPE || type == TRIANGLETYPE) || i < (pa->npoints - 1) ){\r
+                       if ( !is_closed || i < (pa->npoints - 1) ){\r
                                POINT4D pt;\r
                                getPoint4d_p(pa, i, &pt);\r
        \r