Skip to content

Commit

Permalink
Fix a bug in file geohash/geohash.c
Browse files Browse the repository at this point in the history
Add missing bit shifts in the function geohashstr_to_interleaved in order to be able to calculate correctly the  
    1) geo coordinates from a given geohash and 
    2) neigbor geohashes of a given geohash.

The incorrect calculation of neighbor geohashes e.g. has the following impact on the deduplication with lieu: Features are compared that should not be compared because they are too far away from each other. This often results in distances between duplicates that exceed by far the max. expected distance according to the used geohash precision.
  • Loading branch information
in-cloud-opensource authored Dec 12, 2019
1 parent 95bf70e commit ed41f42
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/geohash/geohash.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,28 @@ static int geohashstr_to_interleaved(char *r, size_t length, uint16_t *interleav
if(j== 0) i[0] = map[c[ 0]]<<11;
if(j== 1) i[0] += map[c[ 1]]<< 6;
if(j== 2) i[0] += map[c[ 2]]<< 1;
if(j== 3) i[0] += map[c[ 3]]>> 4;
if(j== 3) {
i[0] += map[c[ 3]]>> 4;
i[1] = map[c[ 3]]<<12;
}
if(j== 4) i[1] += map[c[ 4]]<< 7;
if(j== 5) i[1] += map[c[ 5]]<< 2;
if(j== 6) i[1] += map[c[ 6]]>> 3;
if(j== 6) {
i[1] += map[c[ 6]]>> 3;
i[2] = map[c[ 6]]<<13;
}
if(j== 7) i[2] += map[c[ 7]]<< 8;
if(j== 8) i[2] += map[c[ 8]]<< 3;
if(j== 9) i[2] += map[c[ 9]]>> 2;
if(j== 9) {
i[2] += map[c[ 9]]>> 2;
i[3] = map[c[ 9]]<<14;
}
if(j==10) i[3] += map[c[10]]<< 9;
if(j==11) i[3] += map[c[11]]<< 4;
if(j==12) i[3] += map[c[12]]>> 1;
if(j==12) {
i[3] += map[c[12]]>> 1;
i[4] = map[c[12]]<<15;
}
if(j==13) i[4] += map[c[13]]<<10;
if(j==14) i[4] += map[c[14]]<< 5;
if(j==15) i[4] += map[c[15]]>> 0;
Expand Down Expand Up @@ -514,4 +526,4 @@ int geohash_neighbors(char *hashcode, char *dst, size_t dst_length, int *string_
}

return GEOHASH_OK;
}
}

0 comments on commit ed41f42

Please sign in to comment.