PBF Support (Thanks to Christian for explanations)

This commit is contained in:
Dennis Luxen 2011-01-12 18:08:10 +00:00
parent d38adbe7f1
commit cf46fd79b0
16 changed files with 11022 additions and 570 deletions

View File

@ -275,21 +275,17 @@ public:
}
template< class InputEdge >
void CheckForAllOrigEdges(std::vector< InputEdge >& inputEdges)
{
for(unsigned int i = 0; i < inputEdges.size(); i++)
{
void CheckForAllOrigEdges(std::vector< InputEdge >& inputEdges) {
for(unsigned int i = 0; i < inputEdges.size(); i++) {
bool found = false;
_DynamicGraph::EdgeIterator eit = _graph->BeginEdges(inputEdges[i].source());
for(;eit<_graph->EndEdges(inputEdges[i].source()); eit++)
{
if(_graph->GetEdgeData(eit).distance = inputEdges[i].weight())
for(;eit<_graph->EndEdges(inputEdges[i].source()); eit++) {
if(_graph->GetEdgeData(eit).distance == inputEdges[i].weight())
found = true;
}
eit = _graph->BeginEdges(inputEdges[i].target());
for(;eit<_graph->EndEdges(inputEdges[i].target()); eit++)
{
if(_graph->GetEdgeData(eit).distance = inputEdges[i].weight())
for(;eit<_graph->EndEdges(inputEdges[i].target()); eit++) {
if(_graph->GetEdgeData(eit).distance == inputEdges[i].weight())
found = true;
}
assert(found);
@ -303,7 +299,7 @@ public:
unsigned maxThreads = omp_get_max_threads();
std::vector < _ThreadData* > threadData;
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
threadData.push_back( new _ThreadData( numberOfNodes ) );
}
cout << "Contractor is using " << maxThreads << " threads" << endl;
@ -388,7 +384,7 @@ public:
timeLast = _Timestamp();
//insert new edges
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
_ThreadData& data = *threadData[threadNum];
for ( int i = 0; i < ( int ) data.insertedEdges.size(); ++i ) {
const _ImportEdge& edge = data.insertedEdges[i];
@ -442,14 +438,11 @@ public:
p.printStatus(levelID);
}
for ( int threadNum = 0; threadNum < maxThreads; threadNum++ ) {
// _witnessList.insert( _witnessList.end(), threadData[threadNum]->witnessList.begin(), threadData[threadNum]->witnessList.end() );
for ( unsigned threadNum = 0; threadNum < maxThreads; threadNum++ ) {
delete threadData[threadNum];
}
// log.PrintSummary();
// cout << "Total Time: " << log.GetSum().GetTotalTime()<< " s" << endl;
cout << "checking sanity of generated data ..." << flush;
cout << "[contractor] checking sanity of generated data ..." << flush;
_CheckCH<_EdgeData>();
cout << "ok" << endl;
}
@ -595,7 +588,7 @@ private:
if ( node != source )
heap.Insert( node, inData.distance, _HeapData() );
int maxDistance = 0;
unsigned numTargets = 0;
//unsigned numTargets = 0;
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
const _EdgeData& outData = _graph->GetEdgeData( outEdge );

View File

@ -0,0 +1,34 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef BASEPARSER_H_
#define BASEPARSER_H_
template<typename NodeT, typename RelationT, typename WayT>
class BaseParser {
public:
virtual ~BaseParser() {}
virtual bool Init() = 0;
virtual bool RegisterCallbacks(bool (*nodeCallbackPointer)(NodeT), bool (*relationCallbackPointer)(RelationT), bool (*wayCallbackPointer)(WayT)) = 0;
virtual bool Parse() = 0;
private:
};
#endif /* BASEPARSER_H_ */

View File

@ -50,8 +50,6 @@ std::string names[14] = { "motorway", "motorway_link", "trunk", "trunk_link", "p
double speeds[14] = { 110, 90, 90, 70, 70, 60, 60, 50, 55, 25, 40 , 10, 30, 5};
struct _Node : NodeInfo{
bool trafficSignal;
_Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {}
_Node() {}
@ -77,15 +75,26 @@ struct _Coordinate {
};
struct _Way {
_Way() {
direction = _Way::notSure;
maximumSpeed = -1;
type = -1;
useful = false;
access = true;
}
std::vector< NodeID > path;
enum {
notSure = 0, oneway, bidirectional, opposite
} direction;
unsigned id;
unsigned nameID;
std::string name;
double maximumSpeed;
bool usefull:1;
bool useful:1;
bool access:1;
short type;
HashTable<std::string, std::string> keyVals;
};
struct _Relation {
@ -114,11 +123,11 @@ struct Settings {
vector< double > speed;
vector< string > names;
} speedProfile;
// vector<string> accessList;
int trafficLightPenalty;
// vector<string> accessList;
// int trafficLightPenalty;
int indexInAccessListOf( const string & key)
{
for(int i = 0; i< speedProfile.names.size(); i++)
for(unsigned i = 0; i< speedProfile.names.size(); i++)
{
if(speedProfile.names[i] == key)
return i;
@ -195,265 +204,6 @@ struct CmpNodeByID : public std::binary_function<_Node, _Node, bool>
}
};
_Way _ReadXMLWay( xmlTextReaderPtr& inputReader, Settings& settings, string& name) {
_Way way;
way.direction = _Way::notSure;
way.maximumSpeed = -1;
way.type = -1;
way.usefull = false;
way.access = true;
// cout << "new way" << endl;
if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {
const int depth = xmlTextReaderDepth( inputReader );
while ( xmlTextReaderRead( inputReader ) == 1 ) {
const int childType = xmlTextReaderNodeType( inputReader );
if ( childType != 1 && childType != 15 )
continue;
const int childDepth = xmlTextReaderDepth( inputReader );
xmlChar* childName = xmlTextReaderName( inputReader );
if ( childName == NULL )
continue;
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) {
xmlFree( childName );
break;
}
if ( childType != 1 ) {
xmlFree( childName );
continue;
}
if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) {
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
// cout << "->k=" << k << ", v=" << value << endl;
if ( k != NULL && value != NULL ) {
if ( xmlStrEqual( k, ( const xmlChar* ) "name" ) == 1 ) {
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( value, ( const xmlChar* ) "no" ) == 1 || xmlStrEqual( value, ( const xmlChar* ) "false" ) == 1 || xmlStrEqual( value, ( const xmlChar* ) "0" ) == 1 )
way.direction = _Way::bidirectional;
else if ( xmlStrEqual( value, ( const xmlChar* ) "yes" ) == 1 || xmlStrEqual( value, ( const xmlChar* ) "true" ) == 1 || xmlStrEqual( value, ( const xmlChar* ) "1" ) == 1 )
way.direction = _Way::oneway;
else if ( xmlStrEqual( value, ( const xmlChar* ) "-1" ) == 1 )
way.direction = _Way::opposite;
} else if ( xmlStrEqual( k, ( const xmlChar* ) "junction" ) == 1 ) {
if ( xmlStrEqual( value, ( const xmlChar* ) "roundabout" ) == 1 ) {
if ( way.direction == _Way::notSure ) {
way.direction = _Way::oneway;
}
way.usefull = true;
if(way.type == -1)
way.type = 9;
}
} else if ( xmlStrEqual( k, ( const xmlChar* ) "route" ) == 1 ) {
string name( (const char* ) value );
if (name == "ferry") {
for ( int i = 0; i < settings.speedProfile.names.size(); i++ ) {
if ( name == settings.speedProfile.names[i] ) {
way.type = i;
way.maximumSpeed = settings.speedProfile.speed[i];
way.usefull = true;
way.direction == _Way::bidirectional;
break;
}
}
}
} else if ( xmlStrEqual( k, ( const xmlChar* ) "highway" ) == 1 ) {
string name( ( const char* ) value );
for ( int i = 0; i < settings.speedProfile.names.size(); i++ ) {
if ( name == settings.speedProfile.names[i] ) {
way.type = i;
way.usefull = true;
break;
}
}
if ( name == "motorway" ) {
if ( way.direction == _Way::notSure ) {
way.direction = _Way::oneway;
}
} else if ( name == "motorway_link" ) {
if ( way.direction == _Way::notSure ) {
way.direction = _Way::oneway;
}
}
} else if ( xmlStrEqual( k, ( const xmlChar* ) "maxspeed" ) == 1 ) {
double maxspeed = atof(( const char* ) value );
xmlChar buffer[100];
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lf", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lf kmh", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lfkmh", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lf km/h", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lfkm/h", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lf mph", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lfmph", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lf mp/h", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
} else {
xmlStrPrintf( buffer, 100, ( const xmlChar* ) "%.lfmp/h", maxspeed );
if ( xmlStrEqual( value, buffer ) == 1 ) {
way.maximumSpeed = maxspeed;
}
}
}
}
}
}
}
}
}
} else {
if ( xmlStrEqual( k, (const xmlChar*) "access" ))
{
if ( xmlStrEqual( value, ( const xmlChar* ) "private" ) == 1)
if ( xmlStrEqual( value, ( const xmlChar* ) "private" ) == 1
|| xmlStrEqual( value, ( const xmlChar* ) "no" ) == 1
|| xmlStrEqual( value, ( const xmlChar* ) "agricultural" ) == 1
|| xmlStrEqual( value, ( const xmlChar* ) "forestry" ) == 1
|| xmlStrEqual( value, ( const xmlChar* ) "delivery" ) == 1
) {
way.access = false;
}
else if ( xmlStrEqual( value, ( const xmlChar* ) "yes" ) == 1
|| xmlStrEqual( value, ( const xmlChar* ) "designated" ) == 1
|| xmlStrEqual( value, ( const xmlChar* ) "official" ) == 1
|| xmlStrEqual( value, ( const xmlChar* ) "permissive" ) == 1
) {
way.access = true;
}
}
if ( xmlStrEqual( k, (const xmlChar*) "motorcar" ))
{
if ( xmlStrEqual( value, ( const xmlChar* ) "yes" ) == 1)
{
way.access = true;
} else if ( xmlStrEqual( k, (const xmlChar*) "no" )) {
way.access = false;
}
}
}
if ( k != NULL )
xmlFree( k );
if ( value != NULL )
xmlFree( value );
}
} else if ( xmlStrEqual( childName, ( const xmlChar* ) "nd" ) == 1 ) {
xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" );
if ( ref != NULL ) {
way.path.push_back( atoi(( const char* ) ref ) );
xmlFree( ref );
}
}
xmlFree( childName );
}
}
return way;
}
_Node _ReadXMLNode( xmlTextReaderPtr& inputReader ) {
_Node node;
node.trafficSignal = false;
xmlChar* attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lat" );
if ( attribute != NULL ) {
node.lat = static_cast<NodeID>(100000.*atof(( const char* ) attribute ) );
xmlFree( attribute );
}
attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lon" );
if ( attribute != NULL ) {
node.lon = static_cast<NodeID>(100000.*atof(( const char* ) attribute ));
xmlFree( attribute );
}
attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" );
if ( attribute != NULL ) {
node.id = atoi(( const char* ) attribute );
xmlFree( attribute );
}
if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {
const int depth = xmlTextReaderDepth( inputReader );
while ( xmlTextReaderRead( inputReader ) == 1 ) {
const int childType = xmlTextReaderNodeType( inputReader );
// 1 = Element, 15 = EndElement
if ( childType != 1 && childType != 15 )
continue;
const int childDepth = xmlTextReaderDepth( inputReader );
xmlChar* childName = xmlTextReaderName( inputReader );
if ( childName == NULL )
continue;
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "node" ) == 1 ) {
xmlFree( childName );
break;
}
if ( childType != 1 ) {
xmlFree( childName );
continue;
}
if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) {
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
if ( k != NULL && value != NULL ) {
if ( xmlStrEqual( k, ( const xmlChar* ) "highway" ) == 1 ) {
if ( xmlStrEqual( value, ( const xmlChar* ) "traffic_signals" ) == 1 )
node.trafficSignal = true;
}
}
if ( k != NULL )
xmlFree( k );
if ( value != NULL )
xmlFree( value );
}
xmlFree( childName );
}
}
return node;
}
_Relation _ReadXMLRelation ( xmlTextReaderPtr& inputReader ) {
_Relation relation;
relation.type = _Relation::unknown;
return relation;
}
double ApproximateDistance( const int lat1, const int lon1, const int lat2, const int lon2 ) {
static const double DEG_TO_RAD = 0.017453292519943295769236907684886;
///Earth's quatratic mean radius for WGS-84
@ -472,15 +222,15 @@ double ApproximateDistance( const int lat1, const int lon1, const int lat2, cons
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
double GetAngleBetweenTwoEdges(const _Coordinate& A, const _Coordinate& C, const _Coordinate& B)
{
// double a = ApproximateDistance(A.lat, A.lon, C.lat, C.lon); //first edge segment
// double b = ApproximateDistance(B.lat, B.lon, C.lat, C.lon); //second edge segment
// double c = ApproximateDistance(A.lat, A.lon, B.lat, B.lon); //third edgefrom triangle
//
// double cosAlpha = (a*a + b*b - c*c)/ (2*a*b);
//
// double alpha = ( (acos(cosAlpha) * 180.0 / M_PI) * (cosAlpha > 0 ? -1 : 1) ) + 180;
// return alpha;
// V = <x2 - x1, y2 - y1>
// double a = ApproximateDistance(A.lat, A.lon, C.lat, C.lon); //first edge segment
// double b = ApproximateDistance(B.lat, B.lon, C.lat, C.lon); //second edge segment
// double c = ApproximateDistance(A.lat, A.lon, B.lat, B.lon); //third edgefrom triangle
//
// double cosAlpha = (a*a + b*b - c*c)/ (2*a*b);
//
// double alpha = ( (acos(cosAlpha) * 180.0 / M_PI) * (cosAlpha > 0 ? -1 : 1) ) + 180;
// return alpha;
// V = <x2 - x1, y2 - y1>
int v1x = A.lon - C.lon;
int v1y = A.lat - C.lat;
int v2x = B.lon - C.lon;

View File

@ -181,7 +181,7 @@ public:
delete entries;
}
for(int i = 0; i< indexFileStreams.size(); i++) {
for(unsigned i = 0; i< indexFileStreams.size(); i++) {
delete indexFileStreams[i];
}
threadLookup.EraseAll();
@ -207,7 +207,7 @@ public:
std::vector<std::pair<unsigned, unsigned> > indexList;
getListOfIndexesForEdgeAndGridSize(start, target, indexList);
for(int i = 0; i < indexList.size(); i++)
for(unsigned i = 0; i < indexList.size(); i++)
{
entries->push_back(GridEdgeData(edge, indexList[i].first, indexList[i].second));
}
@ -381,7 +381,7 @@ private:
}
}
for(int i = 0; i < entriesWithSameRAMIndex.size() -1; i++)
for(unsigned i = 0; i < entriesWithSameRAMIndex.size() -1; i++)
{
assert(entriesWithSameRAMIndex[i].ramIndex== entriesWithSameRAMIndex[i+1].ramIndex);
}
@ -431,7 +431,7 @@ private:
}
//write contents of tmpbuffer to disk
for(int i = 0; i < indexIntoTmpBuffer; i++)
for(unsigned i = 0; i < indexIntoTmpBuffer; i++)
{
indexOutFile.write(&(tmpBuffer->at(i)), sizeof(char));
numberOfWrittenBytes += sizeof(char);
@ -448,7 +448,7 @@ private:
unsigned counter = 0;
unsigned max = UINT_MAX;
for(int i = 0; i < vectorWithSameFileIndex.size()-1; i++)
for(unsigned i = 0; i < vectorWithSameFileIndex.size()-1; i++)
{
assert( vectorWithSameFileIndex[i].fileIndex == vectorWithSameFileIndex[i+1].fileIndex );
assert( vectorWithSameFileIndex[i].ramIndex == vectorWithSameFileIndex[i+1].ramIndex );
@ -457,44 +457,44 @@ private:
for(std::vector<GridEdgeData>::const_iterator et = vectorWithSameFileIndex.begin(); et != vectorWithSameFileIndex.end(); et++)
{
char * start = (char *)&et->edge.start;
for(int i = 0; i < sizeof(NodeID); i++)
for(unsigned i = 0; i < sizeof(NodeID); i++)
{
tmpBuffer->at(index+counter) = start[i];
counter++;
}
char * target = (char *)&et->edge.target;
for(int i = 0; i < sizeof(NodeID); i++)
for(unsigned i = 0; i < sizeof(NodeID); i++)
{
tmpBuffer->at(index+counter) = target[i];
counter++;
}
char * slat = (char *) &(et->edge.startCoord.lat);
for(int i = 0; i < sizeof(int); i++)
for(unsigned i = 0; i < sizeof(int); i++)
{
tmpBuffer->at(index+counter) = slat[i];
counter++;
}
char * slon = (char *) &(et->edge.startCoord.lon);
for(int i = 0; i < sizeof(int); i++)
for(unsigned i = 0; i < sizeof(int); i++)
{
tmpBuffer->at(index+counter) = slon[i];
counter++;
}
char * tlat = (char *) &(et->edge.targetCoord.lat);
for(int i = 0; i < sizeof(int); i++)
for(unsigned i = 0; i < sizeof(int); i++)
{
tmpBuffer->at(index+counter) = tlat[i];
counter++;
}
char * tlon = (char *) &(et->edge.targetCoord.lon);
for(int i = 0; i < sizeof(int); i++)
for(unsigned i = 0; i < sizeof(int); i++)
{
tmpBuffer->at(index+counter) = tlon[i];
counter++;
}
}
char * umax = (char *) &max;
for(int i = 0; i < sizeof(unsigned); i++)
for(unsigned i = 0; i < sizeof(unsigned); i++)
{
tmpBuffer->at(index+counter) = umax[i];
counter++;

View File

@ -66,6 +66,7 @@ public:
inline bool FindRoutingStarts(const _Coordinate start, const _Coordinate target, PhantomNodes * phantomNodes) {
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes);
return true;
}
inline void RegisterThread(const unsigned k, const unsigned v) {

421
DataStructures/PBFParser.h Normal file
View File

@ -0,0 +1,421 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef PBFPARSER_H_
#define PBFPARSER_H_
#include <zlib.h>
#include "BaseParser.h"
#include "pbf-proto/fileformat.pb.h"
#include "pbf-proto/osmformat.pb.h"
#include "../typedefs.h"
#include "HashTable.h"
#include "ExtractorStructs.h"
class PBFParser : public BaseParser<_Node, _Relation, _Way> {
enum EntityType {
TypeNode = 1,
TypeWay = 2,
TypeRelation = 4,
TypeDenseNode = 8
} ;
enum Endianness {
LittleEndian = 1,
BigEndian = 2
};
short entityTypeIndicator;
public:
PBFParser(const char * fileName) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
input.open(fileName, std::ios::in | std::ios::binary);
if (!input) {
std::cerr << fileName << ": File not found." << std::endl;
}
blockCount = 0;
groupCount = 0;
}
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*relationCallbackPointer)(_Relation), bool (*wayCallbackPointer)(_Way) ) {
nodeCallback = *nodeCallbackPointer;
wayCallback = *wayCallbackPointer;
relationCallback = *relationCallbackPointer;
return true;
}
~PBFParser() {
if(input.is_open())
input.close();
google::protobuf::ShutdownProtobufLibrary();
std::cout << "[info] blocks: " << blockCount << std::endl;
std::cout << "[info] groups: " << groupCount << std::endl;
}
bool Init() {
if(!readPBFBlobHeader(input)) {
return false;
}
if(readBlob(input)) {
char data[charBuffer.size()];
for(unsigned i = 0; i < charBuffer.size(); i++ ){
data[i] = charBuffer[i];
}
if(!PBFHeaderBlock.ParseFromArray(data, charBuffer.size() ) ) {
std::cerr << "[error] Header not parseable!" << std::endl;
return false;
}
for(int i = 0; i < PBFHeaderBlock.required_features_size(); i++) {
const std::string& feature = PBFHeaderBlock.required_features( i );
bool supported = false;
if ( feature == "OsmSchema-V0.6" )
supported = true;
else if ( feature == "DenseNodes" )
supported = true;
if ( !supported ) {
std::cerr << "[error] required feature not supported: " << feature.data() << std::endl;
return false;
}
}
} else {
std::cerr << "[error] blob not loaded!" << std::endl;
}
return true;
}
bool Parse() {
//parse through all Blocks
while(readNextBlock(input)) {
loadBlock();
for(int i = 0; i < PBFprimitiveBlock.primitivegroup_size(); i++) {
currentGroupID = i;
loadGroup();
if(entityTypeIndicator == TypeNode)
parseNode();
if(entityTypeIndicator == TypeWay)
parseWay();
if(entityTypeIndicator == TypeRelation)
parseRelation();
if(entityTypeIndicator == TypeDenseNode)
parseDenseNode();
}
}
return true;
}
private:
void parseDenseNode() {
const OSMPBF::DenseNodes& dense = PBFprimitiveBlock.primitivegroup( currentGroupID ).dense();
int denseTagIndex = 0;
int m_lastDenseID = 0;
int m_lastDenseLatitude = 0;
int m_lastDenseLongitude = 0;
for(int i = 0; i < dense.id_size(); i++) {
m_lastDenseID += dense.id( i );
m_lastDenseLatitude += dense.lat( i );
m_lastDenseLongitude += dense.lon( i );
_Node n;
n.id = m_lastDenseID;
n.lat = 100000*( ( double ) m_lastDenseLatitude * PBFprimitiveBlock.granularity() + PBFprimitiveBlock.lat_offset() ) / NANO;
n.lon = 100000*( ( double ) m_lastDenseLongitude * PBFprimitiveBlock.granularity() + PBFprimitiveBlock.lon_offset() ) / NANO;
while (denseTagIndex < dense.keys_vals_size()) {
int tagValue = dense.keys_vals( denseTagIndex );
if(tagValue == 0) {
denseTagIndex++;
break;
}
//int keyValue = dense.keys_vals ( denseTagIndex+1 );
/* Key/Value Pairs are known from here on */
// std::cout << "[debug] node: " << n.id << std::endl;
// std::cout << "[debug] key = " << PBFprimitiveBlock.stringtable().s(tagValue).data() << ", value: " << PBFprimitiveBlock.stringtable().s(keyValue).data() << std::endl;
denseTagIndex += 2;
}
if(!(*nodeCallback)(n))
std::cerr << "[PBFParser] dense node not parsed" << std::endl;
}
}
void parseNode() {
_Node n;
if(!(*nodeCallback)(n))
std::cerr << "[PBFParser] simple node not parsed" << std::endl;
}
void parseRelation() {
const OSMPBF::PrimitiveGroup& group = PBFprimitiveBlock.primitivegroup( currentGroupID );
for(int i = 0; i < group.relations_size(); i++ ) {
_Relation r;
r.type = _Relation::unknown;
if(!(*relationCallback)(r))
std::cerr << "[PBFParser] relation not parsed" << std::endl;
}
}
void parseWay() {
if( PBFprimitiveBlock.primitivegroup( currentGroupID ).ways_size() > 0) {
for(int i = 0; i < PBFprimitiveBlock.primitivegroup( currentGroupID ).ways_size(); i++) {
const OSMPBF::Way& inputWay = PBFprimitiveBlock.primitivegroup( currentGroupID ).ways( i );
_Way w;
w.id = inputWay.id();
unsigned pathNode(0);
for(int i = 0; i < inputWay.refs_size(); i++) {
pathNode += inputWay.refs(i);
w.path.push_back(pathNode);
}
assert(inputWay.keys_size() == inputWay.vals_size());
for(int i = 0; i < inputWay.keys_size(); i++) {
// std::cout << "[debug] key: " << PBFprimitiveBlock.stringtable().s(inputWay.keys(i)) << ", val: " << PBFprimitiveBlock.stringtable().s(inputWay.vals(i)) << std::endl;
const std::string key = PBFprimitiveBlock.stringtable().s(inputWay.keys(i));
const std::string val = PBFprimitiveBlock.stringtable().s(inputWay.vals(i));
w.keyVals.Add(key, val);
}
if(!(*wayCallback)(w)) {
std::cerr << "[PBFParser] way not parsed" << std::endl;
}
}
}
}
void loadGroup() {
groupCount++;
const OSMPBF::PrimitiveGroup& group = PBFprimitiveBlock.primitivegroup( currentGroupID );
entityTypeIndicator = 0;
if ( group.nodes_size() != 0 ) {
entityTypeIndicator = TypeNode;
}
if ( group.ways_size() != 0 ) {
entityTypeIndicator = TypeWay;
}
if ( group.relations_size() != 0 ) {
entityTypeIndicator = TypeRelation;
}
if ( group.has_dense() ) {
entityTypeIndicator = TypeDenseNode;
assert( group.dense().id_size() != 0 );
}
assert( entityTypeIndicator != 0 );
}
void loadBlock() {
blockCount++;
currentGroupID = 0;
currentEntityID = 0;
// int stringCount = PBFprimitiveBlock.stringtable().s_size();
}
/* Reverses Network Byte Order into something usable */
inline unsigned swapEndian(unsigned x) {
if(getMachineEndianness() == LittleEndian)
return ( (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24) );
return x;
}
bool readPBFBlobHeader(std::fstream& stream) {
int size(0);
stream.read((char *)&size, sizeof(int));
size = swapEndian(size);
if(stream.eof()) {
return false;
}
if ( size > MAX_BLOB_HEADER_SIZE || size < 0 ) {
return false;
}
char data[size];
for(int i = 0; i < size; i++) {
stream.read(&data[i], 1);
}
if ( !PBFBlobHeader.ParseFromArray( data, size ) ) {
return false;
}
return true;
}
bool unpackZLIB(std::fstream & stream) {
unsigned rawSize = PBFBlob.raw_size();
char unpackedDataArray[rawSize];
z_stream compressedDataStream;
compressedDataStream.next_in = ( unsigned char* ) PBFBlob.zlib_data().data();
compressedDataStream.avail_in = PBFBlob.zlib_data().size();
compressedDataStream.next_out = ( unsigned char* ) unpackedDataArray;
compressedDataStream.avail_out = rawSize;
compressedDataStream.zalloc = Z_NULL;
compressedDataStream.zfree = Z_NULL;
compressedDataStream.opaque = Z_NULL;
int ret = inflateInit( &compressedDataStream );
if ( ret != Z_OK ) {
std::cerr << "[error] failed to init zlib stream" << std::endl;
return false;
}
ret = inflate( &compressedDataStream, Z_FINISH );
if ( ret != Z_STREAM_END ) {
std::cerr << "[error] failed to inflate zlib stream" << std::endl;
return false;
}
ret = inflateEnd( &compressedDataStream );
if ( ret != Z_OK ) {
std::cerr << "[error] failed to deinit zlib stream" << std::endl;
return false;
}
charBuffer.clear(); charBuffer.resize(rawSize);
for(unsigned i = 0; i < rawSize; i++) {
charBuffer[i] = unpackedDataArray[i];
}
return true;
}
bool unpackLZMA(std::fstream & stream) {
return false;
}
bool readBlob(std::fstream& stream) {
if(stream.eof())
return false;
int size = PBFBlobHeader.datasize();
if ( size < 0 || size > MAX_BLOB_SIZE ) {
std::cerr << "[error] invalid Blob size:" << size << std::endl;
return false;
}
char data[size];
for(int i = 0; i < size; i++) {
stream.read(&data[i], 1);
}
if ( !PBFBlob.ParseFromArray( data, size ) ) {
std::cerr << "[error] failed to parse blob" << std::endl;
return false;
}
if ( PBFBlob.has_raw() ) {
const std::string& data = PBFBlob.raw();
charBuffer.clear();
charBuffer.resize( data.size() );
for ( unsigned i = 0; i < data.size(); i++ ) {
charBuffer[i] = data[i];
}
} else if ( PBFBlob.has_zlib_data() ) {
if ( !unpackZLIB(stream) ) {
std::cerr << "[error] zlib data encountered that could not be unpacked" << std::endl;
return false;
}
} else if ( PBFBlob.has_lzma_data() ) {
if ( !unpackLZMA(stream) )
std::cerr << "[error] lzma data encountered that could not be unpacked" << std::endl;
return false;
} else {
std::cerr << "[error] Blob contains no data" << std::endl;
return false;
}
return true;
}
bool readNextBlock(std::fstream& stream) {
if(stream.eof()) {
return false;
}
if ( !readPBFBlobHeader(stream) )
return false;
if ( PBFBlobHeader.type() != "OSMData" ) {
std::cerr << "[error] invalid block type, found" << PBFBlobHeader.type().data() << "instead of OSMData" << std::endl;
return false;
}
if ( !readBlob(stream) )
return false;
char data[charBuffer.size()];
for(unsigned i = 0; i < charBuffer.size(); i++ ){
data[i] = charBuffer[i];
}
if ( !PBFprimitiveBlock.ParseFromArray( data, charBuffer.size() ) ) {
std::cerr << "[error] failed to parse PrimitiveBlock" << std::endl;
return false;
}
return true;
}
Endianness getMachineEndianness() {
int i(1);
char *p = (char *) &i;
if (p[0] == 1)
return LittleEndian;
return BigEndian;
}
static const int NANO = 1000 * 1000 * 1000;
static const int MAX_BLOB_HEADER_SIZE = 64 * 1024;
static const int MAX_BLOB_SIZE = 32 * 1024 * 1024;
OSMPBF::BlobHeader PBFBlobHeader;
OSMPBF::Blob PBFBlob;
OSMPBF::HeaderBlock PBFHeaderBlock;
OSMPBF::PrimitiveBlock PBFprimitiveBlock;
std::vector<char> charBuffer;
int currentGroupID;
int currentEntityID;
// bool m_loadBlock;
// long long m_lastDenseID;
// long long m_lastDenseLatitude;
// long long m_lastDenseLongitude;
// int m_lastDenseTag;
/* counting the number of read blocks and groups */
unsigned groupCount;
unsigned blockCount;
/* Function pointer for nodes */
bool (*nodeCallback)(_Node);
bool (*wayCallback)(_Way);
bool (*relationCallback)(_Relation);
/* the input stream to parse */
std::fstream input;
};
#endif /* PBFPARSER_H_ */

