name of way is now extracted and id of name is prepared.
This commit is contained in:
parent
76488c58e8
commit
affaa106d1
@ -43,6 +43,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
ferry 5
|
ferry 5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef google::dense_hash_map<string, NodeID> StringMap;
|
||||||
|
|
||||||
std::string names[14] = { "motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "unclassified", "residential", "living_street", "service", "ferry" };
|
std::string names[14] = { "motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "unclassified", "residential", "living_street", "service", "ferry" };
|
||||||
double speeds[14] = { 110, 90, 90, 70, 70, 60, 60, 50, 55, 25, 40 , 10, 30, 5};
|
double speeds[14] = { 110, 90, 90, 70, 70, 60, 60, 50, 55, 25, 40 , 10, 30, 5};
|
||||||
|
|
||||||
@ -78,6 +80,7 @@ struct _Way {
|
|||||||
enum {
|
enum {
|
||||||
notSure = 0, oneway, bidirectional, opposite
|
notSure = 0, oneway, bidirectional, opposite
|
||||||
} direction;
|
} direction;
|
||||||
|
unsigned nameID;
|
||||||
double maximumSpeed;
|
double maximumSpeed;
|
||||||
bool usefull:1;
|
bool usefull:1;
|
||||||
bool access:1;
|
bool access:1;
|
||||||
@ -99,6 +102,7 @@ struct _Edge {
|
|||||||
short type;
|
short type;
|
||||||
short direction;
|
short direction;
|
||||||
double speed;
|
double speed;
|
||||||
|
unsigned nameID;
|
||||||
|
|
||||||
_Coordinate startCoord;
|
_Coordinate startCoord;
|
||||||
_Coordinate targetCoord;
|
_Coordinate targetCoord;
|
||||||
@ -191,7 +195,7 @@ struct CmpNodeByID : public std::binary_function<_Node, _Node, bool>
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
_Way _ReadXMLWay( xmlTextReaderPtr& inputReader, Settings& settings ) {
|
_Way _ReadXMLWay( xmlTextReaderPtr& inputReader, Settings& settings, string& name) {
|
||||||
_Way way;
|
_Way way;
|
||||||
way.direction = _Way::notSure;
|
way.direction = _Way::notSure;
|
||||||
way.maximumSpeed = -1;
|
way.maximumSpeed = -1;
|
||||||
@ -226,7 +230,13 @@ _Way _ReadXMLWay( xmlTextReaderPtr& inputReader, Settings& settings ) {
|
|||||||
if ( k != NULL && value != NULL ) {
|
if ( k != NULL && value != NULL ) {
|
||||||
|
|
||||||
if ( xmlStrEqual( k, ( const xmlChar* ) "name" ) == 1 ) {
|
if ( xmlStrEqual( k, ( const xmlChar* ) "name" ) == 1 ) {
|
||||||
//write into namedb and note nameid at edge.
|
name = string((char *) value);
|
||||||
|
} else if ( xmlStrEqual( k, ( const xmlChar* ) "ref" ) == 1 ) {
|
||||||
|
if(name == "")
|
||||||
|
{
|
||||||
|
name = string((char *) value);
|
||||||
|
// cout << ", ref: " << name << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( xmlStrEqual( k, ( const xmlChar* ) "oneway" ) == 1 ) {
|
if ( xmlStrEqual( k, ( const xmlChar* ) "oneway" ) == 1 ) {
|
||||||
@ -458,4 +468,19 @@ double ApproximateDistance( const int lat1, const int lon1, const int lat2, cons
|
|||||||
return EARTH_RADIUS_IN_METERS * distanceArc;
|
return EARTH_RADIUS_IN_METERS * distanceArc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string GetRandomString() {
|
||||||
|
char s[128];
|
||||||
|
static const char alphanum[] =
|
||||||
|
"0123456789"
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
"abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
for (int i = 0; i < 128; ++i) {
|
||||||
|
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
|
||||||
|
}
|
||||||
|
s[128] = 0;
|
||||||
|
return string(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* EXTRACTORSTRUCTS_H_ */
|
#endif /* EXTRACTORSTRUCTS_H_ */
|
||||||
|
@ -44,6 +44,7 @@ typedef google::dense_hash_map<NodeID, _Node> NodeMap;
|
|||||||
typedef stxxl::vector<NodeID> STXXLNodeIDVector;
|
typedef stxxl::vector<NodeID> STXXLNodeIDVector;
|
||||||
typedef stxxl::vector<_Node> STXXLNodeVector;
|
typedef stxxl::vector<_Node> STXXLNodeVector;
|
||||||
typedef stxxl::vector<_Edge> STXXLEdgeVector;
|
typedef stxxl::vector<_Edge> STXXLEdgeVector;
|
||||||
|
typedef stxxl::vector<string> STXXLStringVector;
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
vector<NodeID> SignalNodes;
|
vector<NodeID> SignalNodes;
|
||||||
@ -52,8 +53,10 @@ STXXLNodeVector allNodes;
|
|||||||
STXXLNodeVector confirmedNodes;
|
STXXLNodeVector confirmedNodes;
|
||||||
STXXLEdgeVector allEdges;
|
STXXLEdgeVector allEdges;
|
||||||
STXXLEdgeVector confirmedEdges;
|
STXXLEdgeVector confirmedEdges;
|
||||||
|
STXXLStringVector nameVector;
|
||||||
|
|
||||||
NodeMap * nodeMap = new NodeMap();
|
NodeMap * nodeMap = new NodeMap();
|
||||||
|
StringMap * stringMap = new StringMap();
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -71,6 +74,7 @@ int main (int argc, char *argv[])
|
|||||||
settings.speedProfile.speed.insert(settings.speedProfile.speed.begin(), speeds, speeds+14);
|
settings.speedProfile.speed.insert(settings.speedProfile.speed.begin(), speeds, speeds+14);
|
||||||
|
|
||||||
nodeMap->set_empty_key(UINT_MAX);
|
nodeMap->set_empty_key(UINT_MAX);
|
||||||
|
stringMap->set_empty_key(GetRandomString());
|
||||||
try {
|
try {
|
||||||
while ( xmlTextReaderRead( inputReader ) == 1 ) {
|
while ( xmlTextReaderRead( inputReader ) == 1 ) {
|
||||||
const int type = xmlTextReaderNodeType( inputReader );
|
const int type = xmlTextReaderNodeType( inputReader );
|
||||||
@ -91,35 +95,49 @@ int main (int argc, char *argv[])
|
|||||||
|
|
||||||
}
|
}
|
||||||
if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) {
|
if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) {
|
||||||
_Way way = _ReadXMLWay( inputReader, settings );
|
string name;
|
||||||
|
_Way way = _ReadXMLWay( inputReader, settings, name );
|
||||||
|
|
||||||
if ( way.usefull && way.access && way.path.size() ) {
|
if ( way.usefull && way.access && way.path.size() ) {
|
||||||
|
StringMap::iterator strit = stringMap->find(name);
|
||||||
|
if(name == "") {
|
||||||
|
way.nameID = UINT_MAX;
|
||||||
|
} else {
|
||||||
|
if(strit == stringMap->end())
|
||||||
|
{
|
||||||
|
way.nameID = nameVector.size();
|
||||||
|
nameVector.push_back(name);
|
||||||
|
stringMap->insert(std::make_pair(name, way.nameID) );
|
||||||
|
// cout << "found name ID: " << way.nameID << " (" << name << ")" << endl;
|
||||||
|
} else {
|
||||||
|
way.nameID = strit->second;
|
||||||
|
// cout << "name with ID " << way.nameID << " already existing (" << name << ")" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
for ( unsigned i = 0; i < way.path.size(); ++i ) {
|
for ( unsigned i = 0; i < way.path.size(); ++i ) {
|
||||||
usedNodes.push_back(way.path[i]);
|
usedNodes.push_back(way.path[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( way.direction == _Way::opposite )
|
if ( way.direction == _Way::opposite ){
|
||||||
std::reverse( way.path.begin(), way.path.end() );
|
std::reverse( way.path.begin(), way.path.end() );
|
||||||
|
}
|
||||||
|
vector< NodeID > & path = way.path;
|
||||||
|
assert(way.type > -1 || way.maximumSpeed != -1);
|
||||||
|
assert(path.size()>0);
|
||||||
|
|
||||||
|
if(way.maximumSpeed == -1)
|
||||||
|
way.maximumSpeed = settings.speedProfile.speed[way.type];
|
||||||
|
|
||||||
|
for(vector< NodeID >::size_type n = 0; n < path.size()-1; n++)
|
||||||
{
|
{
|
||||||
vector< NodeID > & path = way.path;
|
_Edge e;
|
||||||
// double speed = way.maximumSpeed;
|
e.start = way.path[n];
|
||||||
assert(way.type > -1 || way.maximumSpeed != -1);
|
e.target = way.path[n+1];
|
||||||
assert(path.size()>0);
|
e.type = way.type;
|
||||||
|
e.direction = way.direction;
|
||||||
if(way.maximumSpeed == -1)
|
e.speed = way.maximumSpeed;
|
||||||
way.maximumSpeed = settings.speedProfile.speed[way.type];
|
e.nameID = way.nameID;
|
||||||
|
allEdges.push_back(e);
|
||||||
for(vector< NodeID >::size_type n = 0; n < path.size()-1; n++)
|
|
||||||
{
|
|
||||||
_Edge e;
|
|
||||||
e.start = way.path[n];
|
|
||||||
e.target = way.path[n+1];
|
|
||||||
e.type = way.type;
|
|
||||||
e.direction = way.direction;
|
|
||||||
e.speed = way.maximumSpeed;
|
|
||||||
allEdges.push_back(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,6 +146,7 @@ int main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
xmlFree( currentName );
|
xmlFree( currentName );
|
||||||
}
|
}
|
||||||
|
cout << "raw no. of names: " << nameVector.size() << endl;
|
||||||
cout << "raw no. of nodes: " << allNodes.size() << endl;
|
cout << "raw no. of nodes: " << allNodes.size() << endl;
|
||||||
cout << "raw no. of edges: " << allEdges.size() << endl;
|
cout << "raw no. of edges: " << allEdges.size() << endl;
|
||||||
|
|
||||||
@ -251,6 +270,7 @@ int main (int argc, char *argv[])
|
|||||||
int intDist = max(1, (int)distance);
|
int intDist = max(1, (int)distance);
|
||||||
int ferryIndex = settings.indexInAccessListOf("ferry");
|
int ferryIndex = settings.indexInAccessListOf("ferry");
|
||||||
|
|
||||||
|
//Todo: write nameID and type of edge to osrm
|
||||||
switch(eit->direction)
|
switch(eit->direction)
|
||||||
{
|
{
|
||||||
case _Way::notSure:
|
case _Way::notSure:
|
||||||
@ -270,6 +290,8 @@ int main (int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Todo: serialize list of names
|
||||||
|
|
||||||
fout.close();
|
fout.close();
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
} catch ( const std::exception& e ) {
|
} catch ( const std::exception& e ) {
|
||||||
@ -288,8 +310,10 @@ int main (int argc, char *argv[])
|
|||||||
confirmedNodes.clear();
|
confirmedNodes.clear();
|
||||||
allEdges.clear();
|
allEdges.clear();
|
||||||
confirmedEdges.clear();
|
confirmedEdges.clear();
|
||||||
|
nameVector.clear();
|
||||||
xmlFreeTextReader(inputReader);
|
xmlFreeTextReader(inputReader);
|
||||||
delete nodeMap;
|
delete nodeMap;
|
||||||
|
delete stringMap;
|
||||||
cout << "finished." << endl;
|
cout << "finished." << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ using namespace std;
|
|||||||
typedef unsigned int NodeID;
|
typedef unsigned int NodeID;
|
||||||
typedef unsigned int EdgeID;
|
typedef unsigned int EdgeID;
|
||||||
typedef unsigned int EdgeWeight;
|
typedef unsigned int EdgeWeight;
|
||||||
|
|
||||||
static const NodeID SPECIAL_NODEID = UINT_MAX;
|
static const NodeID SPECIAL_NODEID = UINT_MAX;
|
||||||
static const EdgeID SPECIAL_EDGEID = UINT_MAX;
|
static const EdgeID SPECIAL_EDGEID = UINT_MAX;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user