36 #define QUAD_EARTH_RADIUS_METRES 6372797.6 49 double min_dist = 0.0;
50 bool have_min =
false;
59 double dist = pointwise_distance(*a_iter, *b_iter);
63 }
else if (dist < min_dist) {
73 const char* b_ptr,
size_t b_len)
const 75 if (a.
empty() || b_len == 0) {
78 double min_dist = 0.0;
79 bool have_min =
false;
81 const char * b_end = b_ptr + b_len;
82 while (b_ptr != b_end) {
88 double dist = pointwise_distance(*a_iter, b);
92 }
else if (dist < min_dist) {
113 double lata = a.
latitude * (M_PI / 180.0);
114 double latb = b.
latitude * (M_PI / 180.0);
116 double latdiff = lata - latb;
119 double sin_half_lat = sin(latdiff / 2);
120 double sin_half_long = sin(longdiff / 2);
121 double h = sin_half_lat * sin_half_lat +
122 sin_half_long * sin_half_long * cos(lata) * cos(latb);
127 return 2 *
radius * asin(sqrt(h));
139 return "Xapian::GreatCircleMetric";
151 const char * p = s.data();
152 const char * end = p + s.size();
The Xapian namespace contains public interfaces for the Xapian library.
double radius
The radius of the sphere in metres.
double pointwise_distance(const LatLongCoord &a, const LatLongCoord &b) const
Return the great-circle distance between points on the sphere.
bool empty() const
Return true if and only if there are no coordinates in the container.
std::string serialise() const
Serialise object parameters into a string.
double operator()(const LatLongCoords &a, const LatLongCoords &b) const
Return the distance between two coordinate lists, in metres.
std::string name() const
Return the full name of the metric.
Hierarchy of classes which Xapian can throw as exceptions.
functions to serialise and unserialise a double
InvalidArgumentError indicates an invalid parameter value was passed to the API.
LatLongCoordsIterator begin() const
Get a begin iterator for the coordinates.
A latitude-longitude coordinate.
double unserialise_double(const char **p, const char *end)
Unserialise a double serialised by serialise_double.
Geospatial search support routines.
void unserialise(const std::string &serialised)
Unserialise a string and set this object to its coordinate.
virtual ~LatLongMetric()
Destructor.
double latitude
A latitude, as decimal degrees.
Base class for calculating distances between two lat/long coordinates.
GreatCircleMetric()
Construct a GreatCircleMetric.
A sequence of latitude-longitude coordinates.
LatLongMetric * unserialise(const std::string &serialised) const
Create object given string serialisation returned by serialise().
std::string serialise_double(double v)
Serialise a double to a string.
An iterator across the values in a LatLongCoords object.
LatLongMetric * clone() const
Clone the metric.
Indicates a problem communicating with a remote database.
LatLongCoordsIterator end() const
Get an end iterator for the coordinates.
#define QUAD_EARTH_RADIUS_METRES
Quadratic mean radius of the Earth in metres.
double longitude
A longitude, as decimal degrees.