root/tools/osm2pgrouting/trunk/src/OSMDocument.cpp

Revision 210, 4.6 KB (checked in by anton, 2 years ago)

osm2pgrouting: onewaystreets support added

Line 
1/***************************************************************************
2 *   Copyright (C) 2008 by Daniel Wendt                                                                    *
3 *   gentoo.murray@gmail.com                                                                                       *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 *                                                                         *
10 *   This program is distributed in the hope that it will be useful,       *
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13 *   GNU General Public License for more details.                          *
14 *                                                                         *
15 *   You should have received a copy of the GNU General Public License     *
16 *   along with this program; if not, write to the                         *
17 *   Free Software Foundation, Inc.,                                       *
18 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19 ***************************************************************************/
20
21#include "stdafx.h"
22#include "OSMDocument.h"
23#include "Configuration.h"
24#include "Node.h"
25#include "Way.h"
26#include "math_functions.h"
27
28
29namespace osm
30{
31
32OSMDocument::OSMDocument( Configuration& config ) : m_rConfig( config )
33{
34}
35
36OSMDocument::~OSMDocument()
37{
38        ez_mapdelete( m_Nodes );
39        ez_vectordelete( m_Ways );             
40        ez_vectordelete( m_SplittedWays );
41}
42void OSMDocument::AddNode( Node* n )
43{
44        m_Nodes[n->id] = n;
45}
46
47void OSMDocument::AddWay( Way* w )
48{
49        m_Ways.push_back( w );
50}
51
52Node* OSMDocument::FindNode( long long nodeRefId )
53const
54{
55        std::map<long long, Node*>::const_iterator  it = m_Nodes.find( nodeRefId );
56        return (it!=m_Nodes.end() ) ? it->second : 0;
57}
58
59void OSMDocument::SplitWays()
60{
61       
62        std::vector<Way*>::const_iterator it(m_Ways.begin());
63        std::vector<Way*>::const_iterator last(m_Ways.end());
64
65        //splitted ways get a new ID
66        long long id=0;
67
68        while(it!=last)
69        {
70                Way* currentWay = *it++;
71               
72                std::vector<Node*>::const_iterator it_node( currentWay->m_NodeRefs.begin());   
73                std::vector<Node*>::const_iterator last_node( currentWay->m_NodeRefs.end());
74               
75                Node* backNode = currentWay->m_NodeRefs.back();
76
77
78
79                while(it_node!=last_node)
80                {
81                       
82                        Node* node = *it_node++;
83                        Node* secondNode=0;
84                        Node* lastNode=0;
85                       
86                        Way* splitted_way = new Way( ++id, currentWay->visible );
87                        splitted_way->name=currentWay->name;
88                        splitted_way->type=currentWay->type;
89                        splitted_way->clss=currentWay->clss;
90                        splitted_way->oneway=currentWay->oneway;
91
92        //GeometryFromText('MULTILINESTRING(('||x1||' '||y1||','||x2||' '||y2||'))',4326);
93                       
94                        splitted_way->geom="MULTILINESTRING(("+ boost::lexical_cast<std::string>(node->lon) + " " + boost::lexical_cast<std::string>(node->lat) +",";
95                       
96                        splitted_way->AddNodeRef(node);
97                       
98                        bool found=false;
99                       
100                        if(it_node!=last_node)
101                        {
102                                while(it_node!=last_node && !found)
103                                {
104                                        splitted_way->AddNodeRef(*it_node);
105                                        if((*it_node)->numsOfUse>1)
106                                        {
107                                                found=true;
108                                                secondNode = *it_node;
109                                                splitted_way->AddNodeRef(secondNode);
110                                                double length = getLength(node,secondNode);
111                                                if(length<0)
112                                                        length*=-1;
113                                                splitted_way->length+=length;
114                                                splitted_way->geom+= boost::lexical_cast<std::string>(secondNode->lon) + " " + boost::lexical_cast<std::string>(secondNode->lat) + "))";
115                                               
116                                        }
117                                        else if(backNode==(*it_node))
118                                        {
119                                                lastNode=*it_node++;
120                                                splitted_way->AddNodeRef(lastNode);
121                                                double length = getLength(node,lastNode);
122                                                if(length<0)
123                                                        length*=-1;
124                                                splitted_way->length+=length;
125                                                splitted_way->geom+= boost::lexical_cast<std::string>(lastNode->lon) + " " + boost::lexical_cast<std::string>(lastNode->lat) + "))";
126                                        }
127                                        else
128                                        {
129                                                splitted_way->geom+= boost::lexical_cast<std::string>((*it_node)->lon) + " " + boost::lexical_cast<std::string>((*it_node)->lat) + ",";
130                                                *it_node++;
131                                        }
132                                }
133                        }
134                               
135                        if(splitted_way->m_NodeRefs.front()!=splitted_way->m_NodeRefs.back())
136                                m_SplittedWays.push_back(splitted_way);
137                        else
138                        {
139                                delete splitted_way;
140                                splitted_way=0;
141                        }
142                               
143                }
144
145        }
146
147} // end SplitWays
148
149} // end namespace osm
Note: See TracBrowser for help on using the browser.