Skip to content

Commit e3fb761

Browse files
James Michael DuPontJames Michael DuPont
James Michael DuPont
authored and
James Michael DuPont
committed
update
1 parent 27a849c commit e3fb761

File tree

2 files changed

+120
-7
lines changed

2 files changed

+120
-7
lines changed

FOSMBin.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class Geography
3333
int read_way_nodes() {
3434

3535
FILE * pFile;
36-
pFile = fopen ( "waynodes.bin" , "r" );
36+
pFile = fopen ( "datafile/way_nodes.bin" , "r" );
3737
if (!pFile) {
38-
printf("file could not be opened\n");
38+
printf("file datafile/waynodes.bin could not be opened\n");
3939
return 2;
4040
}
4141
int waycount;
@@ -85,7 +85,7 @@ class Geography
8585
FILE * pFile;
8686
pFile = fopen ( filename , "r" );
8787
if (!pFile) {
88-
printf("file could not be opened\n");
88+
printf("file \'%s\' could not be opened\n",filename);
8989
return 2;
9090
}
9191
int count;
@@ -151,10 +151,10 @@ class Geography
151151
reverse_components();
152152
}
153153

154-
void read_node_lat(){ read_data<double> ("nodelat.bin" , node_lat); }
155-
void read_node_lon(){ read_data<double> ("nodelon.bin" , node_lon); }
156-
void read_node_id() { read_data<int> ("nodeindex.bin" , node_id); }
157-
void read_way_id() { read_data<int> ("wayindex.bin" , way_id); }
154+
void read_node_lat(){ read_data<double> ("datafiles/node_lat.bin" , node_lat); }
155+
void read_node_lon(){ read_data<double> ("datafiles/node_lon.bin" , node_lon); }
156+
void read_node_id() { read_data<int> ("datafiles/node_ids.bin" , node_id); }
157+
void read_way_id() { read_data<int> ("datafiles/way_ids.bin" , way_id); }
158158

159159

160160
};

metisexport2.cpp

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//=======================================================================
2+
// Copyright 1997-2001 University of Notre Dame.
3+
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
4+
//
5+
// Distributed under the Boost Software License, Version 1.0. (See
6+
// accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
//=======================================================================
9+
10+
#include <boost/config.hpp>
11+
#include <iostream>
12+
#include <vector>
13+
#include <boost/graph/strong_components.hpp>
14+
#include <boost/graph/adjacency_list.hpp>
15+
#include <boost/graph/graphviz.hpp>
16+
#include <boost/graph/graph_utility.hpp>
17+
#include "FOSMBin.hpp"
18+
19+
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> Graph;
20+
typedef typename Graph::vertex_descriptor vertex_descriptor;
21+
typedef typename Graph::edge_property_type edge_property;
22+
23+
24+
int edgecount;
25+
int read_graph(Graph & g) {
26+
// now read the graph
27+
edgecount=0;
28+
29+
FILE * pFile;
30+
pFile = fopen ( "waynodes.bin" , "r" );
31+
if (!pFile) {
32+
printf("file could not be opened\n");
33+
return 2;
34+
}
35+
int waycount;
36+
int i=0;
37+
int br=fread ((void*)&waycount , sizeof(int), 1 , pFile ); // count of ways
38+
39+
for (i =0; i < waycount; i++) {
40+
int j;
41+
int i2;
42+
fread ((void*)&i2 , sizeof(int), 1 , pFile ); // index
43+
if (i2 != i)
44+
{
45+
printf("Reading way index %d failed with a different %d\n",i,i2);
46+
return 1;
47+
}
48+
49+
fread ((void*)&j , sizeof(int), 1 , pFile ); // size
50+
int waynodes[j];
51+
fread ((void*)&waynodes, sizeof(int), j , pFile ); // data
52+
53+
// now we can process the edges...
54+
55+
vertex_descriptor prev = (int)waynodes[0];
56+
// boost::add_edge(prev,prev, g); // loop for self
57+
// edgecount++;
58+
59+
int j2=0; // index of the nodes in the way
60+
for (j2 =1; j2< j; j2++) {
61+
vertex_descriptor to = (int)waynodes[j2];
62+
// edges are from the nodes to each other, not from the way to the edge
63+
boost::add_edge(prev,to, g);
64+
edgecount++;
65+
66+
// boost::add_edge(to,prev, g);
67+
// edgecount++;
68+
prev= to;
69+
}
70+
71+
}
72+
73+
fclose (pFile);
74+
return 0;
75+
}
76+
77+
template <class Name>
78+
void print_graph_dispatch(const Graph& G, Name name)
79+
{
80+
boost::graph_traits<Graph>::vertex_iterator ui,ui_end;
81+
for (boost::tie(ui,ui_end) = vertices(G); ui != ui_end; ++ui) {
82+
std::cout << get(name,*ui) << " "; // self edge
83+
boost::graph_traits<Graph>::out_edge_iterator ei, ei_end;
84+
for(boost::tie(ei,ei_end) = out_edges(*ui,G); ei != ei_end; ++ei)
85+
std::cout << get(name,target(*ei,G)) << " ";
86+
std::cout << std::endl;
87+
}
88+
}
89+
90+
int main(int, char*[])
91+
{
92+
using namespace boost;
93+
using namespace std;
94+
const char* name = "kosovo osm ways";
95+
Graph G;
96+
Geography geo;
97+
int ok =read_graph(G);
98+
99+
geo.read_data<int> ("nodeindex.bin" , geo.node_id);
100+
// int nodecount=(int) geo.node_id.size()+1;
101+
102+
int nodecount = num_vertices(G);
103+
104+
if(ok !=0) {
105+
return ok;
106+
}
107+
108+
cout << edgecount << " "<< nodecount << endl;
109+
// print_graph_dispatch(G, get(vertex_index, G));
110+
print_graph(G);
111+
112+
return 0;
113+
}

0 commit comments

Comments
 (0)