Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sponsored_dataset.hpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a35ab8e803630e4f995ecd1274775cb024e0be19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

#include "indexer/index.hpp"

#include "search/reverse_geocoder.hpp"

#include "platform/local_country_file.hpp"
#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"

#include "base/newtype.hpp"

#include "std/function.hpp"
#include "std/map.hpp"
#include "std/string.hpp"

#include "boost/geometry.hpp"
#include "boost/geometry/geometries/point.hpp"
#include "boost/geometry/geometries/box.hpp"
#include "boost/geometry/index/rtree.hpp"

class FeatureBuilder1;

namespace generator
{
template <typename SponsoredObject>
class SponsoredDataset
{
public:
  using Object = SponsoredObject;
  using ObjectId = typename Object::ObjectId;

  static double constexpr kDistanceLimitInMeters = 150;
  static size_t constexpr kMaxSelectedElements = 3;

  explicit SponsoredDataset(string const & dataPath, string const & addressReferencePath = string());
  explicit SponsoredDataset(istream & dataSource, string const & addressReferencePath = string());

  size_t Size() const { return m_objects.size(); }

  Object const & GetObjectById(ObjectId id) const;
  Object & GetObjectById(ObjectId id);
  vector<ObjectId> GetNearestObjects(ms::LatLon const & latLon, size_t limit,
                                     double maxDistance = 0.0) const;

  /// @return true if |fb| satisfies some necessary conditions to match one or serveral
  /// objects from dataset.
  bool NecessaryMatchingConditionHolds(FeatureBuilder1 const & fb) const;
  ObjectId FindMatchingObjectId(FeatureBuilder1 const & e) const;

  void PreprocessMatchedOsmObject(ObjectId matchedObjId, FeatureBuilder1 & fb,
                                  function<void(FeatureBuilder1 &)> const fn) const;
  void BuildOsmObjects(function<void(FeatureBuilder1 &)> const & fn) const;

protected:
  class AddressMatcher
  {
  public:
    AddressMatcher();
    void operator()(Object & object);

  private:
    Index m_index;
    unique_ptr<search::ReverseGeocoder> m_coder;
  };

  // TODO(mgsergio): Get rid of Box since boost::rtree supports point as value type.
  // TODO(mgsergio): Use mercator instead of latlon or boost::geometry::cs::spherical_equatorial
  // instead of boost::geometry::cs::cartesian.
  using Point = boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian>;
  using Box = boost::geometry::model::box<Point>;
  using Value = pair<Box, ObjectId>;

  // Create the rtree using default constructor.
  boost::geometry::index::rtree<Value, boost::geometry::index::quadratic<16>> m_rtree;

  void BuildObject(Object const & object,
                   function<void(FeatureBuilder1 &)> const & fn) const;

  void LoadData(istream & src, string const & addressReferencePath);

  /// @return an id of a matched object or kInvalidObjectId on failure.
  ObjectId FindMatchingObjectIdImpl(FeatureBuilder1 const & fb) const;

  map<ObjectId, Object> m_objects;
};
}  // namespace generator

#include "generator/sponsored_dataset_inl.hpp"  // SponsoredDataset implementation.