forked from MapWindow/MapWinGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableHelper.cpp
More file actions
65 lines (59 loc) · 1.73 KB
/
TableHelper.cpp
File metadata and controls
65 lines (59 loc) · 1.73 KB
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
#include "stdafx.h"
#include "TableHelper.h"
// **************************************************
// Cast()
// **************************************************
CTableClass* TableHelper::Cast(CComPtr<ITable>& table)
{
return (CTableClass*)&(*table);
}
// **************************************************
// GetNumRows()
// **************************************************
long TableHelper::GetNumRows(ITable* table)
{
if (!table) return 0;
long numRows;
table->get_NumRows(&numRows);
return numRows;
}
// **************************************************
// GetNumFields()
// **************************************************
long TableHelper::GetNumFields(ITable* table)
{
if (!table) return 0;
long numFields;
table->get_NumFields(&numFields);
return numFields;
}
// **************************************************
// SetFieldValues()
// **************************************************
void TableHelper::SetFieldValues(ITable* table, int rowIndex, CustomExpression& expr )
{
if (!table) return;
for (long j = 0; j< expr.get_NumFields(); j++)
{
CComVariant var;
int fieldIndex = expr.get_FieldIndex(j);
table->get_CellValue(fieldIndex, rowIndex, &var);
switch (var.vt)
{
case VT_BSTR: expr.put_FieldValue(j, var.bstrVal); break;
case VT_I4: expr.put_FieldValue(j, (double)var.lVal); break;
case VT_R8: expr.put_FieldValue(j, (double)var.dblVal); break;
}
}
// TODO: don't set shape, if the expression doesn't contain geometry function
IShapefile* sf = ((CTableClass*)table)->GetParentShapefile(); // doesn't add reference
if (sf)
{
CComPtr<IShape> shp = NULL;
sf->get_Shape(rowIndex, &shp);
if (shp)
{
expr.put_Shape(shp);
}
}
}