From: drh Date: Wed, 9 May 2018 15:00:36 +0000 (+0000) Subject: Add the geopoly_json() interface. Untested. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0568e4101208bcfa981b4b2f2f59ef658575bd09;p=thirdparty%2Fsqlite.git Add the geopoly_json() interface. Untested. FossilOrigin-Name: 25695c80a01d18bc533d6c741076452dfc0063b1e632da346e254062ec01acbe --- diff --git a/ext/misc/geopoly.c b/ext/misc/geopoly.c index caf856a037..12476971d9 100644 --- a/ext/misc/geopoly.c +++ b/ext/misc/geopoly.c @@ -302,9 +302,37 @@ static void geopolyBlobFunc( if( p ){ sqlite3_result_blob(context, p->hdr, 4+8*p->nVertex, SQLITE_TRANSIENT); + sqlite3_free(p); } } +/* +** SQL function: geopoly_json(X) +** +** Interpret X as a polygon and render it as a JSON array +** of coordinates. Or, if X is not a valid polygon, return NULL. +*/ +static void geopolyJsonFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + GeoPoly *p = geopolyFuncParam(context, argv[0]); + if( p ){ + sqlite3 *db = sqlite3_context_db_pointer(context); + sqlite3_str *x = sqlite3_str_new(db); + int i; + sqlite3_str_append(x, "[", 1); + for(i=0; inVertex; 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_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free); + sqlite3_free(p); + } +} + + /* ** Implementation of the geopoly_area(X) function. ** @@ -335,6 +363,7 @@ int sqlite3_geopoly_init( } aFunc[] = { { geopolyAreaFunc, 1, "geopoly_area" }, { geopolyBlobFunc, 1, "geopoly_blob" }, + { geopolyJsonFunc, 1, "geopoly_json" }, }; int i; SQLITE_EXTENSION_INIT2(pApi); diff --git a/manifest b/manifest index 730df958af..e86adf5c12 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\schanges,\sand\sespecially\sthe\snewly\spublished\ssqlite3_str\sinterface. -D 2018-05-09T14:33:54.780 +C Add\sthe\sgeopoly_json()\sinterface.\s\sUntested. +D 2018-05-09T15:00:36.551 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 f6a4953a410e5056e9dc6680f7c0c3351939c2bbdfd1cf61925a2198e08a22e9 +F ext/misc/geopoly.c 4b2bd1bec87c687e4156826e971ef4890a7387b7f9fcbe57a1088d432483579e 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 d22fbff2a3dcda4bd5febd36325e4d543b8756eb9c96891ff0c610e16a52ef52 43ea8a6836ccb9910314d35e07d881694200c97ef5969629f62e49f7a2a42f92 -R 5dd3738e573a1c6c8ecc6bb4a25bb591 +P f3609aefe877544c93c556840fe9a129f0680681eea0c64c084b20217dd2191e +R dcdac1776ea78ea7472ff7a0677655bb U drh -Z 9f375a6b8f3ff34711642d3316f97a85 +Z 0605743283407c8ba6d4bf76a23108f0 diff --git a/manifest.uuid b/manifest.uuid index 591844c51b..08afa8abc1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f3609aefe877544c93c556840fe9a129f0680681eea0c64c084b20217dd2191e \ No newline at end of file +25695c80a01d18bc533d6c741076452dfc0063b1e632da346e254062ec01acbe \ No newline at end of file