00001
00002
00003
00004
00005
00006
00007
00008 #include "ElementCopy.h"
00009
00010 #include "../sqllib/sqllib.h"
00011
00012 namespace osmdb
00013 {
00014
00015 ElementCopy::ElementCopy(OsmDatabase& db):
00016 db(db),
00017 copy(sqllib::get_copy_import(db.get_db()))
00018 {
00019
00020 }
00021
00022 void ElementCopy::start_copy()
00023 {
00024 copy.execute();
00025 }
00026
00027 void ElementCopy::end_copy()
00028 {
00029 copy.end_copy();
00030 }
00031
00032 void ElementCopy::insert_node(const osm::Node& nd)
00033 {
00034 copy.copy_data(1, nd.id, 0, 0, nd.position.lon, nd.position.lat, "", "");
00035 for (auto it = nd.tags.begin(); it != nd.tags.end(); ++it)
00036 {
00037 copy.copy_data(4, nd.id, 0, 0, 0, 0, it->first, it->second);
00038 }
00039 }
00040
00041 void ElementCopy::insert_way(const osm::Way& w)
00042 {
00043 copy.copy_data(2, w.id, 0, 0, 0, 0, "", "");
00044 for (auto it = w.tags.begin(); it != w.tags.end(); ++it)
00045 {
00046 copy.copy_data(5, w.id, 0, 0, 0, 0, it->first, it->second);
00047 }
00048 for (unsigned int i = 0; i < w.nodes.size(); ++i)
00049 {
00050 copy.copy_data(7, w.id, w.nodes[i].id, i, 0, 0, "", "");
00051 }
00052 }
00053
00054 void ElementCopy::insert_relation(const osm::Relation& rel)
00055 {
00056 copy.copy_data(3, rel.id, 0, 0, 0, 0, "", "");
00057 for (auto it = rel.tags.begin(); it != rel.tags.end(); ++it)
00058 {
00059 copy.copy_data(6, rel.id, 0, 0, 0, 0, it->first, it->second);
00060 }
00061 for (auto it = rel.members.begin(); it != rel.members.end(); ++it)
00062 {
00063 it->second->add_to_relation(*this, rel.id, it->first);
00064 }
00065 }
00066
00067 void ElementCopy::insert_member_node(int64_t rel_id, const std::string& role, int64_t node_id)
00068 {
00069 copy.copy_data(8, rel_id, node_id, 0, 0, 0, role, "");
00070 }
00071
00072 void ElementCopy::insert_member_way(int64_t rel_id, const std::string& role, int64_t way_id)
00073 {
00074 copy.copy_data(9, rel_id, way_id, 0, 0, 0, role, "");
00075 }
00076
00077 void ElementCopy::insert_member_relation(int64_t parent_id, const std::string& role, int64_t child_id)
00078 {
00079 copy.copy_data(10, parent_id, child_id, 0, 0, 0, role, "");
00080 }
00081
00082 ElementCopy::~ElementCopy()
00083 {
00084 }
00085
00086 }