Skip to content

Commit 1319e22

Browse files
committed
Initial version
0 parents  commit 1319e22

19 files changed

+2063
-0
lines changed

COPYING

+674
Large diffs are not rendered by default.

Makefile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
CXX=g++
2+
CXXFLAGS=-W -Wall -ansi -pedantic -g -Wno-deprecated
3+
LDFLAGS=-lexpat -lbz2 -lpq -lboost_program_options -lboost_filesystem
4+
EXEC=osm4routing
5+
6+
all: $(EXEC)
7+
8+
osm4routing: parameters.o main.o osmreader.o bz2reader.o stdinreader.o csvwriter.o pqwriter.o
9+
$(CXX) -o $@ $^ $(LDFLAGS)
10+
11+
main.o: main.cc main.h
12+
$(CXX) -o $@ -c $< $(CXXFLAGS)
13+
14+
parameters.o: parameters.cc main.h
15+
$(CXX) -o $@ -c $< $(CXXFLAGS)
16+
17+
osmreader.o: osmreader.cc osmreader.h reader.h
18+
$(CXX) -o $@ -c $< $(CXXFLAGS)
19+
20+
bz2reader.o: bz2reader.cc bz2reader.h reader.h
21+
$(CXX) -o $@ -c $< $(CXXFLAGS)
22+
23+
stdinreader.o: stdinreader.cc stdinreader.h reader.h
24+
$(CXX) -o $@ -c $< $(CXXFLAGS)
25+
26+
csvwriter.o: csvwriter.cc csvwriter.h writer.h
27+
$(CXX) -o $@ -c $< $(CXXFLAGS)
28+
29+
pqwriter.o: pqwriter.cc pqwriter.h writer.h
30+
$(CXX) -o $@ -c $< $(CXXFLAGS)
31+
32+
clean:
33+
rm -rf *.o
34+
35+
mrproper: clean
36+
rm -rf $(EXEC)
37+

README

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
This tool provides an OpenStreetMap data parser to turn them into a nodes-edges
2+
adapted for routing applications.
3+
4+
== INPUT FORMAT ==
5+
The input is an OpenStreetMap XML file. The file can be read:
6+
* from a plain .osm file
7+
* from a bz2 file
8+
* from stdin
9+
10+
== OUTPUT FORMAT ==
11+
The output can be:
12+
* a csv file
13+
* postgis database (geographical extension to postgres).
14+
15+
In both output you'll get two files/tables:
16+
* nodes that contain
17+
* id (64 bit integer)
18+
* longitude (decimal real)
19+
* latitude (decimal real)
20+
21+
* edges that contain
22+
* id (64 bit integer)
23+
* source node id (64 bit integer)
24+
* target node id (64 bit integer)
25+
* length (real in meters),
26+
* car accessibility (integer)
27+
* car reverse accessibility (integer)
28+
* bike accessibility (integer)
29+
* bike reverse accessibility (integer)
30+
* foot accessibility (integer)
31+
* geometry (string representing a linestring in the WKT format)
32+
33+
The accessibility is an integer describing the edge for every mean of transport.
34+
As for cars an bikes the driving direction might change those properties, the
35+
are direct (source->target direction) an reverse (target->source direction)
36+
information.
37+
38+
The integers mean:
39+
* cars
40+
* 0 forbiden
41+
* 1 residential street
42+
* 2 tertiary road
43+
* 3 secondary road
44+
* 4 primary road
45+
* 5 trunk
46+
* 6 motorway
47+
* bike
48+
* 0 forbiden
49+
* 1 cycling lane in the opposite direction of the car flow
50+
* 2 allowed without specific equipment
51+
* 3 cycling lane
52+
* 4 bus lane allowed for cycles
53+
* 5 cycling track
54+
* foot (no distinction in made on the direction)
55+
* 0 forbiden
56+
* 1 allowed
57+
58+
59+
== INSTALL ==
60+
You need:
61+
* the GCC C++ complier (g++)
62+
* Boost
63+
* expat (XML parser)
64+
* libbz2 (Bzip2)
65+
* libpq (postgres)
66+
67+
Run make and it should compile.
68+
69+
70+
== USAGE ==
71+
Get the .osm XML file of the region that interests you.
72+
For limited regions, use the export tools from the web interface.
73+
For bigger regions you might find what you want at http://download.geofabrik.de/osm/
74+
75+
To know the options, run:
76+
./osm4routing --help
77+
78+
79+
== Postgres output ==
80+
The database must be a postgis database.
81+
The usual way to get is to execute the following commands (the location of
82+
lwpostgis.sql and spatial_ref_sys.sql depend on your installation).
83+
84+
createdb yourdatabase
85+
createlang plpgsql yourdatabase
86+
psql -d yourdatabase -f lwpostgis.sql
87+
psql -d yourdatabase -f spatial_ref_sys.sql

VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* 0.0
2+
First public release

