-
Notifications
You must be signed in to change notification settings - Fork 0
/
DgInShapefileAtt.cpp
100 lines (85 loc) · 2.73 KB
/
DgInShapefileAtt.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
////////////////////////////////////////////////////////////////////////////////
//
// DgInShapefileAtt.cpp: DgInShapefileAtt class implementation
//
// Version 6.1 - Kevin Sahr, 5/23/13
//
////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include "DgInShapefileAtt.h"
#include "DgLocList.h"
#include "DgPolygon.h"
#include "DgPolygon.h"
#include "DgLocation.h"
#include "DgCell.h"
#include "DgContCartRF.h"
////////////////////////////////////////////////////////////////////////////////
DgInShapefileAtt::DgInShapefileAtt (const DgGeoSphRF& geoRFIn,
const string* fileNameIn, DgReportLevel failLevelIn)
: DgInShapefile (geoRFIn, fileNameIn, failLevelIn),
dbfFile_ (NULL), numFields_ (0)
{
if (fileNameIn)
if (!open(NULL, DgBase::Silent))
report("DgInShapefileAtt::DgInShapefileAtt() unable to open file " +
fileName_, failLevel());
} // DgInShapefileAtt::DgInShapefileAtt
////////////////////////////////////////////////////////////////////////////////
bool
DgInShapefileAtt::open (const string* fileNameIn, DgReportLevel failLevelIn)
{
if (!DgInShapefile::open(fileNameIn, failLevelIn))
return false;
dbfFile_ = DBFOpen(fileName_.c_str(), "rb");
if (dbfFile_ == NULL)
{
report("DgInShapefileAtt::open() unable to open dbf file " +
fileName_, failLevelIn);
return false;
}
DBFFieldType type;
char fName[12];
int w, p;
numFields_ = DBFGetFieldCount(dbfFile_);
for (int i = 0; i < numFields_; i++)
{
type = DBFGetFieldInfo(dbfFile_, i, fName, &w, &p);
if (type == FTInvalid)
{
report("DgInShapefileAtt::open() invalid field #" +
dgg::util::to_string(i) + " in dbf file " +
fileName_, failLevelIn);
return false;
}
DgDBFfield f(fName, type, i, w, p);
fields_.insert(f);
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
void
DgInShapefileAtt::close (void)
{
if (dbfFile_)
{
DBFClose(dbfFile_);
dbfFile_ = NULL;
numFields_ = 0;
fields_.clear();
}
DgInShapefile::close();
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void
DgInShapefileAtt::getNextEntity (void)
{
DgInShapefile::getNextEntity();
curObjFields_.clear();
for (set<DgDBFfield>::iterator it = fields_.begin(); it != fields_.end(); it++)
{
if (!DBFIsAttributeNULL(dbfFile_, curRecNum_, it->fieldNum()))
curObjFields_.insert(*it);
}
}
////////////////////////////////////////////////////////////////////////////////