Jump to content


Yes I am Still using VBA

- - - - -

  • Please log in to reply
2 replies to this topic




  • New Member
  • Pip
  • 1 posts
  • Canada

Please help, I can't figure this out at all!! I have a raster that I have created in VBA which I now need its Mean and Standard deviation put into two seperate, constant value, rasters with the same spatial properties (cell size ect) as the input raster. I have gotten into irasterstatistics but the result is incorrect (the mean is 2.44 but the tool displays 1.65). I cannot get this double value into a constant raster either. Here is my code, see what you think.


Dim pLn As IRaster
Set pLn = pDTWValues ------------------------------------------------------------- this is an igeodataset

Dim pFlwAccBandCol As IRasterBandCollection
Set pFlwAccBandCol = pLn

Dim pFlwAccRasBand As IRasterBand
Set pFlwAccRasBand = pFlwAccBandCol.Item(0)

Dim pFlwAccRasterStatistics As IRasterStatistics
Set pFlwAccRasterStatistics = pFlwAccRasBand.Statistics

Dim FlwMean As Double
Dim FlwSTD As Double
FlwMean = pFlwAccRasterStatistics.Mean
FlwSTD = pFlwAccRasterStatistics.StandardDeviation
MsgBox FlwMean ---------------------------------------------------------------------------------Displays incorrect value
MsgBox FlwSTD ---------------------------------------------------------------------------------Displays incorrect value

Dim pConstantValue2 As IGeoDataset
Set pConstantValue2 = pRasterMakerOp.MakeConstant(FlwMean, False)
Dim pConstantValue3 As IGeoDataset
Set pConstantValue3 = pRasterMakerOp.MakeConstant(FlwSTD, False)

'===============Create Raster Layer===============
Dim pLayer6 As IRasterLayer
Set pLayer6 = New RasterLayer
pLayer6.CreateFromRaster pConstantValue2 ----------------------------------------------------error, will not display
pMap.AddLayer pLayer6

Matthew Hampton

Matthew Hampton

    Hall of Fame

  • Moderator
  • PipPipPipPipPipPipPip
  • 1,418 posts
  • Gender:Male
  • Location:Portland, Oregon
  • Interests:Playing in the mountains and rivers.
  • United States

Hi David,

I think that's the first VBA code I've seen dumped on Cartotalk. You may find quicker elucidation on a forum more specific to using VBA on geospatial rasters. Have you tried an ESRI forum?

co-cartographic creator of boringmaps.com



    Master Contributor

  • Validated Member
  • PipPipPipPip
  • 225 posts
  • Gender:Male
  • Location:Denver
  • United States

In addition to what Matthew said, I think you might get faster results if you just created a model to produce these results.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users