Skip to content

Commit

Permalink
[GEOADD]:all coordinates convert to mercator first
Browse files Browse the repository at this point in the history
  • Loading branch information
yinqiwen committed Sep 19, 2014
1 parent 2615cc4 commit efdfd6c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ CXXFLAGS=-Wall -g ${OPT} -fPIC -D__STDC_FORMAT_MACROS -DARDB_VERSION='"${ARDB_VE
CCFLAGS=-Wall -std=gnu99 ${OPT} -fPIC -pedantic -g -D__STDC_FORMAT_MACROS -DARDB_VERSION='"${ARDB_VERSION}"'
LDFLAGS=-g


LUA_CFLAGS+= -O2 -Wall -DLUA_ANSI $(CCFLAGS)
LUA_LDFLAGS+= $(LDFLAGS)

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

$(ROCKSDB_PATH):
Expand Down
14 changes: 11 additions & 3 deletions src/command/geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace ardb
return 0;
}
GeoHashRange lat_range, lon_range;
GeoHashHelper::GetCoordRange(options.coord_type, lat_range, lon_range);
//GeoHashHelper::GetCoordRange(options.coord_type, lat_range, lon_range);
GeoHashHelper::GetCoordRange(GEO_MERCATOR_TYPE, lat_range, lon_range);

KeyLockerGuard keylock(m_key_lock, ctx.currentDB, cmd.GetArguments()[0]);
ValueObject meta;
Expand All @@ -62,6 +63,14 @@ namespace ardb
while (git != options.points.end())
{
GeoPoint& point = *git;
/*
* Always to store mercator coordinates since it's easy&fast to compare distance in 'geosearch'
*/
if(options.coord_type == GEO_WGS84_TYPE)
{
point.x = GeoHashHelper::GetMercatorX(point.x);
point.y = GeoHashHelper::GetMercatorY(point.y);
}
if (point.x < lon_range.min || point.x > lon_range.max || point.y < lat_range.min
|| point.y > lat_range.max)
{
Expand Down Expand Up @@ -202,6 +211,7 @@ namespace ardb
return -1;
}
GeoHashHelper::GetMercatorXYByHash(score.value.iv, x, y);
//GeoHashHelper::GetXYByHash(score.value.iv, x, y);
}
else
{
Expand All @@ -223,15 +233,13 @@ namespace ardb
StringSet::iterator it = options.submembers.begin();
while (it != options.submembers.end())
{
//GeoPoint point;
Data element, score;
element.SetString(*it, true);
Location loc;
ret = ZSetScore(ctx, meta, element, score, &loc);
if (0 == ret)
{
fetch_options.results.push_back(element);
//fetch_options.results.push_back(score);
fetch_options.locs.push_back(loc);
}
it++;
Expand Down
11 changes: 8 additions & 3 deletions src/common/geo/geohash_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ namespace ardb
distance = distanceEarth(y1, x1, y2, x2);
if (distance > radius)
{
if(std::abs(distance - radius) > std::abs(accurace))
if (std::abs(distance - radius) > std::abs(accurace))
{
return false;
}
Expand Down Expand Up @@ -473,10 +473,10 @@ namespace ardb
return true;
}

bool GeoHashHelper::GetMercatorXYByHash(GeoHashFix60Bits hash, double& x, double& y)
bool GeoHashHelper::GetXYByHash(uint8 coord_type, GeoHashFix60Bits hash, double& x, double& y)
{
GeoHashRange lat_range, lon_range;
GeoHashHelper::GetCoordRange(GEO_MERCATOR_TYPE, lat_range, lon_range);
GeoHashHelper::GetCoordRange(coord_type, lat_range, lon_range);
GeoHashBits hashbits;
hashbits.bits = hash;
hashbits.step = 30;
Expand All @@ -492,5 +492,10 @@ namespace ardb
return false;
}
}

bool GeoHashHelper::GetMercatorXYByHash(GeoHashFix60Bits hash, double& x, double& y)
{
return GetXYByHash(GEO_MERCATOR_TYPE, hash, x, y);
}
}

1 change: 1 addition & 0 deletions src/common/geo/geohash_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace ardb
static bool GetDistanceSquareIfInRadius(uint8 coord_type, double x1, double y1, double x2, double y2, double radius, double& distance, double accurace);

static bool GetMercatorXYByHash(GeoHashFix60Bits hash, double& x, double& y);
static bool GetXYByHash(uint8 coord_type, GeoHashFix60Bits hash, double& x, double& y);
};
}

Expand Down

0 comments on commit efdfd6c

Please sign in to comment.