1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add the geopoly_reverse() function to the GeoPoly extension.

FossilOrigin-Name: 690dd18a5768c5a8cdfa92d5b01901c1a7b1fb6ebb90399f56a3112e41609f92
This commit is contained in:
drh
2018-10-08 12:58:59 +00:00
parent 488cddfa86
commit bc36320f02
3 changed files with 38 additions and 7 deletions

View File

@ -494,6 +494,36 @@ static void geopolyAreaFunc(
}
}
/*
** Implementation of the geopoly_reverse(X) function.
**
** Reverse the order of the vertexes in polygon X. This can be used
** to convert an historical polygon that uses a clockwise rotation into
** a well-formed GeoJSON polygon that uses counter-clockwise rotation.
*/
static void geopolyReverseFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
if( p ){
int ii, jj;
for(ii=2, jj=p->nVertex*2 - 4; ii<jj; ii+=2, jj-=2){
GeoCoord t = p->a[ii];
p->a[ii] = p->a[jj];
p->a[jj] = t;
t = p->a[ii+1];
p->a[ii+1] = p->a[jj+1];
p->a[jj+1] = t;
}
sqlite3_result_blob(context, p->hdr,
4+8*p->nVertex, SQLITE_TRANSIENT);
sqlite3_free(p);
}
}
#define GEOPOLY_PI 3.1415926535897932385
/* Fast approximation for cosine(X) for X between -0.5*pi and 2*pi
@ -1721,6 +1751,7 @@ static int sqlite3_geopoly_init(sqlite3 *db){
{ geopolyBBoxFunc, 1, 1, "geopoly_bbox" },
{ geopolyXformFunc, 7, 1, "geopoly_xform" },
{ geopolyRegularFunc, 4, 1, "geopoly_regular" },
{ geopolyReverseFunc, 1, 1, "geopoly_reverse" },
};
static const struct {
void (*xStep)(sqlite3_context*,int,sqlite3_value**);