-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfileio.cpp
81 lines (70 loc) · 2.2 KB
/
fileio.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "fileio.hpp"
#include <fstream>
#include <boost/lexical_cast.hpp>
void load_lots_shp(const char* file, std::map<int,Lot>& lots)
{
lots.clear();
OGRRegisterAll();
OGRDataSource *poDS = OGRSFDriverRegistrar::Open(file,FALSE);
OGRLayer *poLayer = poDS->GetLayer(0);
poLayer->ResetReading();
OGRFeature *poFeature;
int index = -1;
while( (poFeature = poLayer->GetNextFeature()) )
{
OGRPolygon* ply = (OGRPolygon*)(poFeature->GetGeometryRef());
ply->closeRings();
++index;
lots.insert(std::make_pair(index,Lot(index,ply)));
OGRFeature::DestroyFeature( poFeature );
}
OGRDataSource::DestroyDataSource( poDS );
}
void load_bldgsFinal_shp(std::string& dir, int n,std::map<int,std::vector<Building> >& exp_bldgs)
{
exp_bldgs.clear();
OGRRegisterAll();
std::string file;
for(int i=0; i<n; ++i)
{
file = dir + "/bldgs_final_exp"+ boost::lexical_cast<std::string>(i) + ".shp";
OGRDataSource *poDS = OGRSFDriverRegistrar::Open(file.c_str(),FALSE);
OGRLayer *poLayer = poDS->GetLayer(0);
poLayer->ResetReading();
OGRFeature *poFeature;
while( (poFeature = poLayer->GetNextFeature()) )
{
OGRPolygon* ply = (OGRPolygon*)(poFeature->GetGeometryRef());
double h = poFeature->GetFieldAsDouble("height");
int lotID = poFeature->GetFieldAsInteger("lotID");
exp_bldgs[i].push_back(Building(ply,h,lotID));
OGRFeature::DestroyFeature( poFeature );
}
OGRDataSource::DestroyDataSource( poDS );
}
}
void load_bldgsEvolution_txt(const char* txt,std::map< int,std::vector<Building> >& iter_bldgs)
{
std::ifstream in(txt);
if(in.is_open())
{
int iter;
double x,y,h;
in>>iter;
while(!in.eof())
{
OGRLinearRing ring;
for(int i=0; i<5; ++i)
{
in>>x;
in>>y;
ring.addPoint(x,y);
}
in>>h;
OGRPolygon footprint;
footprint.addRing(&ring);
iter_bldgs[iter].push_back(Building(&footprint,h));
in>>iter;
}
}
}