Skip to content

Instantly share code, notes, and snippets.

@Zia-
Created May 5, 2016 13:18
Show Gist options
  • Save Zia-/2557af6cf9f103c601aef2801ce652f0 to your computer and use it in GitHub Desktop.
Save Zia-/2557af6cf9f103c601aef2801ce652f0 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
<bounds minlat="54.0889580" minlon="12.2487570" maxlat="54.0913900" maxlon="12.2524800"/>
<node id="298884269" lat="54.0901746" lon="12.2482632" user="SvenHRO" uid="46882" visible="true" version="1" changeset="676636" timestamp="2008-09-21T21:37:45Z"/>
<node id="261728686" lat="54.0906309" lon="12.2441924" user="PikoWinter" uid="36744" visible="true" version="1" changeset="323878" timestamp="2008-05-03T13:39:23Z"/>
<node id="1831881213" version="1" changeset="12370172" lat="54.0900666" lon="12.2539381" user="lafkor" uid="75625" visible="true" timestamp="2012-07-20T09:43:19Z">
<tag k="name" v="Neu Broderstorf"/>
<tag k="traffic_sign" v="city_limit"/>
</node>
<node id="298884272" lat="54.0901447" lon="12.2516513" user="SvenHRO" uid="46882" visible="true" version="1" changeset="676636" timestamp="2008-09-21T21:37:45Z"/>
<way id="26659127" user="Masch" uid="55988" visible="true" version="5" changeset="4142606" timestamp="2010-03-16T11:47:08Z">
<nd ref="292403538"/>
<nd ref="298884289"/>
<nd ref="261728686"/>
<tag k="highway" v="unclassified"/>
<tag k="name" v="Pastower Straße"/>
</way>
<relation id="56688" user="kmvar" uid="56190" visible="true" version="28" changeset="6947637" timestamp="2011-01-12T14:23:49Z">
<member type="node" ref="294942404" role=""/>
<member type="node" ref="364933006" role=""/>
<member type="way" ref="4579143" role=""/>
<member type="node" ref="249673494" role=""/>
<tag k="name" v="Küstenbus Linie 123"/>
<tag k="network" v="VVW"/>
<tag k="operator" v="Regionalverkehr Küste"/>
<tag k="ref" v="123"/>
<tag k="route" v="bus"/>
<tag k="type" v="route"/>
</relation>
</osm>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
// #include <stdio.h>
using namespace std;
class Node{
public:
int id;
double lat;
double lon;
void setId(int id);
void setLat(double lat);
void setLon(double lon);
int getId();
double getLat();
double getLon();
};
class Way{
public:
int id;
Node node;
void setId(int id);
void setNode(Node node);
int getId();
Node getNode();
};
int main(){
std::string osmfile_address = "/Users/zia/Documents/Test/Rubbish/osmforcpp_2line.osm";
// // std::cout<< "hi" << std::endl;
// std::ifstream file(osmfile_address);
// std::string str;
// while (std::getline(file, str)){
// std::cout<< str << std::endl;
// }
std::vector<int> wayvector;
// std::vector<wayonevector> wayvector;
std::string oneline;
std::ifstream osmfile(osmfile_address);
while(getline(osmfile, oneline)){
std::string tmpline;
for (int i=0; i<oneline.length(); ++i){
// std::cout << oneline[i] << std::endl;
if (oneline[i] == ' ' && tmpline.size() == 0){
// to escape blank line starts
} else {
tmpline += oneline[i];
}
}
bool found;
if (tmpline.find("<way") != std::string::npos){
found = true;
} else if (tmpline.find("</way>") != std::string::npos){
found = false;
}
if (found){
for (int i=0; i<tmpline.length(); ++i){
// Ways Id
std::string idway;
idway += tmpline[i];
idway += tmpline[i+1];
idway += tmpline[i+2];
idway += tmpline[i+3];
idway += tmpline[i+4];
if (idway == " id=\""){
std::string idw;
int incre = 1;
while ((tmpline[i+4+incre]) != '\"'){
idw += tmpline[i+4+incre];
incre++;
}
std::cout << idw << std::endl;
wayvector.push_back(std::stoi(idw));
}
// Ways nodes Id
std::string refnode;
refnode += tmpline[i];
refnode += tmpline[i+1];
refnode += tmpline[i+2];
refnode += tmpline[i+3];
refnode += tmpline[i+4];
refnode += tmpline[i+5];
if (refnode == " ref=\""){
std::string refn;
int incre = 1;
while ((tmpline[i+5+incre]) != '\"'){
refn += tmpline[i+5+incre];
incre++;
}
std::cout << refn << std::endl;
wayvector.push_back(std::stoi(refn));
// std::string oneline_node;
// while(getline(osmfile, oneline_node)){
// std::string tmpline_node;
// for (int i=0; i<oneline_node.length(); ++i){
// if (oneline_node[i] == ' ' && tmpline_node.size() == 0){
// } else {
// tmpline_node += oneline_node[i];
// }
// }
// std::cout << tmpline_node << std::endl;
// if (tmpline_node.find("<node") != std::string::npos){
// for (int i=0; i<tmpline_node.length(); ++i){
// std::string idnode;
// idnode += tmpline[i];
// idnode += tmpline[i+1];
// idnode += tmpline[i+2];
// idnode += tmpline[i+3];
// idnode += tmpline[i+4];
// std::string idn;
// if (idnode == " id=\""){
// int incre = 1;
// while ((tmpline[i+4+incre]) != '\"'){
// idn += tmpline[i+4+incre];
// incre++;
// }
// }
// if (idn == refn){
// std::cout << "found mnode" << std::endl;
// }
// }
// }
//
//
// }
}
}
}
// if (tmpline.find("<node") != std::string::npos){
// for (int i=0; i<tmpline.length(); ++i){
// // std::cout << tmpline.length() << std::endl;
// std::string idnode;
// idnode += tmpline[i];
// idnode += tmpline[i+1];
// idnode += tmpline[i+2];
// idnode += tmpline[i+3];
// idnode += tmpline[i+4];
// // std::cout << idnode << std::endl;
// std::string idn;
// if (idnode == " id=\""){
// // std::cout << "nodeid" << std::endl;
// int incre = 1;
// while ((tmpline[i+4+incre]) != '\"'){
// idn += tmpline[i+4+incre];
// incre++;
// }
// }
// // std::cout << idn << std::endl;
// }
// }
}
std::cout << wayvector.size() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment