/ Check-in [318ba5f0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the geopoly_svg() SQL function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | geojson
Files: files | file ages | folders
SHA3-256:318ba5f0c52596fc5ceed23a2b7b1ca18644449809890bfed47ab4ee01075060
User & Date: drh 2018-05-12 21:09:31
Context
2018-05-12
23:31
Resolve issues with floating-point round-off error in the geopoly_overlap() routine. check-in: a3c6696f user: drh tags: geojson
21:09
Add the geopoly_svg() SQL function. check-in: 318ba5f0 user: drh tags: geojson
20:28
Preliminary tests show geopoly_overlap() is working. check-in: 77bb7b7d user: drh tags: geojson
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/geopoly.c.

   341    341       }
   342    342       sqlite3_str_appendf(x, "[%!g,%!g]]", p->a[0], p->a[1]);
   343    343       sqlite3_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free);
   344    344       sqlite3_free(p);
   345    345     }
   346    346   }
   347    347   
          348  +/*
          349  +** SQL function:     geopoly_svg(X, ....)
          350  +**
          351  +** Interpret X as a polygon and render it as a SVG <polyline>.
          352  +** Additional arguments are added as attributes to the <polyline>.
          353  +*/
          354  +static void geopolySvgFunc(
          355  +  sqlite3_context *context,
          356  +  int argc,
          357  +  sqlite3_value **argv
          358  +){
          359  +  GeoPoly *p = geopolyFuncParam(context, argv[0]);
          360  +  if( p ){
          361  +    sqlite3 *db = sqlite3_context_db_handle(context);
          362  +    sqlite3_str *x = sqlite3_str_new(db);
          363  +    int i;
          364  +    char cSep = '\'';
          365  +    sqlite3_str_appendf(x, "<polyline points=");
          366  +    for(i=0; i<p->nVertex; i++){
          367  +      sqlite3_str_appendf(x, "%c%g,%g", cSep, p->a[i*2], p->a[i*2+1]);
          368  +      cSep = ' ';
          369  +    }
          370  +    sqlite3_str_appendf(x, " %g,%g'", p->a[0], p->a[1]);
          371  +    for(i=1; i<argc; i++){
          372  +      const char *z = (const char*)sqlite3_value_text(argv[i]);
          373  +      if( z && z[0] ){
          374  +        sqlite3_str_appendf(x, " %s", z);
          375  +      }
          376  +    }
          377  +    sqlite3_str_appendf(x, "></polyline>");
          378  +    sqlite3_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free);
          379  +    sqlite3_free(p);
          380  +  }
          381  +}
   348    382   
   349    383   /*
   350    384   ** Implementation of the geopoly_area(X) function.
   351    385   **
   352    386   ** If the input is a well-formed Geopoly BLOB then return the area
   353    387   ** enclosed by the polygon.  If the polygon circulates clockwise instead
   354    388   ** of counterclockwise (as it should) then return the negative of the
................................................................................
   807    841       void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
   808    842       int nArg;
   809    843       const char *zName;
   810    844     } aFunc[] = {
   811    845        { geopolyAreaFunc,          1,    "geopoly_area"     },
   812    846        { geopolyBlobFunc,          1,    "geopoly_blob"     },
   813    847        { geopolyJsonFunc,          1,    "geopoly_json"     },
          848  +     { geopolySvgFunc,          -1,    "geopoly_svg"      },
   814    849        { geopolyWithinFunc,        3,    "geopoly_within"   },
   815    850        { geopolyOverlapFunc,       2,    "geopoly_overlap"  },
   816    851        { geopolyDebugFunc,         1,    "geopoly_debug"    },
   817    852     };
   818    853     int i;
   819    854     SQLITE_EXTENSION_INIT2(pApi);
   820    855     (void)pzErrMsg;  /* Unused parameter */