SQLite

Check-in [b37625e8e4]
Login

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
Timelines: family | ancestors | descendants | both | geojson
Files: files | file ages | folders
SHA3-256: b37625e8e469f8856b19acabe9a6628322cba2e76d478da18caff4d9613ab5e6
User & Date: drh 2018-05-11 15:38:03.123
Context
2018-05-11
16:50
Add the geopoly_within() SQL function. (check-in: 927d52a93c user: drh tags: geojson)
15:38
Add the geopoly_read() SQL function to the geopoly.c extension. (check-in: b37625e8e4 user: drh tags: geojson)
14:02
Fix a typo in the help message from the ".sha3sum" command in the CLI. (check-in: e76f676c12 user: drh tags: geojson)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/misc/geopoly.c.
337
338
339
340
341
342
343
344


345
346
347
348
349
350















351
352
353
354
355
356
357
}


/*
** Implementation of the geopoly_area(X) function.
**
** If the input is a well-formed Geopoly BLOB then return the area
** enclosed by the polygon.  Otherwise return NULL.


*/
static void geopolyAreaFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){















}


#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_geopoly_init(







|
>
>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
}


/*
** Implementation of the geopoly_area(X) function.
**
** If the input is a well-formed Geopoly BLOB then return the area
** enclosed by the polygon.  If the polygon circulates clockwise instead
** of counterclockwise (as it should) then return the negative of the
** enclosed area.  Otherwise return NULL.
*/
static void geopolyAreaFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  GeoPoly *p = geopolyFuncParam(context, argv[0]);
  if( p ){
    double rArea = 0.0;
    int ii;
    for(ii=0; ii<p->nVertex-1; ii++){
      rArea += (p->a[ii*2] - p->a[ii*2+2])           /* (x0 - x1) */
                * (p->a[ii*2+1] + p->a[ii*2+3])      /* (y0 + y1) */
                * 0.5;
    }
    rArea += (p->a[ii*2] - p->a[0])                  /* (xN - x0) */
             * (p->a[ii*2+1] + p->a[1])              /* (yN + y0) */
             * 0.5;
    sqlite3_result_double(context, rArea);
    sqlite3_free(p);
  }            
}


#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_geopoly_init(