I made a patch which seems to do this for you...once in a while it's fun to do
a bit of programming like this...I didn't do extensive testing on this so you
may want to do some yourself.
It's going to just about double the RTREE size of course.
SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE VIRTUAL TABLE demo_index USING rtree(
...> id, -- Integer primary key
...> minX, maxX, -- Minimum and maximum X coordinate
...> minY, maxY -- Minimum and maximum Y coordinate
...> );
sqlite> INSERT INTO demo_index VALUES(
...> 1, -- Primary key
...> -80.7749, -80.7747, -- Longitude range
...> 30.3776, 30.3778 -- Latitude range
...> );
sqlite> INSERT INTO demo_index VALUES(
...> 2,
...> -81.0, -79.6,
...> 35.0, 36.2
...> );
sqlite> INSERT INTO demo_index VALUES(3,-80.77491234,-80.77471234,30.37761234,30
.37781234);
sqlite> select * from demo_index;
1|-80.7749|-80.7747|30.3776|30.3778
2|-81.0|-79.6|35.0|36.2
3|-80.77491234|-80.77471234|30.37761234|30.37781234
Use this switch to enable double precision on RTREE
/DRTREE_DOUBLE
*** ..\..\sqlite3.c Thu Oct 07 22:36:26 2010
--- sqlite3.c Tue Nov 02 10:43:16 2010
***************
*** 116902,116909 ****
--- 116902,116914 ----
};
union RtreeCoord {
+ #ifndef RTREE_DOUBLE
float f;
int i;
+ #else
+ double f;
+ u64 i;
+ #endif
};
/*
***************
*** 117006,117011 ****
--- 117011,117017 ----
return (p[0]<<8) + p[1];
}
static void readCoord(u8 *p, RtreeCoord *pCoord){
+ #ifndef RTREE_DOUBLE
u32 i = (
(((u32)p[0]) << 24) +
(((u32)p[1]) << 16) +
***************
*** 117013,117018 ****
--- 117019,117037 ----
(((u32)p[3]) << 0)
);
*(u32 *)pCoord = i;
+ #else
+ u64 i = (
+ (((u64)p[0]) << 56) +
+ (((u64)p[1]) << 48) +
+ (((u64)p[2]) << 40) +
+ (((u64)p[3]) << 32) +
+ (((u64)p[4]) << 24) +
+ (((u64)p[5]) << 16) +
+ (((u64)p[6]) << 8) +
+ (((u64)p[7]) << 0)
+ );
+ *(u64 *)pCoord = i;
+ #endif
}
static i64 readInt64(u8 *p){
return (
***************
*** 117038,117043 ****
--- 117057,117063 ----
return 2;
}
static int writeCoord(u8 *p, RtreeCoord *pCoord){
+ #ifndef RTREE_DOUBLE
u32 i;
assert( sizeof(RtreeCoord)==4 );
assert( sizeof(u32)==4 );
***************
*** 117047,117052 ****
--- 117067,117087 ----
p[2] = (i>> 8)&0xFF;
p[3] = (i>> 0)&0xFF;
return 4;
+ #else
+ u64 i;
+ assert( sizeof(RtreeCoord)==8 );
+ assert( sizeof(u64)==8 );
+ i = *(u64 *)pCoord;
+ p[0] = (i>>56)&0xFF;
+ p[1] = (i>>48)&0xFF;
+ p[2] = (i>>40)&0xFF;
+ p[3] = (i>>32)&0xFF;
+ p[4] = (i>>24)&0xFF;
+ p[5] = (i>>16)&0xFF;
+ p[6] = (i>> 8)&0xFF;
+ p[7] = (i>> 0)&0xFF;
+ return 8;
+ #endif
}
static int writeInt64(u8 *p, i64 i){
p[0] = (i>>56)&0xFF;
***************
*** 117365,117371 ****
--- 117400,117410 ----
int iCoord,
RtreeCoord *pCoord /* Space to write result to */
){
+ #ifndef RTREE_DOUBLE
readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord],
pCoord);
+ #else
+ readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 8*iCoord],
pCoord);
+ #endif
}
/*
***************
*** 119463,119470 ****
--- 119502,119514 ----
assert( nData==(pRtree->nDim*2 + 3) );
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
for(ii=0; ii<(pRtree->nDim*2); ii+=2){
+ #ifndef RTREE_DOUBLE
cell.aCoord[ii].f = (float)sqlite3_value_double(azData[ii+3]);
cell.aCoord[ii+1].f = (float)sqlite3_value_double(azData[ii+4]);
+ #else
+ cell.aCoord[ii].f = sqlite3_value_double(azData[ii+3]);
+ cell.aCoord[ii+1].f = sqlite3_value_double(azData[ii+4]);
+ #endif
if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
rc = SQLITE_CONSTRAINT;
goto constraint;
***************
*** 119746,119752 ****
--- 119790,119800 ----
pRtree->zDb = (char *)&pRtree[1];
pRtree->zName = &pRtree->zDb[nDb+1];
pRtree->nDim = (argc-4)/2;
+ #ifndef RTREE_DOUBLE
pRtree->nBytesPerCell = 8 + pRtree->nDim*4*2;
+ #else
+ pRtree->nBytesPerCell = 8 + pRtree->nDim*8*2;
+ #endif
pRtree->eCoordType = eCoordType;
memcpy(pRtree->zDb, argv[1], nDb);
memcpy(pRtree->zName, argv[2], nName);
***************
*** 119818,119824 ****
--- 119866,119877 ----
memset(&node, 0, sizeof(RtreeNode));
memset(&tree, 0, sizeof(Rtree));
tree.nDim = sqlite3_value_int(apArg[0]);
+ #ifndef RTREE_DOUBLE
tree.nBytesPerCell = 8 + 8 * tree.nDim;
+ #else
+ tree.nBytesPerCell = 8 + 16 * tree.nDim;
+ #endif
+
node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
for(ii=0; ii<NCELL(&node); ii++){
Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Northrop Grumman Information Systems
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users