]> granicus.if.org Git - postgis/commitdiff
ST_AsX3D handle empty geometries
authorRegina Obe <lr@pcorp.us>
Fri, 23 Jun 2017 06:00:59 +0000 (06:00 +0000)
committerRegina Obe <lr@pcorp.us>
Fri, 23 Jun 2017 06:00:59 +0000 (06:00 +0000)
References #3704 for PostGIS 2.4 (trunk)

git-svn-id: http://svn.osgeo.org/postgis/trunk@15444 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwout_x3d.c
regress/tickets.sql
regress/tickets_expected

index e6058e0480341a6ff60c2875a86365f95084ea4a..5dd2a5181381a169ef4a145d51960efd28890cb7 100644 (file)
@@ -61,6 +61,15 @@ lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const cha
 {
        int type = geom->type;
 
+       /* Empty string for empties */
+       if( lwgeom_is_empty(geom) )
+       {
+               char *ret = NULL;
+               ret = lwalloc(1);
+               ret[0] = '\0';
+               return ret;
+       }
+
        switch (type)
        {
        case POINTTYPE:
@@ -156,7 +165,7 @@ asx3d3_line_size(const LWLINE *line, char *srs, int precision, int opts, const c
        size_t defidlen = strlen(defid);
 
        size = pointArray_X3Dsize(line->points, precision)*2;
-       
+
        if ( X3D_USE_GEOCOORDS(opts) ) {
                        size += (
                    sizeof("<LineSet vertexCount=''><GeoCoordinate geoSystem='\"GD\" \"WE\" \"longitude_first\"' point='' /></LineSet>")  + defidlen
@@ -394,7 +403,7 @@ asx3d3_multi_size(const LWCOLLECTION *col, char *srs, int precision, int opts, c
                size = sizeof("<PointSet><GeoCoordinate geoSystem='\"GD\" \"WE\" \"longitude_first\"' point='' /></PointSet>");
        else
                size = sizeof("<PointSet><Coordinate point='' /></PointSet>") + defidlen;
-       
+
 
        /* if ( srs ) size += strlen(srs) + sizeof(" srsName=.."); */
 
@@ -525,7 +534,7 @@ asx3d3_psurface_size(const LWPSURFACE *psur, char *srs, int precision, int opts,
 
        if ( X3D_USE_GEOCOORDS(opts) ) size = sizeof("<IndexedFaceSet convex='false' coordIndex=''><GeoCoordinate geoSystem='\"GD\" \"WE\" \"longitude_first\"' point='' />") + defidlen;
        else size = sizeof("<IndexedFaceSet convex='false' coordIndex=''><Coordinate point='' />") + defidlen;
-       
+
 
        for (i=0; i<psur->ngeoms; i++)
        {
@@ -658,7 +667,7 @@ asx3d3_tin_buf(const LWTIN *tin, char *srs, char *output, int precision, int opt
 
        if ( X3D_USE_GEOCOORDS(opts) ) ptr += sprintf(ptr, "'><GeoCoordinate geoSystem='\"GD\" \"WE\" \"%s\"' point='", ( (opts & LW_X3D_FLIP_XY) ? "latitude_first" : "longitude_first") );
        else ptr += sprintf(ptr, "'><Coordinate point='");
-       
+
        for (i=0; i<tin->ngeoms; i++)
        {
                ptr += asx3d3_triangle_buf(tin->geoms[i], 0, ptr, precision,
@@ -781,12 +790,12 @@ asx3d3_collection_buf(const LWCOLLECTION *col, char *srs, char *output, int prec
                else if ( subgeom->type == TINTYPE )
                {
                        ptr += asx3d3_tin_buf((LWTIN*)subgeom, srs, ptr, precision, opts,  defid);
-                       
+
                }
                else if ( subgeom->type == POLYHEDRALSURFACETYPE )
                {
                        ptr += asx3d3_psurface_buf((LWPSURFACE*)subgeom, srs, ptr, precision, opts,  defid);
-                       
+
                }
                else if ( lwgeom_is_collection(subgeom) )
                {
@@ -862,7 +871,7 @@ pointArray_toX3D3(POINTARRAY *pa, char *output, int precision, int opts, int is_
 
                                if ( i )
                                        ptr += sprintf(ptr, " ");
-                                       
+
                                if ( ( opts & LW_X3D_FLIP_XY) )
                                        ptr += sprintf(ptr, "%s %s", y, x);
                                else
index 44fca10edac7803701e548e4e413815a97822acf..13ce855435aa2e101c6fac95d475d240822f8d73 100644 (file)
@@ -27,7 +27,7 @@ SELECT '#2', ST_AsText(ST_Union(g)) FROM
 SELECT '#11', ST_Distance (a.g, ST_Intersection(b.g, a.g)) AS distance
 FROM (SELECT '01020000000200000050E8303FC2E85141B017CFC05A825541000000E0C0E85141000000205C825541'::geometry AS g) a,
         (SELECT 'LINESTRING(4694792.35840419 5638508.89950758,4694793.20840419 5638506.34950758)'::geometry AS g) b;
-       
+
 -- #21 --
 SELECT '#21', ST_AsEWKT(ST_Locate_Along_Measure(g, 4566)) FROM
 ( VALUES
@@ -205,7 +205,7 @@ SELECT '#263', ST_AsEWKT(geometry(geography(pt.the_geom))) As wkt,
         As pca,
        ST_Covers(geometry(geography(poly.the_geom)),
                geometry(geography(pt.the_geom))) As gm_to_gg_gm_pca
-       
+
 FROM (SELECT ST_GeomFromEWKT('SRID=4326;POLYGON((-119.5434 34.9438,-119.5437 34.9445,-119.5452 34.9442,-119.5434 34.9438))') As the_geom)
        As poly
     CROSS JOIN
@@ -1012,5 +1012,8 @@ SELECT '#3620b', ST_AsText(ST_MinimumBoundingCircle('LINESTRING (2 8, 2 8)'));
 SELECT '#3627a', ST_AsEncodedPolyline('SRID=4326;LINESTRING(-0.250691 49.283048,-0.250633 49.283376,-0.250502 49.283972,-0.251245 49.284028,-0.251938 49.284232,-0.251938 49.2842)', 6);
 SELECT '#3627b', ST_Equals(geom, ST_LineFromEncodedPolyline(ST_AsEncodedPolyline(geom, 7), 7)) FROM (VALUES ('SRID=4326;LINESTRING (0 0, 1 1)')) AS v (geom);
 
+-- #3704
+SELECT '#3704', ST_AsX3D('LINESTRING EMPTY') = '';
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
index 787e5d7f8dcd660cc6bb859e7a002780b7935c0c..cbe200c62acb30f9b79e34a87849ba97a00a597b 100644 (file)
@@ -301,3 +301,4 @@ ERROR:  invalid KML representation
 #3620b|POINT(2 8)
 #3627a|o}~~|AdshNoSsBgd@eGoBlm@wKhj@~@?
 #3627b|t
+#3704|t