English

Problem: IGeneralizeOp.Expand and IGeneralizeOp.Shrink affect the zone of value zero, whether it was added to the zone list or not

Description

IGeneralizeOp.Expand and IGeneralizeOp.Shrink will automatically expand or shrink the zone of value zero, whether it was added to the zone list or not. In the following code example the zones of values 2 and 4 will be expanded five cells.

Dim pOp As IGeneralizeOp
Set pOp = New RasterGeneralizeOp
Dim zoneList As Variant
Dim lngArr(2) As Long
lngArr(0) = 2
lngArr(1) = 4
zoneList = lngArr
Dim pOutRaster As IGeoDataset
Set pOutRaster = pOp.Expand(pInRaster, 5, zoneList)

The results will show that zones 0, 2, and 4 were expanded five cells. Only zones 2 and 4 should have been expanded.

Cause

The variant zone list array may not have been correctly defined in Visual Basic, as it has a different style of array definition from C.

In VB, an array Arr(2) defines three elements, Arr(0), Arr(1), and Arr(2) with a default 0 Option Base. In C, Arr(2) defines 2 elements Arr(0) and Arr(1). When you define a zone array lngArr(2) in VB, the first two entries are set by the code, but the third one is not and is set to 0; this is how 0 gets added to the zone list.

Solution or Workaround

Make sure you set up your zone list properly. The following code shows the correct way to define and send in the variant zone list array for the above example:

Code:
Dim pOp As IGeneralizeOp
Set pOp = New RasterGeneralizeOp
Dim zoneList As Variant
Dim lngArr(1) As Long
lngArr(0) = 2
lngArr(1) = 4
zoneList = lngArr
Dim pOutRaster As IGeoDataset
Set pOutRaster = pOp.Expand(pInRaster, 5, zoneList)
Code: