source: subversion/applications/utils/export/segmentise/segmentise.cpp @ 28183

Last change on this file since 28183 was 24400, checked in by nick, 9 years ago

Added segmentise utility: break down OSM ways into segments at joins

File size: 1011 bytes
Line 
1#include "Parser.h"
2#include <fstream>
3#include <iostream>
4
5int main (int argc, char *argv[])
6{
7        if(argc<2)
8        {
9                cerr<<"Usage: "<<argv[0]<<" infile"<<endl;
10                exit(1);
11        }
12
13        std::ifstream infile(argv[1]);
14        if(!infile.good())
15        {
16                cerr<<"Error reading input file"<<endl;
17                exit(1);
18        }
19
20        XML_Parser p = XML_ParserCreate(NULL);
21        if (!p)
22        {
23                cerr<< "Error creating parser"<<endl;
24                exit(1);
25        }
26       
27        XML_SetElementHandler(p, Parser::startElement, Parser::endElement);
28
29        // First parse to find the junction nodes
30        if(!Parser::parse(p,infile))
31        {
32                cerr<<"Error in first pass:" << Parser::getError() <<endl;
33                exit(1);
34        }
35
36        // Rewind the file
37        // www.cs.hmc.edu/~geoff/classes/hmc.cs070.200109/notes/io.html
38        infile.clear();
39        infile.seekg(0,std::ios::beg);
40
41        // Second parse to actually split the ways
42        XML_ParserReset(p,NULL);
43        XML_SetElementHandler(p, Parser::startElement, Parser::endElement);
44        if(!Parser::parse(p,infile))
45        {
46                cerr<<"Error in second pass:" << Parser::getError() <<endl;
47                exit(1);
48        }
49
50
51        return 0;
52}
Note: See TracBrowser for help on using the repository browser.