bz2reader.cc

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
This file is part of osm4routing.
3+
4+
osm4routing is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Mumoro is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with osm4routing. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "bz2reader.h"
19+
#include <iostream>
20+
#include <cerrno>
21+
#include <string.h>
22+
#include <stdlib.h>
23+
24+
25+
using namespace std;
26+
BZReader::BZReader(const std::string & filename)
27+
{
28+
FILE* fp = fopen64(filename.c_str(), "rb");
29+
if(!fp)
30+
{
31+
std::cout << std::endl;
32+
std::cerr << "Error opening file " << filename << " errorno " << errno << " " << strerror(errno) << std::endl;
33+
exit(1);
34+
}
35+
36+
b = BZ2_bzReadOpen ( &bzerror, fp, 0, 0, NULL, 0 );
37+
if ( bzerror != BZ_OK )
38+
{
39+
std::cerr << "Error opening file " << filename << " as bzip2 file, errno " << bzerror << " " <<
40+
BZ2_bzerror(b, &bzerror) << std::endl;
41+
BZ2_bzReadClose ( &bzerror, b );
42+
}
43+
}
44+
45+
int BZReader::read(char * buff, int buffsize)
46+
{
47+
return BZ2_bzRead ( &bzerror, b, buff, buffsize );
48+
}
49+
50+
bool BZReader::eof() const
51+
{
52+
return bzerror == BZ_STREAM_END;
53+
}

bz2reader.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
This file is part of osm4routing.
3+
4+
osm4routing is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Mumoro is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with osm4routing. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "reader.h"
19+
#include <bzlib.h>
20+
#include <string>
21+
22+
#ifndef _BZ2READER_H
23+
#define _BZ2READER_H
24+
class BZReader : public Reader
25+
{
26+
BZFILE* b;
27+
int bzerror;
28+
public:
29+
BZReader(const std::string & filename);
30+
int read(char * buff, int buffsize);
31+
bool eof() const;
32+
};
33+
#endif

csvwriter.cc

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
This file is part of osm4routing.
3+
4+
osm4routing is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Mumoro is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with osm4routing. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "csvwriter.h"
19+
20+
using namespace std;
21+
22+
CSVWriter::CSVWriter(const std::string & nodes_file, const std::string & edges_filename):
23+
nodes_filename(nodes_file)
24+
{
25+
edges_file.open(edges_filename.c_str());
26+
edges_file << setprecision(9);
27+
edges_file << "\"edge_id\",\"source\",\"target\",\"length\",\"car\",\"car reverse\",\"bike\",\"bike reverse\",\"foot\",\"WKT\"" << endl;
28+
}
29+
30+
int CSVWriter::save_nodes(const NodeMapType & nodes)
31+
{
32+
ofstream nodes_file;
33+
nodes_file.open (nodes_filename.c_str());
34+
// By default outstream only give 4 digits after the dot (~10m precision)
35+
nodes_file << setprecision(9);
36+
nodes_file << "\"node_id\",\"longitude\",\"latitude\"" << endl;
37+
int nodes_inserted = 0;
38+
39+
for(NodeMapType::const_iterator i = nodes.begin(); i != nodes.end(); i++)
40+
{
41+
if( (*i).second.uses > 1 )
42+
{
43+
nodes_file << (*i).first << "," <<
44+
(*i).second.lon << "," <<
45+
(*i).second.lat << endl;
46+
nodes_inserted++;
47+
}
48+
}
49+
nodes_file.close();
50+
return nodes_inserted;
51+
}
52+
53+
void CSVWriter::save_edge(int edge_id,
54+
node_t source, node_t target, float length,
55+
char car_direct, char car_rev,
56+
char bike_direct, char bike_rev,
57+
char foot,
58+
std::string geom)
59+
{
60+
edges_file << edge_id << "," << source << "," << target << ","
61+
<< length << ","
62+
<< car_direct << "," << car_rev << ","
63+
<< bike_direct << "," << bike_rev << ","
64+
<< foot << ","
65+
<< "LINESTRING(\"" << geom << "\")" << endl;
66+
}
67+
68+
69+
CSVWriter::~CSVWriter()
70+
{
71+
edges_file.close();
72+
}

csvwriter.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
This file is part of osm4routing.
3+
4+
osm4routing is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Mumoro is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with osm4routing. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "writer.h"
19+
#include <iostream>
20+
21+
#ifndef _CSVWRITER_H
22+
#define _CSVWRITER_H
23+
24+
class CSVWriter : public Writer
25+
{
26+
std::ofstream edges_file;
27+
std::string nodes_filename;
28+
public:
29+
CSVWriter(const std::string & nodes_fn, const std::string & edges_fn);
30+
31+
int save_nodes(const NodeMapType & nodes);
32+
33+
void save_edge(int edge_id,
34+
node_t source, node_t target, float length,
35+
char car, char car_d,
36+
char bike, char bike_d,
37+
char foot,
38+
std::string geom);
39+
40+
~CSVWriter();
41+
};
42+
43+
#endif

0 commit comments

Comments
 (0)