Commit dcb49e8a authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

pbf analyzer

parent 9b1c9b76
......@@ -10,7 +10,7 @@ INCLUDE_OSMPBF=-I../../osmpbf -I../../osmpbf/osmpbf/include
.PHONY: clean
all: elevation_create_database elevation_query_database route_query_nodes_database route_query_lookup_database route route_create_databases_from_pbf lmdb_rewriter
all: elevation_create_database elevation_query_database route_query_nodes_database route_query_lookup_database route route_create_databases_from_pbf lmdb_rewriter analyze_pbf
lmdb_rewriter: lmdb_rewriter.o
$(CC) -static $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB)
......@@ -36,6 +36,9 @@ route: route.o route_db.o lookup.o functions.o nodes_db.o lookup_db.o conv_funct
route_create_databases_from_pbf: route_create_databases_from_pbf.o lookup_db.o nodes_db.o elevation.o parse_way.o conv_functions.o
$(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB) $(LDLIBS_OSMPBF)
analyze_pbf: analyze_pbf.o parse_way.o
$(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_OSMPBF)
lmdb_rewriter.o: lmdb_rewriter.cc conf.h
$(CC) $(CXXFLAGS) -c $< -o $@
......@@ -84,5 +87,8 @@ route.o: route.cc
route_create_databases_from_pbf.o: route_create_databases_from_pbf.cc
$(CC) $(CXXFLAGS) $(INCLUDE_OSMPBF) -c $< -o $@
analyze_pbf.o: analyze_pbf.cc
$(CC) $(CXXFLAGS) $(INCLUDE_OSMPBF) -c $< -o $@
clean:
rm -f *.o
/*
This file is part of the osmpbf library.
Copyright(c) 2014 Daniel Bahrdt.
This library 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 library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see
<http://www.gnu.org/licenses/>.
*/
#include "parse_way.h"
#include <iostream>
#include <osmpbf/osmfile.h>
#include <osmpbf/inode.h>
#include <osmpbf/iway.h>
#include <osmpbf/irelation.h>
#include <osmpbf/filter.h>
#include <osmpbf/primitiveblockinputadaptor.h>
#include <set>
struct srtm_tile_t
{
int lon;
int lat;
srtm_tile_t(const int & lon_i, const int & lat_i) : lon(lon_i), lat(lat_i) {}
srtm_tile_t(const srtm_tile_t & orig) : lon(orig.lon), lat(orig.lat) {}
bool operator<(const srtm_tile_t & rhs) const
{
if(lon<rhs.lon)
return true;
if(lon>rhs.lon)
return false;
if(lat<rhs.lat)
return true;
return false;
}
bool operator==(const srtm_tile_t & rhs) const
{
return (lon == rhs.lon && lat == rhs.lat);
}
};
void parseBlock_ways(
osmpbf::PrimitiveBlockInputAdaptor & pbi,
uint64_t & count,
std::set<srtm_tile_t> & srtm)
{
if (pbi.waysSize())
{
for (osmpbf::IWayStream way = pbi.getWayStream(); !way.isNull(); way.next())
{
std::string tag_highway, tag_cycleway, tag_bicycle, tag_oneway, tag_junction;
for(uint32_t i = 0, s = way.tagsSize(); i < s; ++i)
{
if( way.key(i) == "highway" )
tag_highway = way.value(i);
if( way.key(i) == "cycleway" )
tag_cycleway = way.value(i);
if( way.key(i) == "bicycle" )
tag_bicycle = way.value(i);
if( way.key(i) == "oneway" )
tag_oneway = way.value(i);
if( way.key(i) == "junction" )
tag_junction = way.value(i);
}
bool we_use_it;
way_kind_t way_kind;
int oneway;
parse_way(
we_use_it,
way_kind,
oneway,
tag_highway,
tag_cycleway,
tag_bicycle,
tag_oneway,
tag_junction);
if(we_use_it)
{
for(osmpbf::IWay::RefIterator refIt(way.refBegin()), refEnd(way.refEnd()); refIt != refEnd; ++refIt)
{
count++;
}
}
}
}
if (pbi.nodesSize())
{
for (osmpbf::INodeStream node = pbi.getNodeStream(); !node.isNull(); node.next())
{
double lon = node.lond();
double lat = node.latd();
int lon1 = (int)((lon*1200-3)/1200 + 360)-360;
int lon2 = (int)((lon*1200+3)/1200 + 360)-360;
int lat1 = (int)((lat*1200-3)/1200 + 360)-360;
int lat2 = (int)((lat*1200+3)/1200 + 360)-360;
srtm.insert(srtm_tile_t(lon1,lat1));
srtm.insert(srtm_tile_t(lon1,lat2));
srtm.insert(srtm_tile_t(lon2,lat1));
srtm.insert(srtm_tile_t(lon2,lat2));
}
}
}
int main(int argc, char ** argv)
{
if (argc < 1)
{
fprintf(stderr,"Usage: %s pbf\n",argv[0]);
abort();
}
uint64_t count=0;
std::set<srtm_tile_t> srtm;
std::string inputFileName(argv[1]);
osmpbf::OSMFileIn inFile(inputFileName, false);
if (!inFile.open())
{
std::cout << "Failed to open " << inputFileName << std::endl;
return -1;
}
osmpbf::PrimitiveBlockInputAdaptor pbi;
while (inFile.parseNextBlock(pbi))
{
if (pbi.isNull())
continue;
parseBlock_ways(pbi, count, srtm);
}
for(auto srtm_it = srtm.begin();
srtm_it != srtm.end();
srtm_it++)
{
fprintf(stdout,"%i\t%i\n",srtm_it->lon,srtm_it->lat);
}
fprintf(stderr,"number of (way,node)s: %lu\n",count);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment