Skip to content

Commit 81db134

Browse files
James Michael DuPontJames Michael DuPont
authored andcommitted
now the files can be read, lets try it on a big one
1 parent e3fb761 commit 81db134

File tree

6 files changed

+302
-180
lines changed

6 files changed

+302
-180
lines changed

FOSMBin.cpp

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#include "FOSMBin.hpp"
2+
3+
template <class T> int Geography::read_data (const char * filename,vector<T> & vdata)
4+
{
5+
FILE * pFile;
6+
pFile = fopen ( filename , "r" );
7+
if (!pFile) {
8+
printf("file \'%s\' could not be opened\n",filename);
9+
return 2;
10+
}
11+
printf("opened file \'%s\'\n",filename);
12+
int count;
13+
int i=0;
14+
// int br=fread ((void*)&count , sizeof(int), 1 , pFile ); // count of ways
15+
//printf("Reading bytes %d count %d\n",br,count);
16+
//T data[count];
17+
// vector<T> vdata;
18+
while (1){
19+
T data;
20+
int br= fread ((void*)&data , sizeof(T), 1 , pFile ); // index
21+
if (br<=0) goto done ;
22+
//cerr << "data : br"<< br<< "data:" << data << endl;
23+
//for (i =0; i < count; i++) {
24+
vdata.push_back(data);
25+
}
26+
done :
27+
fclose (pFile);
28+
return 0;
29+
}
30+
31+
32+
#define Q2(X,X2) cerr << X << ":" << X2.count() << endl;
33+
#define Q(X) Q2( #X , X )
34+
void Geography::report()
35+
{
36+
/*
37+
Q(component_map_t)
38+
Q(way_nodes_t)
39+
Q(nodes_ways_t)
40+
Q(way_component_t)
41+
Q(node_components)
42+
Q(node_lat)
43+
Q(node_lon)
44+
Q(node_id)
45+
Q(way_id)
46+
Q(component_map)
47+
Q(way_nodes)
48+
Q(node_ways)
49+
Q(way_components)
50+
*/
51+
52+
cerr << "node_components" << ":" << node_components.size() << endl;
53+
cerr << "node_lat" << ":" << node_lat.size() << endl;
54+
cerr << "node_lon" << ":" << node_lon.size() << endl;
55+
cerr << "node_id" << ":" << node_id.size() << endl;
56+
cerr << "way_id" << ":" << way_id.size() << endl;
57+
cerr << "component_map" << ":" << component_map.size() << endl;
58+
cerr << "way_nodes" << ":" << way_nodes.size() << endl;
59+
cerr << "node_ways" << ":" << node_ways.size() << endl;
60+
cerr << "way_components" << ":" << way_components.size() << endl;
61+
62+
// Q(debug)
63+
}
64+
65+
int Geography::read_way_nodes() {
66+
FILE * pFile;
67+
pFile = fopen ( "datafiles/way_nodes.bin" , "r" );
68+
if (!pFile) {
69+
// perror("");
70+
printf("file datafile/way_nodes.bin could not be opened\n");
71+
return 2;
72+
}
73+
printf("data file datafile/way_nodes.bin opened\n");
74+
75+
int node_count; // should be zero
76+
int br=fread ((void*)&node_count, sizeof(long int), 1 , pFile ); //
77+
//cerr << "first br"<< br << " node count:" << node_count << endl;
78+
79+
while (1) { // for each way
80+
81+
int way; // way index, not id
82+
br=fread ((void*)&way , sizeof(int), 1 , pFile ); // count of ways
83+
//cerr << "br:"<< br<< "way:" << way << endl;
84+
85+
int j=0;
86+
while (1) { // for each node in way until null
87+
int waynode;
88+
br=fread ((void*)&waynode, sizeof(long int), 1 , pFile ); //
89+
if (br == 0) goto done;
90+
if (waynode == -1) goto donelist;
91+
// cerr << " br:"<< br << " node:" << waynode ;
92+
// << endl;
93+
way_nodes[way].push_back(waynode); //the way contains this node
94+
node_ways[waynode].push_back(way); //the node is in this way
95+
j++;
96+
97+
}
98+
donelist :
99+
int donothing;
100+
101+
// cerr << "done list" << endl;
102+
//cerr << " nc:" << j << endl;
103+
104+
};
105+
106+
done:
107+
//cerr << "done file" << endl;
108+
fclose (pFile);
109+
return 0;
110+
111+
} // read nodes
112+
113+
114+
115+
116+
117+
void Geography::read_data()
118+
{
119+
read_node_lat();
120+
read_node_lon();
121+
read_node_id();
122+
read_way_id();
123+
read_way_nodes();
124+
}
125+
126+
void Geography::read_components() {
127+
read_data<int> ("components.bin",node_components);
128+
reverse_components();
129+
}
130+
131+
void Geography::read_node_lat(){ read_data<double> ("datafiles/node_lat.bin" , node_lat); }
132+
void Geography::read_node_lon(){ read_data<double> ("datafiles/node_lon.bin" , node_lon); }
133+
void Geography::read_node_id() { read_data<int> ("datafiles/node_ids.bin" , node_id); }
134+
void Geography::read_way_id() { read_data<int> ("datafiles/way_ids.bin" , way_id); }
135+
136+
template <class T> void Geography::emit(vector<T> & data) {
137+
vector<int>::const_iterator cii;
138+
cerr << endl << "Iterator:" << endl;
139+
for(cii=data.begin(); cii!=data.end(); cii++)
140+
{
141+
cerr << *cii << endl;
142+
}
143+
}
144+
145+
146+
Geography::Geography()
147+
{
148+
debug=1;
149+
}
150+
151+
void Geography::reverse_components ()
152+
{
153+
154+
int index=0;
155+
vector<int>::const_iterator cii;
156+
for(cii=node_components.begin(); cii!=node_components.end(); cii++)
157+
{
158+
component_map[*cii].push_back(index);
159+
if (debug > 8)
160+
{
161+
cout << "Component " << *cii << "contains node "<< index << endl;
162+
}
163+
index++;
164+
}
165+
}
166+
167+
void Geography::emit_ways_components()
168+
{
169+
cerr << "output the way components " << endl;
170+
way_component_t::iterator wcit;
171+
for (wcit=way_components.begin();wcit!=way_components.end();wcit++) {
172+
std::map<int,int>::iterator wcit2;
173+
int comp = wcit->second;
174+
cerr << "way:" << wcit->first << "\tcomponent:" << comp << endl;
175+
}
176+
}
177+

