Skip to content

Commit efdfd6c

Browse files
committed
[GEOADD]:all coordinates convert to mercator first
1 parent 2615cc4 commit efdfd6c

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ CXXFLAGS=-Wall -g ${OPT} -fPIC -D__STDC_FORMAT_MACROS -DARDB_VERSION='"${ARDB_VE
8787
CCFLAGS=-Wall -std=gnu99 ${OPT} -fPIC -pedantic -g -D__STDC_FORMAT_MACROS -DARDB_VERSION='"${ARDB_VERSION}"'
8888
LDFLAGS=-g
8989

90+
9091
LUA_CFLAGS+= -O2 -Wall -DLUA_ANSI $(CCFLAGS)
9192
LUA_LDFLAGS+= $(LDFLAGS)
9293

@@ -268,8 +269,7 @@ rocksdb: $(ROCKSDB_LIBA)
268269
$(ROCKSDB_LIBA): $(SNAPPY_LIBA) $(ROCKSDB_PATH)
269270
echo ">>>>> Building ROCKSDB" && \
270271
cd ${ROCKSDB_PATH} && \
271-
patch -p0 < ../../patch/rocksdb-3.4.patch && \
272-
CXXFLAGS="-I${SNAPPY_PATH}" CFLAGS="-I${SNAPPY_PATH}" LDFLAGS="${SNAPPY_PATH}/.libs" $(MAKE) librocksdb.a && \
272+
CXXFLAGS="-I${SNAPPY_PATH} -O2 -DNDEBUG" CFLAGS="-I${SNAPPY_PATH}" LDFLAGS="${SNAPPY_PATH}/.libs" $(MAKE) librocksdb.a && \
273273
echo "<<<<< Done building ROCKSDB"
274274

275275
$(ROCKSDB_PATH):

src/command/geo.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ namespace ardb
4747
return 0;
4848
}
4949
GeoHashRange lat_range, lon_range;
50-
GeoHashHelper::GetCoordRange(options.coord_type, lat_range, lon_range);
50+
//GeoHashHelper::GetCoordRange(options.coord_type, lat_range, lon_range);
51+
GeoHashHelper::GetCoordRange(GEO_MERCATOR_TYPE, lat_range, lon_range);
5152

5253
KeyLockerGuard keylock(m_key_lock, ctx.currentDB, cmd.GetArguments()[0]);
5354
ValueObject meta;
@@ -62,6 +63,14 @@ namespace ardb
6263
while (git != options.points.end())
6364
{
6465
GeoPoint& point = *git;
66+
/*
67+
* Always to store mercator coordinates since it's easy&fast to compare distance in 'geosearch'
68+
*/
69+
if(options.coord_type == GEO_WGS84_TYPE)
70+
{
71+
point.x = GeoHashHelper::GetMercatorX(point.x);
72+
point.y = GeoHashHelper::GetMercatorY(point.y);
73+
}
6574
if (point.x < lon_range.min || point.x > lon_range.max || point.y < lat_range.min
6675
|| point.y > lat_range.max)
6776
{
@@ -202,6 +211,7 @@ namespace ardb
202211
return -1;
203212
}
204213
GeoHashHelper::GetMercatorXYByHash(score.value.iv, x, y);
214+
//GeoHashHelper::GetXYByHash(score.value.iv, x, y);
205215
}
206216
else
207217
{
@@ -223,15 +233,13 @@ namespace ardb
223233
StringSet::iterator it = options.submembers.begin();
224234
while (it != options.submembers.end())
225235
{
226-
//GeoPoint point;
227236
Data element, score;
228237
element.SetString(*it, true);
229238
Location loc;
230239
ret = ZSetScore(ctx, meta, element, score, &loc);
231240
if (0 == ret)
232241
{
233242
fetch_options.results.push_back(element);
234-
//fetch_options.results.push_back(score);
235243
fetch_options.locs.push_back(loc);
236244
}
237245
it++;

src/common/geo/geohash_helper.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ namespace ardb
439439
distance = distanceEarth(y1, x1, y2, x2);
440440
if (distance > radius)
441441
{
442-
if(std::abs(distance - radius) > std::abs(accurace))
442+
if (std::abs(distance - radius) > std::abs(accurace))
443443
{
444444
return false;
445445
}
@@ -473,10 +473,10 @@ namespace ardb
473473
return true;
474474
}
475475

476-
bool GeoHashHelper::GetMercatorXYByHash(GeoHashFix60Bits hash, double& x, double& y)
476+
bool GeoHashHelper::GetXYByHash(uint8 coord_type, GeoHashFix60Bits hash, double& x, double& y)
477477
{
478478
GeoHashRange lat_range, lon_range;
479-
GeoHashHelper::GetCoordRange(GEO_MERCATOR_TYPE, lat_range, lon_range);
479+
GeoHashHelper::GetCoordRange(coord_type, lat_range, lon_range);
480480
GeoHashBits hashbits;
481481
hashbits.bits = hash;
482482
hashbits.step = 30;
@@ -492,5 +492,10 @@ namespace ardb
492492
return false;
493493
}
494494
}
495+
496+
bool GeoHashHelper::GetMercatorXYByHash(GeoHashFix60Bits hash, double& x, double& y)
497+
{
498+
return GetXYByHash(GEO_MERCATOR_TYPE, hash, x, y);
499+
}
495500
}
496501

src/common/geo/geohash_helper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ namespace ardb
7676
static bool GetDistanceSquareIfInRadius(uint8 coord_type, double x1, double y1, double x2, double y2, double radius, double& distance, double accurace);
7777

7878
static bool GetMercatorXYByHash(GeoHashFix60Bits hash, double& x, double& y);
79+
static bool GetXYByHash(uint8 coord_type, GeoHashFix60Bits hash, double& x, double& y);
7980
};
8081
}
8182

0 commit comments

Comments
 (0)