by wangsh 2011-11-15
isnan问题:在GIS开发中,我们计算两点之间距离之后,需要判断距离是否isnan(
double dist = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371.0;)。
并不是所有的编译器都有isnan,vs2008中没有isnan,在合适的地方加入:
inline bool isnan(double v)
{
return v!=v;
}
这时候完整代码段为:
/* Return distance in km */
double fast_distance_rad(double lat1, double lon1, double lat2, double lon2)
{
double dist = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371.0;
if(isnan(dist))
{
dist = 0;
}
return dist;
}
hash_map的使用:hash_map基于hash table,其最大优点是降低数据存储与查找消耗时间,可近似为常数时间;而代价仅是消耗较多内存。而在当前可利用内存越来越多的情况下,用空间换时间的做法是值得的。(具体参考1和2)
使用hash_map例:
#include <hash_map>
using namespace std;
using namespace stdext;
typedef stdext::hash_map<int, GPSCoordinate>::value_type hashGPS;
参考资料
1. Blog http://www.cppblog.com/woaidongmao/archive/2008/10/15/64014.html
2. 介绍 http://blog.csdn.net/ztj111/article/details/1895200
3. 性能比较 http://hi.baidu.com/lujunqianglw/blog/item/9f7fbc549233cd063b293582.html