FOSMBin.hpp

Lines changed: 14 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Geography
1313
typedef std::map<int, std::vector<int> > way_nodes_t;
1414
typedef std::map<int, std::vector<int> > nodes_ways_t;
1515
typedef std::map<int, int > way_component_t; // a way can be a member of many components, we need to figure out how and way
16-
1716
vector<int> node_components;
1817
vector<double> node_lat;
1918
vector<double> node_lon;
@@ -24,138 +23,22 @@ class Geography
2423
nodes_ways_t node_ways;
2524
way_component_t way_components;
2625
int debug;
27-
public:
28-
Geography()
29-
{
30-
debug=1;
31-
}
32-
33-
int read_way_nodes() {
34-
35-
FILE * pFile;
36-
pFile = fopen ( "datafile/way_nodes.bin" , "r" );
37-
if (!pFile) {
38-
printf("file datafile/waynodes.bin could not be opened\n");
39-
return 2;
40-
}
41-
int waycount;
42-
int br=fread ((void*)&waycount , sizeof(int), 1 , pFile ); // count of ways
43-
44-
// loop over all the ways
45-
int wayindex=0;
46-
for (wayindex =0; wayindex < waycount; wayindex++) {
47-
48-
int i2;
49-
fread ((void*)&i2 , sizeof(int), 1 , pFile ); // index
50-
if (i2 != wayindex) {
51-
printf("Reading way index %d failed with a different %d\n",wayindex,i2);
52-
return 1;
53-
}
54-
55-
int node_count;
56-
fread ((void*)&node_count , sizeof(int), 1 , pFile ); // size
57-
58-
int waynodes[node_count];
59-
fread ((void*)&waynodes, sizeof(int), node_count , pFile ); // data
60-
61-
// now we can process the edges...
62-
int j2;// index
63-
for (j2 =0; j2< node_count; j2++) {
64-
int tonode = (int)waynodes[j2];
65-
66-
//
67-
if (debug > 10)
68-
{
69-
cerr << "reading from node : [" << j2 << "]" << tonode <<"(" << node_id[tonode] << ")"
70-
<< " emit way: " << wayindex <<"(" << way_id[wayindex] << ")"
71-
<< endl;
72-
}
73-
74-
way_nodes[wayindex].push_back(tonode); //the way contains this node
75-
node_ways[tonode].push_back(wayindex); //the node is in this way
76-
}
77-
}
78-
fclose (pFile);
79-
return 0;
80-
}
8126

27+
public:
8228

