From 5d014027e72d064a43dbf5ae1f27012e06661759 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 2 Nov 2012 19:15:05 +0000 Subject: [PATCH] #1996, ST_AsGeoJSON('POINT EMPTY') produces invalid JSON git-svn-id: http://svn.osgeo.org/postgis/trunk@10628 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + liblwgeom/lwout_geojson.c | 5 +++++ regress/tickets.sql | 3 +++ regress/tickets_expected | 1 + 4 files changed, 10 insertions(+) diff --git a/NEWS b/NEWS index 5fcaf4ef5..bae94c8b4 100644 --- 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() diff --git a/liblwgeom/lwout_geojson.c b/liblwgeom/lwout_geojson.c index 015dc8bc6..f7ec7e49c 100644 --- a/liblwgeom/lwout_geojson.c +++ b/liblwgeom/lwout_geojson.c @@ -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, "}"); diff --git a/regress/tickets.sql b/regress/tickets.sql index 919f854b5..dfe241069 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -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; diff --git a/regress/tickets_expected b/regress/tickets_expected index 4ce2d2b3f..afc2ee9a6 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -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":[]} -- 2.40.0