-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathGeoProcessing.cpp
More file actions
61 lines (54 loc) · 1.54 KB
/
GeoProcessing.cpp
File metadata and controls
61 lines (54 loc) · 1.54 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
#include "stdafx.h"
#include "GeoProcessing.h"
#include "ShapefileHelper.h"
#include "FieldHelper.h"
#include "Shapefile.h"
// ****************************************************************
// CopyFields()
// ****************************************************************
void GeoProcessing::CopyFields(IShapefile* sfSubject, IShapefile* sfOverlay, IShapefile* sfResult, map<long, long>& fieldMap, bool mergeFields)
{
// fields of the subject shapefile
LONG numFields, position;
VARIANT_BOOL vbretval;
sfSubject->get_NumFields(&numFields);
ShapefileHelper::CopyFields(sfSubject, sfResult);
// passing the fields of overlay shapefile
if (sfOverlay)
{
LONG numFields2;
sfOverlay->get_NumFields(&numFields2);
for (long i = 0; i < numFields2; i++)
{
IField * field1 = NULL;
sfOverlay->get_Field(i, &field1);
// checking whether we have such field already
bool found = false;
if (mergeFields)
{
for (int j = 0; j < numFields; j++)
{
IField * field2 = NULL;
sfResult->get_Field(j, &field2);
if (FieldHelper::FieldsAreEqual(field1, field2))
{
fieldMap[i] = j;
found = true;
}
field2->Release();
}
}
if (!found)
{
IField* fieldNew = NULL;
field1->Clone(&fieldNew);
sfResult->get_NumFields(&position);
sfResult->EditInsertField(fieldNew, &position, NULL, &vbretval);
fieldNew->Release();
fieldMap[i] = position;
}
field1->Release();
}
FieldHelper::UniqueFieldNames(sfResult);
}
}