23 #ifndef XAPIAN_INCLUDED_GEOSPATIAL_H
24 #define XAPIAN_INCLUDED_GEOSPATIAL_H
26 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
27 # error Never use <xapian/geospatial.h> directly; include <xapian.h> instead.
33 #include <string_view>
56 return 1609.344 * miles;
69 return metres * (1.0 / 1609.344);
126 void unserialise(std::string_view serialised);
139 void unserialise(
const char ** ptr,
const char * end);
143 std::string serialise()
const;
151 if (latitude < other.latitude)
return true;
152 if (latitude > other.latitude)
return false;
153 return (longitude < other.longitude);
157 std::string get_description()
const;
169 std::vector<LatLongCoord>::const_iterator
iter;
200 return iter == other.
iter;
249 return coords.size();
255 return coords.empty();
261 coords.push_back(coord);
270 coords.push_back(coord);
281 void unserialise(std::string_view serialised);
285 std::string serialise()
const;
288 std::string get_description()
const;
338 return (*
this)(a, b.data(), b.
size());
357 const char * b_ptr,
size_t b_len)
const;
372 virtual std::string
name()
const = 0;
426 std::string
name()
const;
427 std::string serialise()
const;
428 LatLongMetric * unserialise(
const std::string & serialised)
const;
474 void calc_distance();
498 double max_range_ = 0.0,
515 double max_range_ = 0.0,
520 void next(
double min_wt);
524 double get_weight()
const;
526 std::string
name()
const;
527 std::string serialise()
const;
529 unserialise_with_registry(
const std::string &serialised,
533 std::string get_description()
const;
579 metric(metric_.clone()),
598 metric(metric_.clone()),
634 metric(metric_.clone()),
654 metric(metric_.clone()),
Compiler attribute macros.
#define XAPIAN_CONST_FUNCTION
A function which does not examine any values except its arguments and has no effects except its retur...
An indexed database of documents.
Class representing a document.
Calculate the great-circle distance between two coordinates on a sphere.
double radius
The radius of the sphere in metres.
Virtual base class for key making functors.
An iterator across the values in a LatLongCoords object.
bool operator==(const LatLongCoordsIterator &other) const
Equality test for LatLongCoordsIterator objects.
const LatLongCoord & operator*() const
Get the LatLongCoord for the current position.
std::vector< LatLongCoord >::const_iterator iter
The current position of the iterator.
std::input_iterator_tag iterator_category
DerefWrapper_< LatLongCoord > operator++(int)
Advance the iterator to the next position (postfix version).
LatLongCoordsIterator()
Default constructor. Produces an uninitialised iterator.
LatLongCoordsIterator & operator++()
Advance the iterator to the next position.
LatLongCoordsIterator(std::vector< LatLongCoord >::const_iterator iter_)
Constructor used by LatLongCoords.
A sequence of latitude-longitude coordinates.
LatLongCoords(const LatLongCoord &coord)
Construct a container holding one coordinate.
LatLongCoords()
Construct an empty container.
size_t size() const
Get the number of coordinates in the container.
LatLongCoordsIterator begin() const
Get a begin iterator for the coordinates.
void append(const LatLongCoord &coord)
Append a coordinate to the end of the sequence.
LatLongCoordsIterator end() const
Get an end iterator for the coordinates.
bool empty() const
Return true if and only if there are no coordinates in the container.
std::vector< LatLongCoord > coords
The coordinates.
KeyMaker subclass which sorts by distance from a latitude/longitude.
LatLongDistanceKeyMaker(Xapian::valueno slot_, const LatLongCoords ¢re_, const LatLongMetric &metric_, double defdistance)
Construct a LatLongDistanceKeyMaker.
LatLongCoords centre
The centre point (or points) for distance calculation.
std::string defkey
The default key to return, for documents with no value stored.
LatLongDistanceKeyMaker(Xapian::valueno slot_, const LatLongCoords ¢re_)
Construct a LatLongDistanceKeyMaker.
Xapian::valueno slot
The value slot to read.
LatLongDistanceKeyMaker(Xapian::valueno slot_, const LatLongCoord ¢re_, const LatLongMetric &metric_, double defdistance)
Construct a LatLongDistanceKeyMaker.
LatLongDistanceKeyMaker(Xapian::valueno slot_, const LatLongCoords ¢re_, const LatLongMetric &metric_)
Construct a LatLongDistanceKeyMaker.
LatLongDistanceKeyMaker(Xapian::valueno slot_, const LatLongCoord ¢re_)
Construct a LatLongDistanceKeyMaker.
const LatLongMetric * metric
The metric to use when calculating distances.
LatLongDistanceKeyMaker(Xapian::valueno slot_, const LatLongCoord ¢re_, const LatLongMetric &metric_)
Construct a LatLongDistanceKeyMaker.
Posting source which returns a weight based on geospatial distance.
double k1
Constant used in weighting function.
double k2
Constant used in weighting function.
double dist
Current distance from centre.
double max_range
Maximum range to allow. If set to 0, there is no maximum range.
LatLongCoords centre
Centre, to compute distance from.
const LatLongMetric * metric
Metric to compute the distance with.
Base class for calculating distances between two lat/long coordinates.
double operator()(const LatLongCoords &a, std::string_view b) const
Return the distance between two coordinate lists, in metres.
virtual double pointwise_distance(const LatLongCoord &a, const LatLongCoord &b) const =0
Return the distance between two coordinates, in metres.
virtual LatLongMetric * unserialise(const std::string &serialised) const =0
Create object given string serialisation returned by serialise().
virtual std::string serialise() const =0
Serialise object parameters into a string.
virtual LatLongMetric * clone() const =0
Clone the metric.
virtual std::string name() const =0
Return the full name of the metric.
Registry for user subclasses.
A posting source which generates weights from a value slot.
Class for wrapping type returned by an input_iterator.
Build key strings for MSet ordering or collapsing.
The Xapian namespace contains public interfaces for the Xapian library.
std::string sortable_serialise(double value)
Convert a floating point number to a string, preserving sort order.
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
bool operator!=(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
double metres_to_miles(double metres) noexcept
Convert from metres to miles.
double miles_to_metres(double miles) noexcept
Convert from miles to metres.
External sources of posting information.
parsing a user query string to build a Xapian::Query object
A latitude-longitude coordinate.
bool operator<(const LatLongCoord &other) const noexcept
Compare with another LatLongCoord.
LatLongCoord() noexcept
Construct an uninitialised coordinate.
double latitude
A latitude, as decimal degrees.
double longitude
A longitude, as decimal degrees.
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT