[UW-GIS-L] IDW problems in Workstation (VBA Solution)
David Finlayson
dfinlays at u.washington.edu
Mon Mar 29 23:31:33 PST 2004
When AML fails, turn to your last resort...VBA:
Sub IDW()
' Set the two variables to fit data
Dim sFieldName As String
sFieldName = "height" 'Field name used in interpolation
Dim CellSize As Double
CellSize = 60 'Cell size for output raster
' Get the point and barrier shapefiles
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Set pFeatureWorkspace = _
pWorkspaceFactory.OpenFromFile("C:\Your\Directory", 0)
Dim pFeaClsPoints As IFeatureClass
Set pFeaClsPoints =
pFeatureWorkspace.OpenFeatureClass("points_shapefile")
Dim pFeaClsBarriers As IFeatureClass
Set pFeaClsBarriers =
pFeatureWorkspace.OpenFeatureClass("barriers_shapefile")
' Create FeatureClassDescriptor using a value field
Dim pFDescr As IFeatureClassDescriptor
Set pFDescr = New FeatureClassDescriptor
pFDescr.Create pFeaClsPoints, Nothing, sFieldName
' Create RasterInterpolationOp object
Dim pIntOp As IInterpolationOp
Set pIntOp = New RasterInterpolationOp
' Set cell size for output raster. The extent of the output raster is
' defualted to as same as input. The output working directory uses
default
Dim pEnv As IRasterAnalysisEnvironment
Set pEnv = pIntOp
pEnv.SetCellSize esriRasterEnvValue, CellSize
' Create raster radius using variable distance
Dim pRadius As IRasterRadius
Set pRadius = New RasterRadius
pRadius.SetVariable 3
' Using FeatureClassDescriptor as an input to the IInterpolationOp and
' Perform the interpolation
Dim pOutRaster As IRaster
Set pOutRaster = pIntOp.IDW(pFDescr, 2, pRadius, pFeaClsBarriers)
End Sub
I adapted this solution from:
http://arcobjectsonline.esri.com/ArcObjectsOnline/Samples/Spatial%20Analyst/FeatureClassDescriptor.htm
It's only 44 times as long as the AML code to do the same thing. Too bad
the AML didn't work :(
Cheers,
David
David Finlayson wrote:
> I am trying to script a cross-validation analysis using IDW with
> barriers (hence, I cannot use Geostatistical Analyst).
>
> When I issue the command:
>
> > outgrid = idw(point.gen, #, #, 2, RADIUS, 52800, 3, 52800)
>
> The interpolation proceeds without error. However, when I include the
> barriers I get the following error:
>
> > outgrid = idw(point.gen, #, barrier.gen, 2, RADIUS, 52800, 3, 52800)
> Unknown input point type: 1
>
> The error is in the barrier file (since IDW worked without the
> barriers) or it's a bug in IDW. I created the barriers as a coverage
> and then dumped them to the file with UNGENERATE, so presumably it's
> in the proper format. I have tried selectively removing lines from the
> barrier file (down to just one line) with the same error results.
>
> Interestingly enough, the interpolation with barriers works fine from
> Spatial Analyst's GUI (but I don't want to manually create 100's of
> IDW grids!)
>
> Has anyone else run into this?
>
> David
>
--
David Finlayson
Marine Geology & Geophysics
School of Oceanography
Box 357940
University of Washington
Seattle, WA 98195-7940
USA
Office: Marine Sciences Building, Room 112
Phone: (206) 616-9407
Web: http://students.washington.edu/dfinlays
More information about the Uw-gis-l
mailing list