]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
The translation in and out of GeoJSON automatically adds or removes the
authordrh <drh@noemail.net>
Wed, 9 May 2018 15:27:35 +0000 (15:27 +0000)
committerdrh <drh@noemail.net>
Wed, 9 May 2018 15:27:35 +0000 (15:27 +0000)
redundant last vertex, as necessary.

FossilOrigin-Name: 2653bedd9f8237d9ddef533a05e161a6afe6fa4af86fac47407b3df09dc2a9eb

ext/misc/geopoly.c
manifest
manifest.uuid

index 351fbe70511fa05e371f4f6b58223c19229ef15b..c791b59741304eace3d9a059e5c4767c05fce0ae 100644 (file)
@@ -223,10 +223,14 @@ static GeoPoly *geopolyParseJson(const unsigned char *z){
       }
       break;
     }
-    if( geopolySkipSpace(&s)==']' ){
-      int nByte = sizeof(GeoPoly) * (s.nVertex-1)*2*sizeof(GeopolyCoord);
-      GeoPoly *pOut = sqlite3_malloc64( nByte );
-      int x = 1;
+    if( geopolySkipSpace(&s)==']' && s.nVertex>=4 ){
+      int nByte;
+      GeoPoly *pOut;
+      int x = (s.nVertex-1)*2;
+      if( s.a[x]==s.a[0] && s.a[x+1]==s.a[1] ) s.nVertex--;
+      nByte = sizeof(GeoPoly) * (s.nVertex-1)*2*sizeof(GeopolyCoord);
+      pOut = sqlite3_malloc64( nByte );
+      x = 1;
       if( pOut==0 ) goto parse_json_err;
       pOut->nVertex = s.nVertex;
       memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeopolyCoord));
@@ -324,9 +328,9 @@ static void geopolyJsonFunc(
     int i;
     sqlite3_str_append(x, "[", 1);
     for(i=0; i<p->nVertex; i++){
-      sqlite3_str_appendf(x, "[%g,%g]", p->a[i*2], p->a[i*2+1]);
-      sqlite3_str_append(x, i==p->nVertex-1 ? "]" : ",", 1);
+      sqlite3_str_appendf(x, "[%!g,%!g],", p->a[i*2], p->a[i*2+1]);
     }
+    sqlite3_str_appendf(x, "[%!g,%!g]]", p->a[0], p->a[1]);
     sqlite3_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free);
     sqlite3_free(p);
   }
index 74a1319ecf006856eef7db1a73ebd52018d8f2fb..eb951cf73b8b4735b9eb27d4167e3f8d1ba92ebb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sthe\sgeopoly_json()\sSQL\sfunction\sso\sthat\sit\sworks.
-D 2018-05-09T15:20:47.783
+C The\stranslation\sin\sand\sout\sof\sGeoJSON\sautomatically\sadds\sor\sremoves\sthe\nredundant\slast\svertex,\sas\snecessary.
+D 2018-05-09T15:27:35.268
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in bfc40f350586923e0419d2ea4b559c37ec10ee4b6e210e08c14401f8e340f0da
@@ -279,7 +279,7 @@ F ext/misc/dbdump.c 69ef1be5b210538f77dfcc6fcb55b4b5f5e98b1e0bcfd67d818711e10761
 F ext/misc/eval.c 6ea9b22a5fa0dd973b67ca4e53555be177bc0b7b263aadf1024429457c82c0e3
 F ext/misc/fileio.c 48c7751c78fc4cdd29d8c862fd2f3f98bbfefa2a3cf1ca1496df4bf02eb8cded
 F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25
-F ext/misc/geopoly.c 6f2fe66fdb97d4ed794d3f1ca2f984aa84d2d731704f5d0ec0ed5ef242a921d4
+F ext/misc/geopoly.c 5c980f724ac01d075ecadd0b6e8e009224c62cb723f0d972f0d620eeb4397461
 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c
 F ext/misc/json1.c dbe086615b9546c156bf32b9378fc09383b58bd17513b866cfd24c1e15281984
 F ext/misc/memvfs.c ab36f49e02ebcdf85a1e08dc4d8599ea8f343e073ac9e0bca18a98b7e1ec9567
@@ -1729,7 +1729,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 5bb9e6a9f19f9d73314b08afbecb13f46b0cf7b27bfb567960d8f60e3a7a74a1
-R 19ac43755ffa82d1ceb67768a613f870
+P 236588d573a007c9c9eb8e337387d3b6318d19c8b8f260fa7324ed8c4e17060b
+R ce0801999b26c2f522e752eaa60d3a97
 U drh
-Z f8290016445a89aa601b008a34a72134
+Z f8b6d58cd5211c2e2594239d6fddec6f
index 135ebb78dc75fbf44a1943ba3897d5eca2fe446c..0118873a2e2709e8cdf6939f3d2b1e0397c16aff 100644 (file)
@@ -1 +1 @@
-236588d573a007c9c9eb8e337387d3b6318d19c8b8f260fa7324ed8c4e17060b
\ No newline at end of file
+2653bedd9f8237d9ddef533a05e161a6afe6fa4af86fac47407b3df09dc2a9eb
\ No newline at end of file