forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ElasticSearch: decode geohash values in a geo_point field
git-svn-id: https://svn.osgeo.org/gdal/trunk@29776 f0d54148-0727-0410-94bb-9a71ac55c965
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -954,6 +954,38 @@ OGRFeature *OGRElasticLayer::GetNextRawFeature() | |
return NULL; | ||
} | ||
|
||
/************************************************************************/ | ||
/* decode_geohash_bbox() */ | ||
/************************************************************************/ | ||
|
||
/* Derived from routine from https://github.com/davetroy/geohash/blob/master/ext/geohash_native.c */ | ||
/* (c) 2008-2010 David Troy, [email protected], (The MIT License) */ | ||
|
||
static const char BASE32[] = "0123456789bcdefghjkmnpqrstuvwxyz"; | ||
|
||
static void decode_geohash_bbox(const char *geohash, double lat[2], double lon[2]) | ||
{ | ||
int i, j, hashlen; | ||
char c, cd, mask, is_even=1; | ||
static const char bits[] = {16,8,4,2,1}; | ||
lat[0] = -90.0; lat[1] = 90.0; | ||
lon[0] = -180.0; lon[1] = 180.0; | ||
hashlen = strlen(geohash); | ||
for (i=0; i<hashlen; i++) { | ||
c = tolower(geohash[i]); | ||
cd = strchr(BASE32, c)-BASE32; | ||
for (j=0; j<5; j++) { | ||
mask = bits[j]; | ||
if (is_even) { | ||
lon[!(cd&mask)] = (lon[0] + lon[1])/2; | ||
} else { | ||
lat[!(cd&mask)] = (lat[0] + lat[1])/2; | ||
} | ||
is_even = !is_even; | ||
} | ||
} | ||
} | ||
|
||
/************************************************************************/ | ||
/* BuildFeature() */ | ||
/************************************************************************/ | ||
|
@@ -1102,7 +1134,13 @@ void OGRElasticLayer::BuildFeature(OGRFeature* poFeature, json_object* poSource, | |
poGeom = new OGRPoint( CPLAtof(papszTokens[1]), | ||
CPLAtof(papszTokens[0]) ); | ||
} | ||
// TODO decode if stored as a geohash string ? | ||
else | ||
{ | ||
double lat[2], lon[2]; | ||
decode_geohash_bbox(pszLatLon, lat, lon); | ||
poGeom = new OGRPoint( (lon[0] + lon[1]) / 2, | ||
(lat[0] + lat[1]) / 2 ); | ||
} | ||
|
||
CSLDestroy(papszTokens); | ||
} | ||
|