217
DataStructures/XMLParser.h Normal file
View File

@ -0,0 +1,217 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef XMLPARSER_H_
#define XMLPARSER_H_
#include <libxml/xmlreader.h>
#include "../typedefs.h"
#include "BaseParser.h"
#include "HashTable.h"
#include "ExtractorStructs.h"
#include "InputReaderFactory.h"
class XMLParser : public BaseParser<_Node, _Relation, _Way> {
public:
XMLParser(const char * filename) {
inputReader = inputReaderFactory(filename);
}
~XMLParser() {}
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*relationCallbackPointer)(_Relation), bool (*wayCallbackPointer)(_Way) ) {
nodeCallback = *nodeCallbackPointer;
wayCallback = *wayCallbackPointer;
relationCallback = *relationCallbackPointer;
return true;
}
bool Init() {
return (xmlTextReaderRead( inputReader ) == 1);
}
bool Parse() {
while ( xmlTextReaderRead( inputReader ) == 1 ) {
const int type = xmlTextReaderNodeType( inputReader );
//1 is Element
if ( type != 1 )
continue;
xmlChar* currentName = xmlTextReaderName( inputReader );
if ( currentName == NULL )
continue;
if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) {
_Node n = _ReadXMLNode( );
if(!(*nodeCallback)(n))
std::cerr << "[XMLParser] node not parsed" << std::endl;
}
if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) {
string name;
_Way way = _ReadXMLWay( );
if(!(*wayCallback)(way)) {
std::cerr << "[XMLParser] way not parsed" << std::endl;
}
}
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
_Relation r;
r.type = _Relation::unknown;
if(!(*relationCallback)(r))
std::cerr << "[error] relation not parsed" << std::endl;
}
xmlFree( currentName );
}
return true;
}
private:
_Relation _ReadXMLRelation ( ) {
_Relation relation;
relation.type = _Relation::unknown;
return relation;
}
_Way _ReadXMLWay( ) {
_Way way;
way.direction = _Way::notSure;
way.maximumSpeed = -1;
way.type = -1;
way.useful = false;
way.access = true;
// cout << "new way" << endl;
if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {
const int depth = xmlTextReaderDepth( inputReader );
while ( xmlTextReaderRead( inputReader ) == 1 ) {
const int childType = xmlTextReaderNodeType( inputReader );
if ( childType != 1 && childType != 15 )
continue;
const int childDepth = xmlTextReaderDepth( inputReader );
xmlChar* childName = xmlTextReaderName( inputReader );
if ( childName == NULL )
continue;
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) {
xmlFree( childName );
break;
}
if ( childType != 1 ) {
xmlFree( childName );
continue;
}
if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) {
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
// cout << "->k=" << k << ", v=" << value << endl;
if ( k != NULL && value != NULL ) {
way.keyVals.Add(std::string( (char *) k ), std::string( (char *) value));
}
if ( k != NULL )
xmlFree( k );
if ( value != NULL )
xmlFree( value );
} else if ( xmlStrEqual( childName, ( const xmlChar* ) "nd" ) == 1 ) {
xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" );
if ( ref != NULL ) {
way.path.push_back( atoi(( const char* ) ref ) );
xmlFree( ref );
}
}
xmlFree( childName );
}
}
return way;
}
_Node _ReadXMLNode( ) {
_Node node;
xmlChar* attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lat" );
if ( attribute != NULL ) {
node.lat = static_cast<NodeID>(100000.*atof(( const char* ) attribute ) );
xmlFree( attribute );
}
attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lon" );
if ( attribute != NULL ) {
node.lon = static_cast<NodeID>(100000.*atof(( const char* ) attribute ));
xmlFree( attribute );
}
attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" );
if ( attribute != NULL ) {
node.id = atoi(( const char* ) attribute );
xmlFree( attribute );
}
if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {
const int depth = xmlTextReaderDepth( inputReader );
while ( xmlTextReaderRead( inputReader ) == 1 ) {
const int childType = xmlTextReaderNodeType( inputReader );
// 1 = Element, 15 = EndElement
if ( childType != 1 && childType != 15 )
continue;
const int childDepth = xmlTextReaderDepth( inputReader );
xmlChar* childName = xmlTextReaderName( inputReader );
if ( childName == NULL )
continue;
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "node" ) == 1 ) {
xmlFree( childName );
break;
}
if ( childType != 1 ) {
xmlFree( childName );
continue;
}
if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) {
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
if ( k != NULL && value != NULL ) {
if ( xmlStrEqual( k, ( const xmlChar* ) "highway" ) == 1 ) {
if ( xmlStrEqual( value, ( const xmlChar* ) "traffic_signals" ) == 1 ){
//node.trafficSignal = true;
}
}
}
if ( k != NULL )
xmlFree( k );
if ( value != NULL )
xmlFree( value );
}
xmlFree( childName );
}
}
return node;
}
/* Input Reader */
xmlTextReaderPtr inputReader;
/* Function pointer for nodes */
bool (*nodeCallback)(_Node);
bool (*wayCallback)(_Way);
bool (*relationCallback)(_Relation);
};
#endif /* XMLPARSER_H_ */

