Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
1,976 additions
and 0 deletions.
- +674 −0 COPYING
- +37 −0 Makefile
- +2 −0 VERSION
- +53 −0 bz2reader.cc
- +33 −0 bz2reader.h
- +72 −0 csvwriter.cc
- +43 −0 csvwriter.h
- +362 −0 main.cc
- +94 −0 main.h
- +44 −0 osmreader.cc
- +31 −0 osmreader.h
- +188 −0 parameters.cc
- +202 −0 pqwriter.cc
- +48 −0 pqwriter.h
- +12 −0 reader.h
- +32 −0 stdinreader.cc
- +28 −0 stdinreader.h
- +21 −0 writer.h
@@ -0,0 +1,37 @@ | ||
CXX=g++ | ||
CXXFLAGS=-W -Wall -ansi -pedantic -g -Wno-deprecated | ||
LDFLAGS=-lexpat -lbz2 -lpq -lboost_program_options -lboost_filesystem | ||
EXEC=osm4routing | ||
|
||
all: $(EXEC) | ||
|
||
osm4routing: parameters.o main.o osmreader.o bz2reader.o stdinreader.o csvwriter.o pqwriter.o | ||
$(CXX) -o $@ $^ $(LDFLAGS) | ||
|
||
main.o: main.cc main.h | ||
$(CXX) -o $@ -c $< $(CXXFLAGS) | ||
|
||
parameters.o: parameters.cc main.h | ||
$(CXX) -o $@ -c $< $(CXXFLAGS) | ||
|
||
osmreader.o: osmreader.cc osmreader.h reader.h | ||
$(CXX) -o $@ -c $< $(CXXFLAGS) | ||
|
||
bz2reader.o: bz2reader.cc bz2reader.h reader.h | ||
$(CXX) -o $@ -c $< $(CXXFLAGS) | ||
|
||
stdinreader.o: stdinreader.cc stdinreader.h reader.h | ||
$(CXX) -o $@ -c $< $(CXXFLAGS) | ||
|
||
csvwriter.o: csvwriter.cc csvwriter.h writer.h | ||
$(CXX) -o $@ -c $< $(CXXFLAGS) | ||
|
||
pqwriter.o: pqwriter.cc pqwriter.h writer.h | ||
$(CXX) -o $@ -c $< $(CXXFLAGS) | ||
|
||
clean: | ||
rm -rf *.o | ||
|
||
mrproper: clean | ||
rm -rf $(EXEC) | ||
|
@@ -0,0 +1,2 @@ | ||
* 0.0 | ||
First public release |
@@ -0,0 +1,53 @@ | ||
/* | ||
This file is part of osm4routing. | ||
osm4routing is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Mumoro is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with osm4routing. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "bz2reader.h" | ||
#include <iostream> | ||
#include <cerrno> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
|
||
using namespace std; | ||
BZReader::BZReader(const std::string & filename) | ||
{ | ||
FILE* fp = fopen64(filename.c_str(), "rb"); | ||
if(!fp) | ||
{ | ||
std::cout << std::endl; | ||
std::cerr << "Error opening file " << filename << " errorno " << errno << " " << strerror(errno) << std::endl; | ||
exit(1); | ||
} | ||
|
||
b = BZ2_bzReadOpen ( &bzerror, fp, 0, 0, NULL, 0 ); | ||
if ( bzerror != BZ_OK ) | ||
{ | ||
std::cerr << "Error opening file " << filename << " as bzip2 file, errno " << bzerror << " " << | ||
BZ2_bzerror(b, &bzerror) << std::endl; | ||
BZ2_bzReadClose ( &bzerror, b ); | ||
} | ||
} | ||
|
||
int BZReader::read(char * buff, int buffsize) | ||
{ | ||
return BZ2_bzRead ( &bzerror, b, buff, buffsize ); | ||
} | ||
|
||
bool BZReader::eof() const | ||
{ | ||
return bzerror == BZ_STREAM_END; | ||
} |
@@ -0,0 +1,33 @@ | ||
/* | ||
This file is part of osm4routing. | ||
osm4routing is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Mumoro is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with osm4routing. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "reader.h" | ||
#include <bzlib.h> | ||
#include <string> | ||
|
||
#ifndef _BZ2READER_H | ||
#define _BZ2READER_H | ||
class BZReader : public Reader | ||
{ | ||
BZFILE* b; | ||
int bzerror; | ||
public: | ||
BZReader(const std::string & filename); | ||
int read(char * buff, int buffsize); | ||
bool eof() const; | ||
}; | ||
#endif |
@@ -0,0 +1,72 @@ | ||
/* | ||
This file is part of osm4routing. | ||
osm4routing is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Mumoro is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with osm4routing. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "csvwriter.h" | ||
|
||
using namespace std; | ||
|
||
CSVWriter::CSVWriter(const std::string & nodes_file, const std::string & edges_filename): | ||
nodes_filename(nodes_file) | ||
{ | ||
edges_file.open(edges_filename.c_str()); | ||
edges_file << setprecision(9); | ||
edges_file << "\"edge_id\",\"source\",\"target\",\"length\",\"car\",\"car reverse\",\"bike\",\"bike reverse\",\"foot\",\"WKT\"" << endl; | ||
} | ||
|
||
int CSVWriter::save_nodes(const NodeMapType & nodes) | ||
{ | ||
ofstream nodes_file; | ||
nodes_file.open (nodes_filename.c_str()); | ||
// By default outstream only give 4 digits after the dot (~10m precision) | ||
nodes_file << setprecision(9); | ||
nodes_file << "\"node_id\",\"longitude\",\"latitude\"" << endl; | ||
int nodes_inserted = 0; | ||
|
||
for(NodeMapType::const_iterator i = nodes.begin(); i != nodes.end(); i++) | ||
{ | ||
if( (*i).second.uses > 1 ) | ||
{ | ||
nodes_file << (*i).first << "," << | ||
(*i).second.lon << "," << | ||
(*i).second.lat << endl; | ||
nodes_inserted++; | ||
} | ||
} | ||
nodes_file.close(); | ||
return nodes_inserted; | ||
} | ||
|
||
void CSVWriter::save_edge(int edge_id, | ||
node_t source, node_t target, float length, | ||
char car_direct, char car_rev, | ||
char bike_direct, char bike_rev, | ||
char foot, | ||
std::string geom) | ||
{ | ||
edges_file << edge_id << "," << source << "," << target << "," | ||
<< length << "," | ||
<< car_direct << "," << car_rev << "," | ||
<< bike_direct << "," << bike_rev << "," | ||
<< foot << "," | ||
<< "LINESTRING(\"" << geom << "\")" << endl; | ||
} | ||
|
||
|
||
CSVWriter::~CSVWriter() | ||
{ | ||
edges_file.close(); | ||
} |
@@ -0,0 +1,43 @@ | ||
/* | ||
This file is part of osm4routing. | ||
osm4routing is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Mumoro is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with osm4routing. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "writer.h" | ||
#include <iostream> | ||
|
||
#ifndef _CSVWRITER_H | ||
#define _CSVWRITER_H | ||
|
||
class CSVWriter : public Writer | ||
{ | ||
std::ofstream edges_file; | ||
std::string nodes_filename; | ||
public: | ||
CSVWriter(const std::string & nodes_fn, const std::string & edges_fn); | ||
|
||
int save_nodes(const NodeMapType & nodes); | ||
|
||
void save_edge(int edge_id, | ||
node_t source, node_t target, float length, | ||
char car, char car_d, | ||
char bike, char bike_d, | ||
char foot, | ||
std::string geom); | ||
|
||
~CSVWriter(); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.