]> granicus.if.org Git - postgis/commitdiff
#1996, ST_AsGeoJSON('POINT EMPTY') produces invalid JSON
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 2 Nov 2012 19:15:05 +0000 (19:15 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 2 Nov 2012 19:15:05 +0000 (19:15 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10628 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/lwout_geojson.c
regress/tickets.sql
regress/tickets_expected

diff --git a/NEWS b/NEWS
index 5fcaf4ef5012eb942caf44c61a0920b323d4df38..bae94c8b4fe7faec4dfebce99e008cdbedaa3458 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -94,6 +94,7 @@ PostGIS 2.1.0
   - #1957, ST_Distance to a one-point LineString returns NULL 
   - #1976, Geography point-in-ring code overhauled for more reliability
   - #1981, cleanup of unused variables causing warnings with gcc 4.6+
+  - #1996, support POINT EMPTY in GeoJSON output
   - #2026, improve performance of distance calculations 
   - #2057, Fixed linking issue for raster2psql to libpq
   - #2077, Fixed incorrect values returning from ST_Hillshade()
index 015dc8bc6237d71d09681042c50ecccf58dc95e3..f7ec7e49cfdb3b16b1f375f32ddde7159798ab79 100644 (file)
@@ -158,6 +158,9 @@ asgeojson_point_size(const LWPOINT *point, char *srs, GBOX *bbox, int precision)
        size += sizeof("{'type':'Point',");
        size += sizeof("'coordinates':}");
 
+       if ( lwpoint_is_empty(point) )
+               size += 2; /* [] */
+
        if (srs) size += asgeojson_srs_size(srs);
        if (bbox) size += asgeojson_bbox_size(FLAGS_GET_Z(point->flags), precision);
 
@@ -174,6 +177,8 @@ asgeojson_point_buf(const LWPOINT *point, char *srs, char *output, GBOX *bbox, i
        if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(point->flags), precision);
 
        ptr += sprintf(ptr, "\"coordinates\":");
+       if ( lwpoint_is_empty(point) )
+               ptr += sprintf(ptr, "[]");
        ptr += pointArray_to_geojson(point->point, ptr, precision);
        ptr += sprintf(ptr, "}");
 
index 919f854b5b10a56d9d43c2bf3b50929fee65a253..dfe241069166320edae87ee6b77d0df3cd4a325a 100644 (file)
@@ -725,5 +725,8 @@ SELECT '#1957', ST_Distance(ST_Makeline(ARRAY['POINT(1 0)'::geometry]), 'POINT(0
 -- #1978 --
 SELECT '#1978', round(ST_Length(ST_GeomFromText('CIRCULARSTRING(0 0,1 0,0 0)',0))::numeric,4);
 
+-- #1996 --
+SELECT '#1996', ST_AsGeoJSON(ST_GeomFromText('POINT EMPTY'));
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
index 4ce2d2b3f59b298fed9ef65e30d198caef0ac564..afc2ee9a6484cc4455c8ae8738b7d76b0634a6a0 100644 (file)
@@ -228,3 +228,4 @@ ERROR:  ST_Segmentize: invalid max_distance 0 (must be >= 0)
 ERROR:  invalid GML representation
 #1957|1
 #1978|3.1413
+#1996|{"type":"Point","coordinates":[]}