-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.cpp
54 lines (47 loc) · 1.72 KB
/
parser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "parser.h"
#include <math.h>
#include <fstream>
ParsedLine::ParsedLine(int id, int ix, double la, double lo) : lineStringId(id), pointIdx(ix), lat(la), lon(lo) { }
Parser::Parser(vector<string*>* rowNames, vector<string*>* fileNames) : parsedData(new vector<ParsedLine*>()),
rows(rowNames), files(fileNames),
mercatorLocalProjWithScale(new vector<pair<double, double>*>()) {}
vector<ParsedLine*> Parser::parse ()
{
for (vector<string*>::iterator it = files->begin(); it != files->end(); ++it) {
io::CSVReader<ROWS_NUMBER> in(*(*it));
in.read_header(io::ignore_extra_column, *rows->at(0), *rows->at(1), *rows->at(2), *rows->at(3));
int line_string_id, point_idx;
double lat, lon;
while (in.read_row(line_string_id, point_idx, lat, lon)){
ParsedLine* pl = new ParsedLine(line_string_id, point_idx, lat, lon);
parsedData->push_back(pl);
}
}
return *parsedData;
}
void Parser::convert()
{
double t1, t2;
for (vector<ParsedLine*>::iterator it = parsedData->begin(); it != parsedData->end(); ++it) {
mercatorLocalProjWithScale->push_back(new pair<double, double>(
modf( abs(xConversion((*it)->lon) - xConversion(LON_0)) * SCALE, &t1 ) * SHIFT,
modf( abs(yConversion((*it)->lat) - yConversion(LAT_0)) * SCALE, &t2 ) * SHIFT
));
}
}
double Parser::xConversion(double l)
{
return R * l * M_PI * Q;
}
double Parser::yConversion(double l)
{
return R * log10(tan(M_PI * 0.25 + l * J));
}
void Parser::convertToObj()
{
ofstream o("level_10.obj");
convert();
for (vector<pair<double, double>*>::iterator it = mercatorLocalProjWithScale->begin(); it != mercatorLocalProjWithScale->end(); ++it) {
o << "v " << (*it)->first << ' ' << (*it)->second << ' ' << '1' << '\n';
}
}