/ Check-in [b37625e8]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Add the geopoly_read() SQL function to the geopoly.c extension.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | geojson
Files: files | file ages | folders
SHA3-256: b37625e8e469f8856b19acabe9a6628322cba2e76d478da18caff4d9613ab5e6
User & Date: drh 2018-05-11 15:38:03
Context
2018-05-11
16:50
Add the geopoly_within() SQL function. check-in: 927d52a9 user: drh tags: geojson
15:38
Add the geopoly_read() SQL function to the geopoly.c extension. check-in: b37625e8 user: drh tags: geojson
14:02
Fix a typo in the help message from the ".sha3sum" command in the CLI. check-in: e76f676c user: drh tags: geojson
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/geopoly.c.

   337    337   }
   338    338   
   339    339   
   340    340   /*
   341    341   ** Implementation of the geopoly_area(X) function.
   342    342   **
   343    343   ** If the input is a well-formed Geopoly BLOB then return the area
   344         -** enclosed by the polygon.  Otherwise return NULL.
          344  +** enclosed by the polygon.  If the polygon circulates clockwise instead
          345  +** of counterclockwise (as it should) then return the negative of the
          346  +** enclosed area.  Otherwise return NULL.
   345    347   */
   346    348   static void geopolyAreaFunc(
   347    349     sqlite3_context *context,
   348    350     int argc,
   349    351     sqlite3_value **argv
   350    352   ){
          353  +  GeoPoly *p = geopolyFuncParam(context, argv[0]);
          354  +  if( p ){
          355  +    double rArea = 0.0;
          356  +    int ii;
          357  +    for(ii=0; ii<p->nVertex-1; ii++){
          358  +      rArea += (p->a[ii*2] - p->a[ii*2+2])           /* (x0 - x1) */
          359  +                * (p->a[ii*2+1] + p->a[ii*2+3])      /* (y0 + y1) */
          360  +                * 0.5;
          361  +    }
          362  +    rArea += (p->a[ii*2] - p->a[0])                  /* (xN - x0) */
          363  +             * (p->a[ii*2+1] + p->a[1])              /* (yN + y0) */
          364  +             * 0.5;
          365  +    sqlite3_result_double(context, rArea);
          366  +    sqlite3_free(p);
          367  +  }            
   351    368   }
   352    369   
   353    370   
   354    371   #ifdef _WIN32
   355    372   __declspec(dllexport)
   356    373   #endif
   357    374   int sqlite3_geopoly_init(