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

towns_dumper.hpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d0fa46551721f9e12897bbc4bce56cf9f7f34635 (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
#pragma once

#include "geometry/latlon.hpp"
#include "geometry/mercator.hpp"
#include "geometry/rect2d.hpp"

#include "base/string_utils.hpp"

#include "std/limits.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"

class TownsDumper
{
public:
  TownsDumper();

  template <typename TElement>
  void CheckElement(TElement const & em)
  {
    if (em.type != TElement::EntityType::Node)
      return;
    uint64_t population = 1;
    bool town = false;
    bool capital = false;
    int admin_level = numeric_limits<int>::max();
    for (auto const & tag : em.Tags())
    {
      string key(tag.key), value(tag.value);
      if (key == "population")
      {
        if (!strings::to_uint64(value, population))
          continue;
      }
      else if (key == "admin_level")
      {
        if (!strings::to_int(value, admin_level))
          continue;
      }
      else if (key == "capital" && value == "yes")
      {
        capital = true;
      }
      else if (key == "place" && (value == "city" || value == "town"))
      {
        town = true;
      }
    }

    // Ignore regional capitals.
    if (capital && admin_level > 2)
      capital = false;

    if (town || capital)
      m_records.emplace_back(em.lat, em.lon, em.id, capital, population);
  }

  void Dump(string const & filePath);

private:
  void FilterTowns();

  struct Town
  {
    ms::LatLon point;
    uint64_t id;
    bool capital;
    uint64_t population;

    Town(double lat, double lon, uint64_t id, bool isCapital, uint64_t population)
      : point(lat, lon), id(id), capital(isCapital), population(population)
    {
    }

    bool operator<(Town const & rhs) const { return population < rhs.population; }
    m2::RectD GetLimitRect() const
    {
      return m2::RectD(MercatorBounds::FromLatLon(point), MercatorBounds::FromLatLon(point));
    }
  };

  vector<Town> m_records;
};