[postgis-tickets] r15444 - ST_AsX3D handle empty geometries

Regina Obe lr at pcorp.us
Thu Jun 22 23:00:59 PDT 2017


Author: robe
Date: 2017-06-22 23:00:59 -0700 (Thu, 22 Jun 2017)
New Revision: 15444

Modified:
   trunk/liblwgeom/lwout_x3d.c
   trunk/regress/tickets.sql
   trunk/regress/tickets_expected
Log:
ST_AsX3D handle empty geometries
References #3704 for PostGIS 2.4 (trunk)

Modified: trunk/liblwgeom/lwout_x3d.c
===================================================================
--- trunk/liblwgeom/lwout_x3d.c	2017-06-23 05:55:55 UTC (rev 15443)
+++ trunk/liblwgeom/lwout_x3d.c	2017-06-23 06:00:59 UTC (rev 15444)
@@ -61,6 +61,15 @@
 {
 	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 @@
 	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,8 +403,8 @@
 		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=.."); */
 
 	for (i=0; i<col->ngeoms; i++)
@@ -525,8 +534,8 @@
 
 	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++)
 	{
 		size += asx3d3_poly_size(psur->geoms[i], 0, precision, opts, defid)*5; /** need to make space for coordIndex values too including -1 separating each poly**/
@@ -658,7 +667,7 @@
 
 	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 @@
 		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 @@
 
 				if ( i )
 					ptr += sprintf(ptr, " ");
-					
+
 				if ( ( opts & LW_X3D_FLIP_XY) )
 					ptr += sprintf(ptr, "%s %s", y, x);
 				else

Modified: trunk/regress/tickets.sql
===================================================================
--- trunk/regress/tickets.sql	2017-06-23 05:55:55 UTC (rev 15443)
+++ trunk/regress/tickets.sql	2017-06-23 06:00:59 UTC (rev 15444)
@@ -27,7 +27,7 @@
 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 @@
 	 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 '#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;

Modified: trunk/regress/tickets_expected
===================================================================
--- trunk/regress/tickets_expected	2017-06-23 05:55:55 UTC (rev 15443)
+++ trunk/regress/tickets_expected	2017-06-23 06:00:59 UTC (rev 15444)
@@ -301,3 +301,4 @@
 #3620b|POINT(2 8)
 #3627a|o}~~|AdshNoSsBgd at eGoBlm@wKhj@~@?
 #3627b|t
+#3704|t



More information about the postgis-tickets mailing list