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

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

#include "xml_element.hpp"
#include "osm_decl.hpp"

#include "../indexer/mercator.hpp"

#include "../base/string_utils.hpp"


template <class THolder>
class FirstPassParser : public BaseOSMParser
{
  THolder & m_holder;

public:
  FirstPassParser(THolder & holder) : m_holder(holder)
  {
    static char const * tags[] = { "osm", "node", "way", "relation" };
    SetTags(tags);
  }

protected:
  virtual void EmitElement(XMLElement * p)
  {
    uint64_t id;
    VERIFY ( strings::to_uint64(p->attrs["id"], id), ("Unknown element with invalid id : ", p->attrs["id"]) );

    if (p->name == "node")
    {
      // store point

      double lat, lng;
      VERIFY ( strings::to_double(p->attrs["lat"], lat), ("Bad node lat : ", p->attrs["lat"]) );
      VERIFY ( strings::to_double(p->attrs["lon"], lng), ("Bad node lon : ", p->attrs["lon"]) );

      // convert to mercator
      lat = MercatorBounds::LatToY(lat);
      lng = MercatorBounds::LonToX(lng);

      m_holder.AddNode(id, lat, lng);
    }
    else if (p->name == "way")
    {
      // store way
      WayElement e(id);

      for (size_t i = 0; i < p->childs.size(); ++i)
      {
        if (p->childs[i].name == "nd")
        {
          uint64_t ref;
          VERIFY ( strings::to_uint64(p->childs[i].attrs["ref"], ref), ("Bad node ref in way : ", p->childs[i].attrs["ref"]) );
          e.nodes.push_back(ref);
        }
      }

      if (e.IsValid())
        m_holder.AddWay(id, e);
    }
    else if (p->name == "relation")
    {
      // store relation

      RelationElement e;
      for (size_t i = 0; i < p->childs.size(); ++i)
      {
        if (p->childs[i].name == "member")
        {
          uint64_t ref;
          VERIFY ( strings::to_uint64(p->childs[i].attrs["ref"], ref), ("Bad ref in relation : ", p->childs[i].attrs["ref"]) );

          string const & type = p->childs[i].attrs["type"];
          string const & role = p->childs[i].attrs["role"];
          if (type == "node")
            e.nodes.push_back(make_pair(ref, role));
          else
            e.ways.push_back(make_pair(ref, role));
        }
        else if (p->childs[i].name == "tag")
        {
          // relation tags writing as is
          e.tags.insert(make_pair(p->childs[i].attrs["k"], p->childs[i].attrs["v"]));
        }
      }

      if (e.IsValid())
        m_holder.AddRelation(id, e);
    }
  }
};