]> granicus.if.org Git - postgis/commitdiff
Encoded Polyline of EMPTY
authorDarafei Praliaskouski <me@komzpa.net>
Fri, 12 Jan 2018 08:18:39 +0000 (08:18 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Fri, 12 Jan 2018 08:18:39 +0000 (08:18 +0000)
Closes #3982
Closes https://github.com/postgis/postgis/pull/189

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

NEWS
liblwgeom/cunit/cu_out_encoded_polyline.c
liblwgeom/lwout_encoded_polyline.c

diff --git a/NEWS b/NEWS
index 31f5825771f9f3968dfe4e404fdd9e0758159296..c9b485cbf99a71c8f0bc96791c38bee971b2eb95 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,8 @@ PostGIS 2.5.0
            (Darafei Praliaskouski)
   - #3971, ST_ClusterKMeans now uses better initial seed (Darafei Praliaskouski)
   - #3977, ST_ClusterKMeans is now faster and simpler (Darafei Praliaskouski)
+  - #3982, ST_AsEncodedPolyline supports LINESTRING EMPTY and MULTIPOINT EMPTY
+           (Darafei Praliaskouski)
 
 PostGIS 2.4.0
 2017/09/30
index b9728a3f8b3d624ec8cf082c9e7e81edf13f95d6..0cdcc1f599b63fa82ef56ea6100675124e7f806b 100644 (file)
@@ -46,17 +46,18 @@ out_encoded_polyline_test_geoms(void)
                "33.6673 38.6972,33.6626 38.6871)",
                5,
                "k~fkFsvolEbe@bVvVzJb~@j\\");
-       return;
 
        /* Linestring */
        do_encoded_polyline_test(
                "LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)",
                5,
                "_p~iF~ps|U_ulLnnqC_mqNvxq`@");
+       do_encoded_polyline_test("LINESTRING EMPTY", 5, "");
 
        /* MultiPoint */
        do_encoded_polyline_test(
                "MULTIPOINT(-120.2 38.5,-120.95 40.7)", 5, "_p~iF~ps|U_ulLnnqC");
+       do_encoded_polyline_test("MULTIPOINT EMPTY", 5, "");
 }
 
 static void
index 1400e46cfd4e276859a0a04bcb1ca3f2f5ccad2a..011da60acbc7ed7edde7bbc4d7aafb4df0d31b7e 100644 (file)
@@ -69,18 +69,27 @@ pointarray_to_encoded_polyline(const POINTARRAY* pa, int precision)
 {
        int i;
        const POINT2D* prevPoint;
-       int* delta = lwalloc(2 * sizeof(int) * pa->npoints);
+       int* delta;
        char* encoded_polyline = NULL;
        stringbuffer_t* sb;
        double scale = pow(10, precision);
 
+       /* Empty input is empty string */
+       if (pa->npoints == 0) {
+               encoded_polyline = lwalloc(1 * sizeof(char));
+               encoded_polyline[0] = 0;
+               return encoded_polyline;
+       }
+
+       delta = lwalloc(2 * sizeof(int) * pa->npoints);
+
        /* Take the double value and multiply it by 1x10^precision, rounding the
         * result */
        prevPoint = getPoint2d_cp(pa, 0);
        delta[0] = round(prevPoint->y * scale);
        delta[1] = round(prevPoint->x * scale);
 
-       /*  points only include the offset from the previous point */
+       /* Points only include the offset from the previous point */
        for (i = 1; i < pa->npoints; i++)
        {
                const POINT2D* point = getPoint2d_cp(pa, i);