xapian-core  1.4.25
geoencode.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2011 Richard Boulton
5  * Based closely on a python version, copyright (C) 2010 Olly Betts
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to
9  * deal in the Software without restriction, including without limitation the
10  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23  * IN THE SOFTWARE.
24  */
25 
26 #ifndef XAPIAN_INCLUDED_GEOENCODE_H
27 #define XAPIAN_INCLUDED_GEOENCODE_H
28 
29 #include <string>
30 
31 namespace GeoEncode {
32 
46 extern bool
47 encode(double lat, double lon, std::string & result);
48 
63 extern void
64 decode(const char * value, size_t len, double & lat_ref, double & lon_ref);
65 
79 static inline void
80 decode(const std::string & value, double & lat_ref, double & lon_ref)
81 {
82  return GeoEncode::decode(value.data(), value.size(), lat_ref, lon_ref);
83 }
84 
94  double lon1;
95 
98  double lon2;
99 
102  double min_lat;
103 
106  double max_lat;
107 
110  unsigned char start1;
111 
114  unsigned char start2;
115 
119 
124 
125  public:
137  DecoderWithBoundingBox(double lat1, double lon1, double lat2, double lon2);
138 
153  bool decode(const std::string & value,
154  double & lat_ref, double & lon_ref) const;
155 };
156 
157 }
158 
159 #endif /* XAPIAN_INCLUDED_GEOENCODE_H */
double max_lat
Maximum latitude in bounding box.
Definition: geoencode.h:106
void decode(const char *value, size_t len, double &lat_ref, double &lon_ref)
Decode a coordinate from a buffer.
Definition: geoencode.cc:135
double min_lat
Minimum latitude in bounding box.
Definition: geoencode.h:102
bool encode(double lat, double lon, std::string &result)
Encode a coordinate and append it to a string.
Definition: geoencode.cc:73
bool decode(const std::string &value, double &lat_ref, double &lon_ref) const
Decode a coordinate.
Definition: geoencode.cc:226
unsigned char start1
First byte of encoded form of coordinates with lon1.
Definition: geoencode.h:110
double lon1
Longitude at western edge of bounding box.
Definition: geoencode.h:94
unsigned char start2
First byte of encoded form of coordinates with lon2.
Definition: geoencode.h:114
double lon2
Longitude at eastern edge of bounding box.
Definition: geoencode.h:98
bool include_poles
True if either of the poles are included in the range.
Definition: geoencode.h:118
bool discontinuous_longitude_range
Flag; true if the longitude range is discontinuous (ie, goes over the boundary at which longitudes wr...
Definition: geoencode.h:123
A class for decoding coordinates within a bounding box.
Definition: geoencode.h:91
DecoderWithBoundingBox(double lat1, double lon1, double lat2, double lon2)
Create a decoder with a bounding box.
Definition: geoencode.cc:190