View File

@ -0,0 +1,848 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include "fileformat.pb.h"
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// @@protoc_insertion_point(includes)
namespace OSMPBF {
namespace {
const ::google::protobuf::Descriptor* Blob_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
Blob_reflection_ = NULL;
const ::google::protobuf::Descriptor* BlobHeader_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
BlobHeader_reflection_ = NULL;
} // namespace
void protobuf_AssignDesc_fileformat_2eproto() {
protobuf_AddDesc_fileformat_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"fileformat.proto");
GOOGLE_CHECK(file != NULL);
Blob_descriptor_ = file->message_type(0);
static const int Blob_offsets_[5] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Blob, raw_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Blob, raw_size_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Blob, zlib_data_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Blob, lzma_data_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Blob, obsolete_bzip2_data_),
};
Blob_reflection_ =
new ::google::protobuf::internal::GeneratedMessageReflection(
Blob_descriptor_,
Blob::default_instance_,
Blob_offsets_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Blob, _has_bits_[0]),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Blob, _unknown_fields_),
-1,
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(Blob));
BlobHeader_descriptor_ = file->message_type(1);
static const int BlobHeader_offsets_[3] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BlobHeader, type_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BlobHeader, indexdata_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BlobHeader, datasize_),
};
BlobHeader_reflection_ =
new ::google::protobuf::internal::GeneratedMessageReflection(
BlobHeader_descriptor_,
BlobHeader::default_instance_,
BlobHeader_offsets_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BlobHeader, _has_bits_[0]),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BlobHeader, _unknown_fields_),
-1,
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(BlobHeader));
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
inline void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_fileformat_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
Blob_descriptor_, &Blob::default_instance());
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
BlobHeader_descriptor_, &BlobHeader::default_instance());
}
} // namespace
void protobuf_ShutdownFile_fileformat_2eproto() {
delete Blob::default_instance_;
delete Blob_reflection_;
delete BlobHeader::default_instance_;
delete BlobHeader_reflection_;
}
void protobuf_AddDesc_fileformat_2eproto() {
static bool already_here = false;
if (already_here) return;
already_here = true;
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\020fileformat.proto\022\006OSMPBF\"l\n\004Blob\022\013\n\003ra"
"w\030\001 \001(\014\022\020\n\010raw_size\030\002 \001(\005\022\021\n\tzlib_data\030\003"
" \001(\014\022\021\n\tlzma_data\030\004 \001(\014\022\037\n\023OBSOLETE_bzip"
"2_data\030\005 \001(\014B\002\030\001\"?\n\nBlobHeader\022\014\n\004type\030\001"
" \002(\t\022\021\n\tindexdata\030\002 \001(\014\022\020\n\010datasize\030\003 \002("
"\005B\017\n\rcrosby.binary", 218);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"fileformat.proto", &protobuf_RegisterTypes);
Blob::default_instance_ = new Blob();
BlobHeader::default_instance_ = new BlobHeader();
Blob::default_instance_->InitAsDefaultInstance();
BlobHeader::default_instance_->InitAsDefaultInstance();
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_fileformat_2eproto);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_fileformat_2eproto {
StaticDescriptorInitializer_fileformat_2eproto() {
protobuf_AddDesc_fileformat_2eproto();
}
} static_descriptor_initializer_fileformat_2eproto_;
// ===================================================================
const ::std::string Blob::_default_raw_;
const ::std::string Blob::_default_zlib_data_;
const ::std::string Blob::_default_lzma_data_;
const ::std::string Blob::_default_obsolete_bzip2_data_;
#ifndef _MSC_VER
const int Blob::kRawFieldNumber;
const int Blob::kRawSizeFieldNumber;
const int Blob::kZlibDataFieldNumber;
const int Blob::kLzmaDataFieldNumber;
const int Blob::kOBSOLETEBzip2DataFieldNumber;
#endif // !_MSC_VER
Blob::Blob()
: ::google::protobuf::Message() {
SharedCtor();
}
void Blob::InitAsDefaultInstance() {
}
Blob::Blob(const Blob& from)
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
void Blob::SharedCtor() {
_cached_size_ = 0;
raw_ = const_cast< ::std::string*>(&_default_raw_);
raw_size_ = 0;
zlib_data_ = const_cast< ::std::string*>(&_default_zlib_data_);
lzma_data_ = const_cast< ::std::string*>(&_default_lzma_data_);
obsolete_bzip2_data_ = const_cast< ::std::string*>(&_default_obsolete_bzip2_data_);
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
Blob::~Blob() {
SharedDtor();
}
void Blob::SharedDtor() {
if (raw_ != &_default_raw_) {
delete raw_;
}
if (zlib_data_ != &_default_zlib_data_) {
delete zlib_data_;
}
if (lzma_data_ != &_default_lzma_data_) {
delete lzma_data_;
}
if (obsolete_bzip2_data_ != &_default_obsolete_bzip2_data_) {
delete obsolete_bzip2_data_;
}
if (this != default_instance_) {
}
}
void Blob::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Blob::descriptor() {
protobuf_AssignDescriptorsOnce();
return Blob_descriptor_;
}
const Blob& Blob::default_instance() {
if (default_instance_ == NULL) protobuf_AddDesc_fileformat_2eproto(); return *default_instance_;
}
Blob* Blob::default_instance_ = NULL;
Blob* Blob::New() const {
return new Blob;
}
void Blob::Clear() {
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (_has_bit(0)) {
if (raw_ != &_default_raw_) {
raw_->clear();
}
}
raw_size_ = 0;
if (_has_bit(2)) {
if (zlib_data_ != &_default_zlib_data_) {
zlib_data_->clear();
}
}
if (_has_bit(3)) {
if (lzma_data_ != &_default_lzma_data_) {
lzma_data_->clear();
}
}
if (_has_bit(4)) {
if (obsolete_bzip2_data_ != &_default_obsolete_bzip2_data_) {
obsolete_bzip2_data_->clear();
}
}
}
::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->Clear();
}
bool Blob::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
::google::protobuf::uint32 tag;
while ((tag = input->ReadTag()) != 0) {
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional bytes raw = 1;
case 1: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_raw()));
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(16)) goto parse_raw_size;
break;
}
// optional int32 raw_size = 2;
case 2: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
parse_raw_size:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &raw_size_)));
_set_bit(1);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(26)) goto parse_zlib_data;
break;
}
// optional bytes zlib_data = 3;
case 3: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_zlib_data:
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_zlib_data()));
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(34)) goto parse_lzma_data;
break;
}
// optional bytes lzma_data = 4;
case 4: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_lzma_data:
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_lzma_data()));
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(42)) goto parse_OBSOLETE_bzip2_data;
break;
}
// optional bytes OBSOLETE_bzip2_data = 5 [deprecated = true];
case 5: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_OBSOLETE_bzip2_data:
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_obsolete_bzip2_data()));
} else {
goto handle_uninterpreted;
}
if (input->ExpectAtEnd()) return true;
break;
}
default: {
handle_uninterpreted:
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
return true;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, mutable_unknown_fields()));
break;
}
}
}
return true;
#undef DO_
}
void Blob::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// optional bytes raw = 1;
if (_has_bit(0)) {
::google::protobuf::internal::WireFormatLite::WriteBytes(
1, this->raw(), output);
}
// optional int32 raw_size = 2;
if (_has_bit(1)) {
::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->raw_size(), output);
}
// optional bytes zlib_data = 3;
if (_has_bit(2)) {
::google::protobuf::internal::WireFormatLite::WriteBytes(
3, this->zlib_data(), output);
}
// optional bytes lzma_data = 4;
if (_has_bit(3)) {
::google::protobuf::internal::WireFormatLite::WriteBytes(
4, this->lzma_data(), output);
}
// optional bytes OBSOLETE_bzip2_data = 5 [deprecated = true];
if (_has_bit(4)) {
::google::protobuf::internal::WireFormatLite::WriteBytes(
5, this->obsolete_bzip2_data(), output);
}
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
}
::google::protobuf::uint8* Blob::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
// optional bytes raw = 1;
if (_has_bit(0)) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
1, this->raw(), target);
}
// optional int32 raw_size = 2;
if (_has_bit(1)) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->raw_size(), target);
}
// optional bytes zlib_data = 3;
if (_has_bit(2)) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
3, this->zlib_data(), target);
}
// optional bytes lzma_data = 4;
if (_has_bit(3)) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
4, this->lzma_data(), target);
}
// optional bytes OBSOLETE_bzip2_data = 5 [deprecated = true];
if (_has_bit(4)) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
5, this->obsolete_bzip2_data(), target);
}
if (!unknown_fields().empty()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
unknown_fields(), target);
}
return target;
}
int Blob::ByteSize() const {
int total_size = 0;
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
// optional bytes raw = 1;
if (has_raw()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
this->raw());
}
// optional int32 raw_size = 2;
if (has_raw_size()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
this->raw_size());
}
// optional bytes zlib_data = 3;
if (has_zlib_data()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
this->zlib_data());
}
// optional bytes lzma_data = 4;
if (has_lzma_data()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
this->lzma_data());
}
// optional bytes OBSOLETE_bzip2_data = 5 [deprecated = true];
if (has_obsolete_bzip2_data()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
this->obsolete_bzip2_data());
}
}
if (!unknown_fields().empty()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
void Blob::MergeFrom(const ::google::protobuf::Message& from) {
GOOGLE_CHECK_NE(&from, this);
const Blob* source =
::google::protobuf::internal::dynamic_cast_if_available<const Blob*>(
&from);
if (source == NULL) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
MergeFrom(*source);
}
}
void Blob::MergeFrom(const Blob& from) {
GOOGLE_CHECK_NE(&from, this);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (from._has_bit(0)) {
set_raw(from.raw());
}
if (from._has_bit(1)) {
set_raw_size(from.raw_size());
}
if (from._has_bit(2)) {
set_zlib_data(from.zlib_data());
}
if (from._has_bit(3)) {
set_lzma_data(from.lzma_data());
}
if (from._has_bit(4)) {
set_obsolete_bzip2_data(from.obsolete_bzip2_data());
}
}
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
void Blob::CopyFrom(const ::google::protobuf::Message& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
void Blob::CopyFrom(const Blob& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool Blob::IsInitialized() const {
return true;
}
void Blob::Swap(Blob* other) {
if (other != this) {
std::swap(raw_, other->raw_);
std::swap(raw_size_, other->raw_size_);
std::swap(zlib_data_, other->zlib_data_);
std::swap(lzma_data_, other->lzma_data_);
std::swap(obsolete_bzip2_data_, other->obsolete_bzip2_data_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.Swap(&other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_);
}
}
::google::protobuf::Metadata Blob::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = Blob_descriptor_;
metadata.reflection = Blob_reflection_;
return metadata;
}
// ===================================================================
const ::std::string BlobHeader::_default_type_;
const ::std::string BlobHeader::_default_indexdata_;
#ifndef _MSC_VER
const int BlobHeader::kTypeFieldNumber;
const int BlobHeader::kIndexdataFieldNumber;
const int BlobHeader::kDatasizeFieldNumber;
#endif // !_MSC_VER
BlobHeader::BlobHeader()
: ::google::protobuf::Message() {
SharedCtor();
}
void BlobHeader::InitAsDefaultInstance() {
}
BlobHeader::BlobHeader(const BlobHeader& from)
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
void BlobHeader::SharedCtor() {
_cached_size_ = 0;
type_ = const_cast< ::std::string*>(&_default_type_);
indexdata_ = const_cast< ::std::string*>(&_default_indexdata_);
datasize_ = 0;
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
BlobHeader::~BlobHeader() {
SharedDtor();
}
void BlobHeader::SharedDtor() {
if (type_ != &_default_type_) {
delete type_;
}
if (indexdata_ != &_default_indexdata_) {
delete indexdata_;
}
if (this != default_instance_) {
}
}
void BlobHeader::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* BlobHeader::descriptor() {
protobuf_AssignDescriptorsOnce();
return BlobHeader_descriptor_;
}
const BlobHeader& BlobHeader::default_instance() {
if (default_instance_ == NULL) protobuf_AddDesc_fileformat_2eproto(); return *default_instance_;
}
BlobHeader* BlobHeader::default_instance_ = NULL;
BlobHeader* BlobHeader::New() const {
return new BlobHeader;
}
void BlobHeader::Clear() {
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (_has_bit(0)) {
if (type_ != &_default_type_) {
type_->clear();
}
}
if (_has_bit(1)) {
if (indexdata_ != &_default_indexdata_) {
indexdata_->clear();
}
}
datasize_ = 0;
}
::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->Clear();
}
bool BlobHeader::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
::google::protobuf::uint32 tag;
while ((tag = input->ReadTag()) != 0) {
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// required string type = 1;
case 1: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_type()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->type().data(), this->type().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(18)) goto parse_indexdata;
break;
}
// optional bytes indexdata = 2;
case 2: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_indexdata:
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_indexdata()));
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(24)) goto parse_datasize;
break;
}
// required int32 datasize = 3;
case 3: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
parse_datasize:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &datasize_)));
_set_bit(2);
} else {
goto handle_uninterpreted;
}
if (input->ExpectAtEnd()) return true;
break;
}
default: {
handle_uninterpreted:
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
return true;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, mutable_unknown_fields()));
break;
}
}
}
return true;
#undef DO_
}
void BlobHeader::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// required string type = 1;
if (_has_bit(0)) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->type().data(), this->type().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
1, this->type(), output);
}
// optional bytes indexdata = 2;
if (_has_bit(1)) {
::google::protobuf::internal::WireFormatLite::WriteBytes(
2, this->indexdata(), output);
}
// required int32 datasize = 3;
if (_has_bit(2)) {
::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->datasize(), output);
}
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
}
::google::protobuf::uint8* BlobHeader::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
// required string type = 1;
if (_has_bit(0)) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->type().data(), this->type().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
1, this->type(), target);
}
// optional bytes indexdata = 2;
if (_has_bit(1)) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
2, this->indexdata(), target);
}
// required int32 datasize = 3;
if (_has_bit(2)) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->datasize(), target);
}
if (!unknown_fields().empty()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
unknown_fields(), target);
}
return target;
}
int BlobHeader::ByteSize() const {
int total_size = 0;
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
// required string type = 1;
if (has_type()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->type());
}
// optional bytes indexdata = 2;
if (has_indexdata()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
this->indexdata());
}
// required int32 datasize = 3;
if (has_datasize()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
this->datasize());
}
}
if (!unknown_fields().empty()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
void BlobHeader::MergeFrom(const ::google::protobuf::Message& from) {
GOOGLE_CHECK_NE(&from, this);
const BlobHeader* source =
::google::protobuf::internal::dynamic_cast_if_available<const BlobHeader*>(
&from);
if (source == NULL) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
MergeFrom(*source);
}
}
void BlobHeader::MergeFrom(const BlobHeader& from) {
GOOGLE_CHECK_NE(&from, this);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (from._has_bit(0)) {
set_type(from.type());
}
if (from._has_bit(1)) {
set_indexdata(from.indexdata());
}
if (from._has_bit(2)) {
set_datasize(from.datasize());
}
}
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
void BlobHeader::CopyFrom(const ::google::protobuf::Message& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
void BlobHeader::CopyFrom(const BlobHeader& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool BlobHeader::IsInitialized() const {
if ((_has_bits_[0] & 0x00000005) != 0x00000005) return false;
return true;
}
void BlobHeader::Swap(BlobHeader* other) {
if (other != this) {
std::swap(type_, other->type_);
std::swap(indexdata_, other->indexdata_);
std::swap(datasize_, other->datasize_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.Swap(&other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_);
}
}
::google::protobuf::Metadata BlobHeader::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = BlobHeader_descriptor_;
metadata.reflection = BlobHeader_reflection_;
return metadata;
}
// @@protoc_insertion_point(namespace_scope)
} // namespace OSMPBF
// @@protoc_insertion_point(global_scope)

View File

@ -0,0 +1,599 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: fileformat.proto
#ifndef PROTOBUF_fileformat_2eproto__INCLUDED
#define PROTOBUF_fileformat_2eproto__INCLUDED
#include <string>
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 2003000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 2003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
// @@protoc_insertion_point(includes)
namespace OSMPBF {
// Internal implementation detail -- do not call these.
void protobuf_AddDesc_fileformat_2eproto();
void protobuf_AssignDesc_fileformat_2eproto();
void protobuf_ShutdownFile_fileformat_2eproto();
class Blob;
class BlobHeader;
// ===================================================================
class Blob : public ::google::protobuf::Message {
public:
Blob();
virtual ~Blob();
Blob(const Blob& from);
inline Blob& operator=(const Blob& from) {
CopyFrom(from);
return *this;
}
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _unknown_fields_;
}
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const ::google::protobuf::Descriptor* descriptor();
static const Blob& default_instance();
void Swap(Blob* other);
// implements Message ----------------------------------------------
Blob* New() const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const Blob& from);
void MergeFrom(const Blob& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional bytes raw = 1;
inline bool has_raw() const;
inline void clear_raw();
static const int kRawFieldNumber = 1;
inline const ::std::string& raw() const;
inline void set_raw(const ::std::string& value);
inline void set_raw(const char* value);
inline void set_raw(const void* value, size_t size);
inline ::std::string* mutable_raw();
// optional int32 raw_size = 2;
inline bool has_raw_size() const;
inline void clear_raw_size();
static const int kRawSizeFieldNumber = 2;
inline ::google::protobuf::int32 raw_size() const;
inline void set_raw_size(::google::protobuf::int32 value);
// optional bytes zlib_data = 3;
inline bool has_zlib_data() const;
inline void clear_zlib_data();
static const int kZlibDataFieldNumber = 3;
inline const ::std::string& zlib_data() const;
inline void set_zlib_data(const ::std::string& value);
inline void set_zlib_data(const char* value);
inline void set_zlib_data(const void* value, size_t size);
inline ::std::string* mutable_zlib_data();
// optional bytes lzma_data = 4;
inline bool has_lzma_data() const;
inline void clear_lzma_data();
static const int kLzmaDataFieldNumber = 4;
inline const ::std::string& lzma_data() const;
inline void set_lzma_data(const ::std::string& value);
inline void set_lzma_data(const char* value);
inline void set_lzma_data(const void* value, size_t size);
inline ::std::string* mutable_lzma_data();
// optional bytes OBSOLETE_bzip2_data = 5 [deprecated = true];
inline bool has_obsolete_bzip2_data() const PROTOBUF_DEPRECATED;
inline void clear_obsolete_bzip2_data() PROTOBUF_DEPRECATED;
static const int kOBSOLETEBzip2DataFieldNumber = 5;
inline const ::std::string& obsolete_bzip2_data() const PROTOBUF_DEPRECATED;
inline void set_obsolete_bzip2_data(const ::std::string& value) PROTOBUF_DEPRECATED;
inline void set_obsolete_bzip2_data(const char* value) PROTOBUF_DEPRECATED;
inline void set_obsolete_bzip2_data(const void* value, size_t size) PROTOBUF_DEPRECATED;
inline ::std::string* mutable_obsolete_bzip2_data() PROTOBUF_DEPRECATED;
// @@protoc_insertion_point(class_scope:OSMPBF.Blob)
private:
::google::protobuf::UnknownFieldSet _unknown_fields_;
mutable int _cached_size_;
::std::string* raw_;
static const ::std::string _default_raw_;
::google::protobuf::int32 raw_size_;
::std::string* zlib_data_;
static const ::std::string _default_zlib_data_;
::std::string* lzma_data_;
static const ::std::string _default_lzma_data_;
::std::string* obsolete_bzip2_data_;
static const ::std::string _default_obsolete_bzip2_data_;
friend void protobuf_AddDesc_fileformat_2eproto();
friend void protobuf_AssignDesc_fileformat_2eproto();
friend void protobuf_ShutdownFile_fileformat_2eproto();
::google::protobuf::uint32 _has_bits_[(5 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
inline bool _has_bit(int index) const {
return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
}
inline void _set_bit(int index) {
_has_bits_[index / 32] |= (1u << (index % 32));
}
inline void _clear_bit(int index) {
_has_bits_[index / 32] &= ~(1u << (index % 32));
}
void InitAsDefaultInstance();
static Blob* default_instance_;
};
// -------------------------------------------------------------------
class BlobHeader : public ::google::protobuf::Message {
public:
BlobHeader();
virtual ~BlobHeader();
BlobHeader(const BlobHeader& from);
inline BlobHeader& operator=(const BlobHeader& from) {
CopyFrom(from);
return *this;
}
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _unknown_fields_;
}
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const ::google::protobuf::Descriptor* descriptor();
static const BlobHeader& default_instance();
void Swap(BlobHeader* other);
// implements Message ----------------------------------------------
BlobHeader* New() const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const BlobHeader& from);
void MergeFrom(const BlobHeader& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required string type = 1;
inline bool has_type() const;
inline void clear_type();
static const int kTypeFieldNumber = 1;
inline const ::std::string& type() const;
inline void set_type(const ::std::string& value);
inline void set_type(const char* value);
inline void set_type(const char* value, size_t size);
inline ::std::string* mutable_type();
// optional bytes indexdata = 2;
inline bool has_indexdata() const;
inline void clear_indexdata();
static const int kIndexdataFieldNumber = 2;
inline const ::std::string& indexdata() const;
inline void set_indexdata(const ::std::string& value);
inline void set_indexdata(const char* value);
inline void set_indexdata(const void* value, size_t size);
inline ::std::string* mutable_indexdata();
// required int32 datasize = 3;
inline bool has_datasize() const;
inline void clear_datasize();
static const int kDatasizeFieldNumber = 3;
inline ::google::protobuf::int32 datasize() const;
inline void set_datasize(::google::protobuf::int32 value);
// @@protoc_insertion_point(class_scope:OSMPBF.BlobHeader)
private:
::google::protobuf::UnknownFieldSet _unknown_fields_;
mutable int _cached_size_;
::std::string* type_;
static const ::std::string _default_type_;
::std::string* indexdata_;
static const ::std::string _default_indexdata_;
::google::protobuf::int32 datasize_;
friend void protobuf_AddDesc_fileformat_2eproto();
friend void protobuf_AssignDesc_fileformat_2eproto();
friend void protobuf_ShutdownFile_fileformat_2eproto();
::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
inline bool _has_bit(int index) const {
return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
}
inline void _set_bit(int index) {
_has_bits_[index / 32] |= (1u << (index % 32));
}
inline void _clear_bit(int index) {
_has_bits_[index / 32] &= ~(1u << (index % 32));
}
void InitAsDefaultInstance();
static BlobHeader* default_instance_;
};
// ===================================================================
// ===================================================================
// Blob
// optional bytes raw = 1;
inline bool Blob::has_raw() const {
return _has_bit(0);
}
inline void Blob::clear_raw() {
if (raw_ != &_default_raw_) {
raw_->clear();
}
_clear_bit(0);
}
inline const ::std::string& Blob::raw() const {
return *raw_;
}
inline void Blob::set_raw(const ::std::string& value) {
_set_bit(0);
if (raw_ == &_default_raw_) {
raw_ = new ::std::string;
}
raw_->assign(value);
}
inline void Blob::set_raw(const char* value) {
_set_bit(0);
if (raw_ == &_default_raw_) {
raw_ = new ::std::string;
}
raw_->assign(value);
}
inline void Blob::set_raw(const void* value, size_t size) {
_set_bit(0);
if (raw_ == &_default_raw_) {
raw_ = new ::std::string;
}
raw_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* Blob::mutable_raw() {
_set_bit(0);
if (raw_ == &_default_raw_) {
raw_ = new ::std::string;
}
return raw_;
}
// optional int32 raw_size = 2;
inline bool Blob::has_raw_size() const {
return _has_bit(1);
}
inline void Blob::clear_raw_size() {
raw_size_ = 0;
_clear_bit(1);
}
inline ::google::protobuf::int32 Blob::raw_size() const {
return raw_size_;
}
inline void Blob::set_raw_size(::google::protobuf::int32 value) {
_set_bit(1);
raw_size_ = value;
}
// optional bytes zlib_data = 3;
inline bool Blob::has_zlib_data() const {
return _has_bit(2);
}
inline void Blob::clear_zlib_data() {
if (zlib_data_ != &_default_zlib_data_) {
zlib_data_->clear();
}
_clear_bit(2);
}
inline const ::std::string& Blob::zlib_data() const {
return *zlib_data_;
}
inline void Blob::set_zlib_data(const ::std::string& value) {
_set_bit(2);
if (zlib_data_ == &_default_zlib_data_) {
zlib_data_ = new ::std::string;
}
zlib_data_->assign(value);
}
inline void Blob::set_zlib_data(const char* value) {
_set_bit(2);
if (zlib_data_ == &_default_zlib_data_) {
zlib_data_ = new ::std::string;
}
zlib_data_->assign(value);
}
inline void Blob::set_zlib_data(const void* value, size_t size) {
_set_bit(2);
if (zlib_data_ == &_default_zlib_data_) {
zlib_data_ = new ::std::string;
}
zlib_data_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* Blob::mutable_zlib_data() {
_set_bit(2);
if (zlib_data_ == &_default_zlib_data_) {
zlib_data_ = new ::std::string;
}
return zlib_data_;
}
// optional bytes lzma_data = 4;
inline bool Blob::has_lzma_data() const {
return _has_bit(3);
}
inline void Blob::clear_lzma_data() {
if (lzma_data_ != &_default_lzma_data_) {
lzma_data_->clear();
}
_clear_bit(3);
}
inline const ::std::string& Blob::lzma_data() const {
return *lzma_data_;
}
inline void Blob::set_lzma_data(const ::std::string& value) {
_set_bit(3);
if (lzma_data_ == &_default_lzma_data_) {
lzma_data_ = new ::std::string;
}
lzma_data_->assign(value);
}
inline void Blob::set_lzma_data(const char* value) {
_set_bit(3);
if (lzma_data_ == &_default_lzma_data_) {
lzma_data_ = new ::std::string;
}
lzma_data_->assign(value);
}
inline void Blob::set_lzma_data(const void* value, size_t size) {
_set_bit(3);
if (lzma_data_ == &_default_lzma_data_) {
lzma_data_ = new ::std::string;
}
lzma_data_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* Blob::mutable_lzma_data() {
_set_bit(3);
if (lzma_data_ == &_default_lzma_data_) {
lzma_data_ = new ::std::string;
}
return lzma_data_;
}
// optional bytes OBSOLETE_bzip2_data = 5 [deprecated = true];
inline bool Blob::has_obsolete_bzip2_data() const {
return _has_bit(4);
}
inline void Blob::clear_obsolete_bzip2_data() {
if (obsolete_bzip2_data_ != &_default_obsolete_bzip2_data_) {
obsolete_bzip2_data_->clear();
}
_clear_bit(4);
}
inline const ::std::string& Blob::obsolete_bzip2_data() const {
return *obsolete_bzip2_data_;
}
inline void Blob::set_obsolete_bzip2_data(const ::std::string& value) {
_set_bit(4);
if (obsolete_bzip2_data_ == &_default_obsolete_bzip2_data_) {
obsolete_bzip2_data_ = new ::std::string;
}
obsolete_bzip2_data_->assign(value);
}
inline void Blob::set_obsolete_bzip2_data(const char* value) {
_set_bit(4);
if (obsolete_bzip2_data_ == &_default_obsolete_bzip2_data_) {
obsolete_bzip2_data_ = new ::std::string;
}
obsolete_bzip2_data_->assign(value);
}
inline void Blob::set_obsolete_bzip2_data(const void* value, size_t size) {
_set_bit(4);
if (obsolete_bzip2_data_ == &_default_obsolete_bzip2_data_) {
obsolete_bzip2_data_ = new ::std::string;
}
obsolete_bzip2_data_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* Blob::mutable_obsolete_bzip2_data() {
_set_bit(4);
if (obsolete_bzip2_data_ == &_default_obsolete_bzip2_data_) {
obsolete_bzip2_data_ = new ::std::string;
}
return obsolete_bzip2_data_;
}
// -------------------------------------------------------------------
// BlobHeader
// required string type = 1;
inline bool BlobHeader::has_type() const {
return _has_bit(0);
}
inline void BlobHeader::clear_type() {
if (type_ != &_default_type_) {
type_->clear();
}
_clear_bit(0);
}
inline const ::std::string& BlobHeader::type() const {
return *type_;
}
inline void BlobHeader::set_type(const ::std::string& value) {
_set_bit(0);
if (type_ == &_default_type_) {
type_ = new ::std::string;
}
type_->assign(value);
}
inline void BlobHeader::set_type(const char* value) {
_set_bit(0);
if (type_ == &_default_type_) {
type_ = new ::std::string;
}
type_->assign(value);
}
inline void BlobHeader::set_type(const char* value, size_t size) {
_set_bit(0);
if (type_ == &_default_type_) {
type_ = new ::std::string;
}
type_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* BlobHeader::mutable_type() {
_set_bit(0);
if (type_ == &_default_type_) {
type_ = new ::std::string;
}
return type_;
}
// optional bytes indexdata = 2;
inline bool BlobHeader::has_indexdata() const {
return _has_bit(1);
}
inline void BlobHeader::clear_indexdata() {
if (indexdata_ != &_default_indexdata_) {
indexdata_->clear();
}
_clear_bit(1);
}
inline const ::std::string& BlobHeader::indexdata() const {
return *indexdata_;
}
inline void BlobHeader::set_indexdata(const ::std::string& value) {
_set_bit(1);
if (indexdata_ == &_default_indexdata_) {
indexdata_ = new ::std::string;
}
indexdata_->assign(value);
}
inline void BlobHeader::set_indexdata(const char* value) {
_set_bit(1);
if (indexdata_ == &_default_indexdata_) {
indexdata_ = new ::std::string;
}
indexdata_->assign(value);
}
inline void BlobHeader::set_indexdata(const void* value, size_t size) {
_set_bit(1);
if (indexdata_ == &_default_indexdata_) {
indexdata_ = new ::std::string;
}
indexdata_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* BlobHeader::mutable_indexdata() {
_set_bit(1);
if (indexdata_ == &_default_indexdata_) {
indexdata_ = new ::std::string;
}
return indexdata_;
}
// required int32 datasize = 3;
inline bool BlobHeader::has_datasize() const {
return _has_bit(2);
}
inline void BlobHeader::clear_datasize() {
datasize_ = 0;
_clear_bit(2);
}
inline ::google::protobuf::int32 BlobHeader::datasize() const {
return datasize_;
}
inline void BlobHeader::set_datasize(::google::protobuf::int32 value) {
_set_bit(2);
datasize_ = value;
}
// @@protoc_insertion_point(namespace_scope)
} // namespace OSMPBF
#ifndef SWIG
namespace google {
namespace protobuf {
} // namespace google
} // namespace protobuf
#endif // SWIG
// @@protoc_insertion_point(global_scope)
#endif // PROTOBUF_fileformat_2eproto__INCLUDED

View File

@ -0,0 +1,53 @@
/** Copyright (c) 2010 Scott A. Crosby. <scott@sacrosby.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
option java_package = "crosby.binary";
package OSMPBF;
//protoc --java_out=../.. fileformat.proto
//
// STORAGE LAYER: Storing primitives.
//
message Blob {
optional bytes raw = 1; // No compression
optional int32 raw_size = 2; // When compressed, the uncompressed size
// Possible compressed versions of the data.
optional bytes zlib_data = 3;
// PROPOSED feature for LZMA compressed data. SUPPORT IS NOT REQUIRED.
optional bytes lzma_data = 4;
// Formerly used for bzip2 compressed data. Depreciated in 2010.
optional bytes OBSOLETE_bzip2_data = 5 [deprecated=true]; // Don't reuse this tag number.
}
/* A file contains an sequence of fileblock headers, each prefixed by
their length in network byte order, followed by a data block
containing the actual data. types staring with a "_" are reserved.
*/
message BlobHeader {
required string type = 1;
optional bytes indexdata = 2;
required int32 datasize = 3;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,226 @@
/** Copyright (c) 2010 Scott A. Crosby. <scott@sacrosby.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
option java_package = "crosby.binary";
package OSMPBF;
/* OSM Binary file format
This is the master schema file of the OSM binary file format. This
file is designed to support limited random-access and future
extendability.
A binary OSM file consists of a sequence of FileBlocks (please see
fileformat.proto). The first fileblock contains a serialized instance
of HeaderBlock, followed by a sequence of PrimitiveBlock blocks that
contain the primitives.
Each primitiveblock is designed to be independently parsable. It
contains a string table storing all strings in that block (keys and
values in tags, roles in relations, usernames, etc.) as well as
metadata containing the precision of coordinates or timestamps in that
block.
A primitiveblock contains a sequence of primitive groups, each
containing primitives of the same type (nodes, densenodes, ways,
relations). Coordinates are stored in signed 64-bit integers. Lat&lon
are measured in units <granularity> nanodegrees. The default of
granularity of 100 nanodegrees corresponds to about 1cm on the ground,
and a full lat or lon fits into 32 bits.
Converting an integer to a lattitude or longitude uses the formula:
$OUT = IN * granularity / 10**9$. Many encoding schemes use delta
coding when representing nodes and relations.
*/
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/* Contains the file header. */
message HeaderBlock {
optional HeaderBBox bbox = 1;
/* Additional tags to aid in parsing this dataset */
repeated string required_features = 4;
repeated string optional_features = 5;
optional string writingprogram = 16;
optional string source = 17; // From the bbox field.
}
/** The bounding box field in the OSM header. BBOX, as used in the OSM
header. Units are always in nanodegrees -- they do not obey
granularity rules. */
message HeaderBBox {
required sint64 left = 1;
required sint64 right = 2;
required sint64 top = 3;
required sint64 bottom = 4;
}
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
message PrimitiveBlock {
required StringTable stringtable = 1;
repeated PrimitiveGroup primitivegroup = 2;
// Granularity, units of nanodegrees, used to store coordinates in this block
optional int32 granularity = 17 [default=100];
// Offset value between the output coordinates coordinates and the granularity grid in unites of nanodegrees.
optional int64 lat_offset = 19 [default=0];
optional int64 lon_offset = 20 [default=0];
// Granularity of dates, normally represented in units of milliseconds since the 1970 epoch.
optional int32 date_granularity = 18 [default=1000];
// Proposed extension:
//optional BBox bbox = XX;
}
// Group of OSMPrimitives. All primitives in a group must be the same type.
message PrimitiveGroup {
repeated Node nodes = 1;
optional DenseNodes dense = 2;
repeated Way ways = 3;
repeated Relation relations = 4;
repeated ChangeSet changesets = 5;
}
/** String table, contains the common strings in each block.
Note that we reserve index '0' as a delimiter, so the entry at that
index in the table is ALWAYS blank and unused.
*/
message StringTable {
repeated bytes s = 1;
}
/* Optional metadata that may be included into each primitive. */
message Info {
optional int32 version = 1 [default = -1];
optional int64 timestamp = 2;
optional int64 changeset = 3;
optional int32 uid = 4;
optional uint32 user_sid = 5; // String IDs
}
/** Optional metadata that may be included into each primitive. Special dense format used in DenseNodes. */
message DenseInfo {
repeated int32 version = 1 [packed = true];
repeated sint64 timestamp = 2 [packed = true]; // DELTA coded
repeated sint64 changeset = 3 [packed = true]; // DELTA coded
repeated sint32 uid = 4 [packed = true]; // DELTA coded
repeated sint32 user_sid = 5 [packed = true]; // String IDs for usernames. DELTA coded
}
// THIS IS STUB DESIGN FOR CHANGESETS. NOT USED RIGHT NOW.
// TODO: REMOVE THIS?
message ChangeSet {
required int64 id = 1;
//
// // Parallel arrays.
// repeated uint32 keys = 2 [packed = true]; // String IDs.
// repeated uint32 vals = 3 [packed = true]; // String IDs.
//
// optional Info info = 4;
// optional int64 created_at = 8;
// optional int64 closetime_delta = 9;
// optional bool open = 10;
// optional HeaderBBox bbox = 11;
}
message Node {
required sint64 id = 1;
// Parallel arrays.
repeated uint32 keys = 2 [packed = true]; // String IDs.
repeated uint32 vals = 3 [packed = true]; // String IDs.
optional Info info = 4; // May be omitted in omitmeta
required sint64 lat = 8;
required sint64 lon = 9;
}
/* Used to densly represent a sequence of nodes that do not have any tags.
We represent these nodes columnwise as five columns: ID's, lats, and
lons, all delta coded. When metadata is not omitted,
We encode keys & vals for all nodes as a single array of integers
containing key-stringid and val-stringid, using a stringid of 0 as a
delimiter between nodes.
( (<keyid> <valid>)* '0' )*
*/
message DenseNodes {
repeated sint64 id = 1 [packed = true]; // DELTA coded
//repeated Info info = 4;
optional DenseInfo denseinfo = 5;
repeated sint64 lat = 8 [packed = true]; // DELTA coded
repeated sint64 lon = 9 [packed = true]; // DELTA coded
// Special packing of keys and vals into one array. May be empty if all nodes in this block are tagless.
repeated int32 keys_vals = 10 [packed = true];
}
message Way {
required int64 id = 1;
// Parallel arrays.
repeated uint32 keys = 2 [packed = true];
repeated uint32 vals = 3 [packed = true];
optional Info info = 4;
repeated sint64 refs = 8 [packed = true]; // DELTA coded
}
message Relation {
enum MemberType {
NODE = 0;
WAY = 1;
RELATION = 2;
}
required int64 id = 1;
// Parallel arrays.
repeated uint32 keys = 2 [packed = true];
repeated uint32 vals = 3 [packed = true];
optional Info info = 4;
// Parallel arrays
repeated int32 roles_sid = 8 [packed = true];
repeated sint64 memids = 9 [packed = true]; // DELTA encoded
repeated MemberType types = 10 [packed = true];
}

View File

@ -15,7 +15,7 @@
class HelloWorldPlugin : public BasePlugin {
public:
HelloWorldPlugin() {}
~HelloWorldPlugin() { std::cout << GetDescriptor() << " destructor" << std::endl; }
~HelloWorldPlugin() { /*std::cout << GetDescriptor() << " destructor" << std::endl;*/ }
std::string GetDescriptor() { return std::string("hello"); }
void HandleRequest(std::vector<std::string> parameters, http::Reply& reply) {
std::cout << "[hello world]: runnning handler" << std::endl;
@ -23,7 +23,7 @@ public:
reply.content.append("<html><head><title>Hello World Demonstration Document</title></head><body><h1>Hello, World!</h1>");
std::stringstream content;
content << "Number of parameters: " << parameters.size() << "<br>";
for(int i = 0; i < parameters.size(); i++) {
for(unsigned i = 0; i < parameters.size(); i++) {
content << parameters[i] << "<br>";
}
reply.content.append(content.str());

View File

@ -31,7 +31,7 @@ else: #Mac OS X
else:
env.Append(CPPPATH = ['/usr/include', '/usr/include/include', '/usr/include/libxml2/'])
if GetOption('buildconfiguration') == 'debug':
env.Append(CCFLAGS = ' -g3')
env.Append(CCFLAGS = ' -Wall -g3')
else:
env.Append(CCFLAGS = ' -O3 -DNDEBUG')
#print "Compiling with: ", env['CXX']
@ -86,13 +86,16 @@ if not conf.CheckLibWithHeader('stxxl', 'stxxl.h', 'CXX'):
env.Append(CCFLAGS = ' -fopenmp')
env.Append(LINKFLAGS = ' -fopenmp')
env.StaticObject("DataStructures/pbf-proto/fileformat.pb.cc")
env.StaticObject("DataStructures/pbf-proto/osmformat.pb.cc")
env.Program("extractNetwork.cpp")
env.Program("extractLargeNetwork.cpp")
env.Program("createHierarchy.cpp")
if os.path.exists("many-to-many.cpp"):
env.Program("many-to-many.cpp")
env.Append(CCFLAGS = ' -lboost_regex -lboost_iostreams -lboost_system -lbz2')
env.Append(LINKFLAGS = ' -lboost_regex -lboost_iostreams -lboost_system -lbz2 -lboost_program_options')
env.Append(CCFLAGS = ' -lboost_regex -lboost_iostreams -lboost_system -lbz2 -lz -lprotobuf')
env.Append(LINKFLAGS = ' -lboost_regex -lboost_iostreams -lboost_system -lbz2 -lz -lboost_program_options')
env.Append(LINKFLAGS = ' -lprotobuf DataStructures/pbf-proto/fileformat.pb.o DataStructures/pbf-proto/osmformat.pb.o')
env.Program("routed.cpp")
env = conf.Finish()

View File

@ -39,16 +39,20 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "typedefs.h"
#include "DataStructures/InputReaderFactory.h"
#include "DataStructures/ExtractorStructs.h"
#include "DataStructures/PBFParser.h"
#include "DataStructures/XMLParser.h"
using namespace std;
typedef google::dense_hash_map<NodeID, _Node> NodeMap;
typedef stxxl::vector<NodeID> STXXLNodeIDVector;
typedef stxxl::vector<_Node> STXXLNodeVector;
typedef stxxl::vector<_Edge> STXXLEdgeVector;
typedef stxxl::vector<string> STXXLStringVector;
NodeMap * nodeMap = new NodeMap();
StringMap * stringMap = new StringMap();
unsigned globalRelationCounter = 0;
Settings settings;
vector<NodeID> SignalNodes;
STXXLNodeIDVector usedNodes;
STXXLNodeVector allNodes;
STXXLNodeVector confirmedNodes;
@ -56,154 +60,235 @@ STXXLEdgeVector allEdges;
STXXLEdgeVector confirmedEdges;
STXXLStringVector nameVector;
NodeMap * nodeMap = new NodeMap();
StringMap * stringMap = new StringMap();
bool nodeFunction(_Node n) {
allNodes.push_back(n);
return true;
}
bool relationFunction(_Relation r) {
globalRelationCounter++;
return true;
}
bool wayFunction(_Way w) {
std::string highway( w.keyVals.Find("highway") );
std::string name( w.keyVals.Find("name") );
std::string ref( w.keyVals.Find("ref"));
std::string oneway( w.keyVals.Find("oneway"));
std::string junction( w.keyVals.Find("junction") );
std::string route( w.keyVals.Find("route") );
std::string maxspeed( w.keyVals.Find("maxspeed") );
std::string access( w.keyVals.Find("access") );
std::string motorcar( w.keyVals.Find("motorcar") );
if ( name != "" ) {
w.name = name;
} else if ( ref != "" ) {
w.name = ref;
}
if ( oneway != "" ) {
if ( oneway == "no" || oneway == "false" || oneway == "0" ) {
w.direction = _Way::bidirectional;
} else {
if ( oneway == "yes" || oneway == "true" || oneway == "1" ) {
w.direction = _Way::oneway;
} else {
if (oneway == "-1" )
w.direction = _Way::opposite;
}
}
}
if ( junction == "roundabout" ) {
if ( w.direction == _Way::notSure ) {
w.direction = _Way::oneway;
}
w.useful = true;
if(w.type == -1)
w.type = 9;
}
if ( route == "ferry") {
for ( unsigned i = 0; i < settings.speedProfile.names.size(); i++ ) {
if ( route == settings.speedProfile.names[i] ) {
w.type = i;
w.maximumSpeed = settings.speedProfile.speed[i];
w.useful = true;
w.direction = _Way::bidirectional;
break;
}
}
}
if ( highway != "" ) {
for ( unsigned i = 0; i < settings.speedProfile.names.size(); i++ ) {
if ( highway == settings.speedProfile.names[i] ) {
w.maximumSpeed = settings.speedProfile.speed[i];
w.type = i;
w.useful = true;
break;
}
}
if ( highway == "motorway" ) {
if ( w.direction == _Way::notSure ) {
w.direction = _Way::oneway;
}
} else if ( highway == "motorway_link" ) {
if ( w.direction == _Way::notSure ) {
w.direction = _Way::oneway;
}
}
}
if ( maxspeed != "" ) {
double maxspeedNumber = atof( maxspeed.c_str() );
if(maxspeedNumber != 0) {
w.maximumSpeed = maxspeedNumber;
}
}
if ( access != "" ) {
if ( access == "private" || access == "no" || access == "agricultural" || access == "forestry" || access == "delivery") {
w.access = false;
}
if ( access == "yes" || access == "designated" || access == "official" || access == "permissive") {
w.access = true;
}
}
if ( motorcar == "yes" ) {
w.access = true;
} else if ( motorcar == "no" ) {
w.access = false;
}
if ( w.useful && w.access && w.path.size() ) {
// std::cout << "[debug] looking for name: " << w.name << std::endl;
StringMap::iterator strit = stringMap->find(w.name);
if(strit == stringMap->end())
{
w.nameID = nameVector.size();
nameVector.push_back(w.name);
stringMap->insert(std::make_pair(w.name, w.nameID) );
// if(w.name != "")
// cout << "[debug] found new name ID: " << w.nameID << " (" << w.name << ")" << endl;
} else {
w.nameID = strit->second;
// std::cout << "[debug] name with ID " << w.nameID << " already existing (" << w.name << ")" << endl;
}
for ( unsigned i = 0; i < w.path.size(); ++i ) {
// std::cout << "[debug] using node " << w.path[i] << std::endl;
usedNodes.push_back(w.path[i]);
}
if ( w.direction == _Way::opposite ){
std::reverse( w.path.begin(), w.path.end() );
}
vector< NodeID > & path = w.path;
assert(w.type > -1 || w.maximumSpeed != -1);
assert(path.size()>0);
if(w.maximumSpeed == -1)
w.maximumSpeed = settings.speedProfile.speed[w.type];
for(vector< NodeID >::size_type n = 0; n < path.size()-1; n++) {
_Edge e;
e.start = w.path[n];
e.target = w.path[n+1];
e.type = w.type;
e.direction = w.direction;
e.speed = w.maximumSpeed;
e.nameID = w.nameID;
allEdges.push_back(e);
}
}
return true;
}
int main (int argc, char *argv[]) {
if(argc <= 1) {
cerr << "usage: " << endl << argv[0] << " <file.osm>" << endl;
std::cerr << "usage: " << endl << argv[0] << " <file.osm>" << std::endl;
exit(-1);
}
cout << "extracting data from input file " << argv[1] << endl;
cout << "reading input file. This may take some time ..." << flush;
xmlTextReaderPtr inputReader = inputReaderFactory(argv[1]);
std::cout << "[extractor] extracting data from input file " << argv[1] << std::endl;
bool isPBF = false;
std::string outputFileName(argv[1]);
std::string::size_type pos = outputFileName.find(".osm.bz2");
if(pos==string::npos) {
pos = outputFileName.find(".osm.pbf");
if(pos!=string::npos) {
// std::cout << "[debug] found pbf file" << std::endl;
isPBF = true;
}
}
if(pos!=string::npos) {
outputFileName.replace(pos, 8, ".osrm");
} else {
pos=outputFileName.find(".osm");
if(pos!=string::npos) {
outputFileName.replace(pos, 5, ".osrm");
} else {
outputFileName.append(".osrm");
}
}
double time = get_timestamp();
settings.speedProfile.names.insert(settings.speedProfile.names.begin(), names, names+14);
settings.speedProfile.speed.insert(settings.speedProfile.speed.begin(), speeds, speeds+14);
double time = get_timestamp();
nodeMap->set_empty_key(UINT_MAX);
stringMap->set_empty_key(GetRandomString());
stringMap->insert(std::make_pair("", 0));
try {
while ( xmlTextReaderRead( inputReader ) == 1 ) {
const int type = xmlTextReaderNodeType( inputReader );
//1 is Element
if ( type != 1 )
continue;
xmlChar* currentName = xmlTextReaderName( inputReader );
if ( currentName == NULL )
continue;
if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) {
_Node node = _ReadXMLNode( inputReader );
allNodes.push_back(node);
if ( node.trafficSignal )
SignalNodes.push_back( node.id );
}
if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) {
string name;
_Way way = _ReadXMLWay( inputReader, settings, name );
if ( way.usefull && way.access && way.path.size() ) {
StringMap::iterator strit = stringMap->find(name);
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;
BaseParser<_Node, _Relation, _Way> * parser;
if(isPBF)
parser = new PBFParser(argv[1]);
else
parser = new XMLParser(argv[1]);
parser->RegisterCallbacks(&nodeFunction, &relationFunction, &wayFunction);
if(parser->Init()) {
parser->Parse();
} else {
way.nameID = strit->second;
// cout << "name with ID " << way.nameID << " already existing (" << name << ")" << endl;
}
for ( unsigned i = 0; i < way.path.size(); ++i ) {
usedNodes.push_back(way.path[i]);
std::cerr << "[error] parser not initialized!" << std::endl;
exit(-1);
}
if ( way.direction == _Way::opposite ){
std::reverse( way.path.begin(), way.path.end() );
}
vector< NodeID > & path = way.path;
assert(way.type > -1 || way.maximumSpeed != -1);
assert(path.size()>0);
try {
std::cout << "[info] raw no. of names: " << nameVector.size() << std::endl;
std::cout << "[info] raw no. of nodes: " << allNodes.size() << std::endl;
std::cout << "[info] no. of used nodes: " << usedNodes.size() << std::endl;
std::cout << "[info] raw no. of edges: " << allEdges.size() << std::endl;
std::cout << "[info] raw no. of relations: " << globalRelationCounter << std::endl;
if(way.maximumSpeed == -1)
way.maximumSpeed = settings.speedProfile.speed[way.type];
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;
e.nameID = way.nameID;
allEdges.push_back(e);
}
}
}
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
}
xmlFree( currentName );
}
cout << "raw no. of names: " << nameVector.size() << endl;
cout << "raw no. of nodes: " << allNodes.size() << endl;
cout << "raw no. of edges: " << allEdges.size() << endl;
cout << "ok, after " << get_timestamp() - time << "s" << endl;
std::cout << "[info] parsing throug input file took " << get_timestamp() - time << "seconds" << std::endl;
time = get_timestamp();
unsigned memory_to_use = 1024 * 1024 * 1024;
cout << "Sorting used nodes ..." << flush;
std::cout << "[extractor] Sorting used nodes ... " << std::flush;
stxxl::sort(usedNodes.begin(), usedNodes.end(), Cmp(), memory_to_use);
cout << "ok, after " << get_timestamp() - time << "s" << endl;
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
time = get_timestamp();
cout << "Erasing duplicate entries ..." << flush;
std::cout << "[extractor] Erasing duplicate entries ... " << std::flush;
stxxl::vector<NodeID>::iterator NewEnd = unique ( usedNodes.begin(),usedNodes.end() ) ;
usedNodes.resize ( NewEnd - usedNodes.begin() );
cout << "ok, after " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "Sorting all nodes ..." << flush;
std::cout << "[extractor] Sorting all nodes ... " << std::flush;
stxxl::sort(allNodes.begin(), allNodes.end(), CmpNodeByID(), memory_to_use);
cout << "ok, after " << get_timestamp() - time << "s" << endl;
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
time = get_timestamp();
string name(argv[1]);
int pos;
pos = name.find(".osm.bz2");
if(pos!=string::npos)
{
name.replace(pos, 8, ".osrm");
} else {
pos=name.find(".osm");
if(pos!=string::npos)
{
name.replace(pos, 5, ".osrm");
} else {
name.append(".osrm");
}
}
ofstream fout;
fout.open(name.c_str());
fout.open(outputFileName.c_str());
cout << "Confirming used nodes ..." << flush;
NodeID counter = 0;
NodeID notfound = 0;
cout << "[extractor] Confirming used nodes ... " << flush;
STXXLNodeVector::iterator nvit = allNodes.begin();
STXXLNodeIDVector::iterator niit = usedNodes.begin();
while(niit != usedNodes.end() && nvit != allNodes.end())
{
while(niit != usedNodes.end() && nvit != allNodes.end()) {
if(*niit < nvit->id){
niit++;
continue;
}
if(*niit > nvit->id)
{
if(*niit > nvit->id) {
nvit++;
continue;
}
if(*niit == nvit->id)
{
if(*niit == nvit->id) {
confirmedNodes.push_back(*nvit);
nodeMap->insert(std::make_pair(nvit->id, *nvit));
niit++;
@ -213,19 +298,17 @@ int main (int argc, char *argv[]) {
cout << "ok, after " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "Writing used nodes ..." << flush;
cout << "[extractor] Writing used nodes ... " << flush;
fout << confirmedNodes.size() << endl;
for(STXXLNodeVector::iterator ut = confirmedNodes.begin(); ut != confirmedNodes.end(); ut++)
{
for(STXXLNodeVector::iterator ut = confirmedNodes.begin(); ut != confirmedNodes.end(); ut++) {
fout << ut->id<< " " << ut->lon << " " << ut->lat << "\n";
}
cout << "ok, after " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "confirming used ways ..." << flush;
for(STXXLEdgeVector::iterator eit = allEdges.begin(); eit != allEdges.end(); eit++)
{
cout << "[extractor] confirming used ways ... " << flush;
for(STXXLEdgeVector::iterator eit = allEdges.begin(); eit != allEdges.end(); eit++) {
assert(eit->type > -1 || eit->speed != -1);
NodeMap::iterator startit = nodeMap->find(eit->start);
@ -245,19 +328,15 @@ int main (int argc, char *argv[]) {
cout << "ok, after " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "writing confirmed ways ..." << flush;
for(STXXLEdgeVector::iterator eit = confirmedEdges.begin(); eit != confirmedEdges.end(); eit++)
{
cout << "[extractor] writing confirmed ways ... " << flush;
for(STXXLEdgeVector::iterator eit = confirmedEdges.begin(); eit != confirmedEdges.end(); eit++) {
NodeMap::iterator startit = nodeMap->find(eit->start);
if(startit == nodeMap->end())
{
if(startit == nodeMap->end()) {
continue;
}
NodeMap::iterator targetit = nodeMap->find(eit->target);
if(targetit == nodeMap->end())
{
if(targetit == nodeMap->end()) {
continue;
}
double distance = ApproximateDistance(startit->second.lat, startit->second.lon, targetit->second.lat, targetit->second.lon);
@ -269,8 +348,7 @@ int main (int argc, char *argv[]) {
int ferryIndex = settings.indexInAccessListOf("ferry");
assert(ferryIndex != -1);
switch(eit->direction)
{
switch(eit->direction) {
case _Way::notSure:
fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << " " << eit->type << " " << eit->nameID << "\n";
break;
@ -284,59 +362,60 @@ int main (int argc, char *argv[]) {
fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << " " << eit->type << " " << eit->nameID << "\n";
break;
default:
std::cerr << "[error] edge with no direction: " << eit->direction << std::endl;
assert(false);
break;
}
}
fout.close();
name.append(".names");
cout << "ok, after " << get_timestamp() - time << "s" << endl;
outputFileName.append(".names");
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
// std::cout << "[debug] written edges: " << testCounter << std::endl;
time = get_timestamp();
cout << "writing street name index ..." << flush;
std::cout << "[extractor] writing street name index ... " << std::flush;
vector<unsigned> * nameIndex = new vector<unsigned>(nameVector.size()+1, 0);
std::vector<unsigned> * nameIndex = new std::vector<unsigned>(nameVector.size()+1, 0);
unsigned currentNameIndex = 0;
for(int i = 0; i < nameVector.size(); i++) {
for(unsigned i = 0; i < nameVector.size(); i++) {
nameIndex->at(i) = currentNameIndex;
currentNameIndex += nameVector[i].length();
}
nameIndex->at(nameVector.size()) = currentNameIndex;
ofstream nameOutFile(name.c_str(), ios::binary);
ofstream nameOutFile(outputFileName.c_str(), ios::binary);
unsigned sizeOfNameIndex = nameIndex->size();
nameOutFile.write((char *)&(sizeOfNameIndex), sizeof(unsigned));
for(int i = 0; i < nameIndex->size(); i++) {
for(unsigned i = 0; i < nameIndex->size(); i++) {
nameOutFile.write((char *)&(nameIndex->at(i)), sizeof(unsigned));
}
for(int i = 0; i < nameVector.size(); i++){
for(unsigned i = 0; i < nameVector.size(); i++){
nameOutFile << nameVector[i];
}
nameOutFile.close();
delete nameIndex;
cout << "ok, after " << get_timestamp() - time << "s" << endl;
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
} catch ( const std::exception& e ) {
cerr << "Caught Execption:" << e.what() << endl;
std::cerr << "Caught Execption:" << e.what() << std::endl;
return false;
}
cout << endl << "Statistics:" << endl;
cout << "-----------" << endl;
cout << "Usable Nodes: " << confirmedNodes.size() << endl;
cout << "Usable Ways : " << confirmedEdges.size() << endl;
std::cout << "[info] Statistics:" << std::endl;
std::cout << "[info] -----------" << std::endl;
std::cout << "[info] Usable Nodes: " << confirmedNodes.size() << std::endl;
std::cout << "[info] Usable Edges: " << confirmedEdges.size() << std::endl;
SignalNodes.clear();
usedNodes.clear();
allNodes.clear();
confirmedNodes.clear();
allEdges.clear();
confirmedEdges.clear();
nameVector.clear();
xmlFreeTextReader(inputReader);
delete nodeMap;
delete stringMap;
cout << "finished." << endl;
delete parser;
cout << "[extractor] finished." << endl;
return 0;
}