[OSM-dev] Proposal: Database accelerator and dirty tile marker based on simple algorithm.
Nick Hill
nick at nickhill.co.uk
Wed Sep 20 23:25:44 BST 2006
The following code follows my worked example exactly:
uint64_t nickconvert_1E7(double lat, double lon){
uint64_t result; unsigned int intLat, intLon,count; double
coefficient=10000000;
//First, we convert the number to an unsigned int where the MSB is 1 if
negative
//the very low coefficients compensate for floating point rounding
errors (pedantic=affirmative)
if(lat<0){intLat=(lat-0.000000001)*-1*coefficient+2147483648;}else{intLat=coefficient*(lat+0.000000001);}
if(lon<0){intLon=(lon-0.000000001)*-1*coefficient+2147483648;}else{intLon=coefficient*(lat+0.000000001);}
for(count=(unsigned int)1<<31;count>0; count>>=1){
result<<=2;
result += (intLat & count ?2:0) + (intLon & count ? 1:0);
}
return result;
}
The following code will generate the quadtree tiles as I think you have
in mind:
uint64_t nickconvert_quadtile(double lat, double lon){
uint64_t result; unsigned int intLat, intLon,count;
double coefficient=(2^32)/360;
intLat=lat*coefficient; intLon=lon*coefficient;
for(count=(unsigned int)1<<31;count>0; count>>=1){
result<<=2;
result += (intLat & count ?2:0) + (intLon & count ? 1:0);
}
return result;
}
The quadtile example may provide a convenient platform-created rollover
at the edges.
Nick Hill wrote:
> Hello Nigel
>
> You are correct in representing two approaches to the same problem.
> Yours being to recursively sub-divide the planet, mine being to convert
> the lat/lon values through binary manipulation to the same conclusion.
>
More information about the dev
mailing list