83-
template <class T> int read_data (const char * filename,vector<T> & vdata)
84-
{
85-
FILE * pFile;
86-
pFile = fopen ( filename , "r" );
87-
if (!pFile) {
88-
printf("file \'%s\' could not be opened\n",filename);
89-
return 2;
90-
}
91-
int count;
92-
int i=0;
93-
int br=fread ((void*)&count , sizeof(int), 1 , pFile ); // count of ways
94-
// printf("Reading bytes %d count %d\n",br,count);
95-
T data[count];
96-
br= fread ((void*)&data , sizeof(T), count , pFile ); // index
97-
fclose (pFile);
98-
for (i =0; i < count; i++) {
99-
vdata.push_back((T)data[i]);
100-
}
101-
return 0;
102-
}
103-
104-
template <class T> void emit(vector<T> & data) {
105-
vector<int>::const_iterator cii;
106-
cerr << endl << "Iterator:" << endl;
107-
for(cii=data.begin(); cii!=data.end(); cii++)
108-
{
109-
cerr << *cii << endl;
110-
}
111-
}
112-
113-
void reverse_components ()
114-
{
115-
116-
int index=0;
117-
vector<int>::const_iterator cii;
118-
for(cii=node_components.begin(); cii!=node_components.end(); cii++)
119-
{
120-
component_map[*cii].push_back(index);
121-
if (debug > 8)
122-
{
123-
cout << "Component " << *cii << "contains node "<< index << endl;
124-
}
125-
index++;
126-
}
127-
}
128-
129-
void emit_ways_components()
130-
{
131-
cerr << "output the way components " << endl;
132-
way_component_t::iterator wcit;
133-
for (wcit=way_components.begin();wcit!=way_components.end();wcit++) {
134-
std::map<int,int>::iterator wcit2;
135-
int comp = wcit->second;
136-
cerr << "way:" << wcit->first << "\tcomponent:" << comp << endl;
137-
}
138-
}
139-
140-
void read_data()
141-
{
142-
read_node_lat();
143-
read_node_lon();
144-
read_node_id();
145-
read_way_id();
146-
read_way_nodes();
147-
}
148-
149-
void read_components() {
150-
read_data<int> ("components.bin",node_components);
151-
reverse_components();
152-
}
153-
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); }
158-
29+
Geography();
30+
int read_way_nodes();
31+
template <class T> int read_data (const char * filename,vector<T> & vdata);
32+
template <class T> void emit(vector<T> & data);
33+
void reverse_components () ;
34+
void emit_ways_components();
35+
void read_data();
36+
void read_components();
37+
void read_node_lat();
38+
void read_node_lon();
39+
void read_node_id();
40+
void read_way_id();
41+
void report();
15942

16043
};
16144

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
CC = gcc
2-
CFLAGS = # -O0 -g -DTESTING
2+
CFLAGS = -O0 -g -DTESTING
33

44
PROGS=bzip-table seek-bunzip bzip-table-fosm bzip-table-linecount ragelosm
55

66
HEADERS= datafile.hpp tagfile.hpp wayfile.hpp fileindexer.hpp fileindexer.hpp ifileindexer.hpp
77

88
all: $(PROGS) all2
99

10+
FOSMBin.o : FOSMBin.cpp FOSMBin.hpp
11+
g++ $(CFLAGS) -c $< -o $@
12+
13+
1014
bzip-table : bzip-table.c micro-bunzip.c
1115
g++ $(CFLAGS) bzip-table.c micro-bunzip.c -o $@
1216

@@ -116,16 +120,22 @@ componentsreadbin : componentsreadbin.c
116120
gcc -o componentsreadbin componentsreadbin.c
117121
# use this to create a pack file perl process_components.pl
118122

119-
readalldata : readalldata.cpp FOSMBin.hpp
120-
g++ -g -o readalldata readalldata.cpp
123+
124+
readalldata : readalldata.cpp FOSMBin.hpp FOSMBin.o
125+
g++ -g -o readalldata readalldata.cpp FOSMBin.o
121126

122127
waysreadbin : waysreadbin.c
123128
g++ -o waysreadbin waysreadbin.c
124129

125130
dumplatlon : dumplatlon.cpp FOSMBin.hpp
126131
g++ -o dumplatlon dumplatlon.cpp
127132

128-
hierachy : hierarchybuilder.cpp FOSMBin.hpp
129-
g++ -o hierachy hierarchybuilder.cpp
133+
hierachy : hierarchybuilder.cpp FOSMBin.hpp FOSMBin.o
134+
g++ -o hierachy hierarchybuilder.cpp FOSMBin.o
135+
130136

137+
testral: readalldata
138+
./readalldata
131139

140+
retest : testoffenbach testral
141+
echo ok

0 commit comments

Comments
 (0)