/*
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
.
*/
#include "parse_way.h"
#include
#include
#include
#include
#include
#include
#include
#include
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(lonrhs.lon)
return false;
if(lat & 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;
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;
}