AnsweredAssumed Answered

Help with ITinEdit.AddFromPixelBlock

Question asked by limgeomatics_u2 on Aug 4, 2015
Latest reply on Oct 29, 2015 by SEria-esristaff

Hey All,

 

I am attempting to create a TIN from a Raster Dataset:

 

private void Example(IRasterDataset rasterDataset, IGeometry aoi)
        {
            ITin tin = new TinClass();
            ITinEdit tinEdit = (ITinEdit)tin;
              tinEdit.InitNew(aoi.Envelope);


            var raster = rasterDataset.CreateDefaultRaster();
            var rasterProps = (IRasterProps)raster;
            var cellsize = rasterProps.MeanCellSize();


            IPnt blocksize = new PntClass();
            blocksize.SetCoords(Math.Floor(aoi.Envelope.Width / cellsize.X), Math.Floor(aoi.Envelope.Height / cellsize.Y));
            //IRasterCursor rasterCursor = raster2.CreateCursorEx(blocksize);
            var rasterCursor = ((IRaster2)raster).CreateCursorEx(blocksize);
            var pixelBlock = rasterCursor.PixelBlock;


            //Get the pixel blocks
            IPnt tlc = new PntClass();
            tlc.SetCoords(Math.Floor((aoi.Envelope.XMin - rasterProps.Extent.XMin) / cellsize.X), Math.Ceiling((rasterProps.Extent.YMax - aoi.Envelope.YMax) / cellsize.Y));
            raster.Read(tlc, pixelBlock);


            IPixelBlock3 pixelBlock3 = (IPixelBlock3)pixelBlock;
            var pixels = (System.Array)pixelBlock3.get_PixelDataByRef(0);


            object maxPoints = 3000000;
            object toleranceAchieved = false;
            object nodata = -9999.0;


            try
            {
                tinEdit.AddFromPixelBlock(aoi.Envelope.XMin + (cellsize.X / 2), aoi.Envelope.YMax - (cellsize.Y / 2), cellsize.X, cellsize.Y, nodata, pixelBlock, 1, ref maxPoints, out toleranceAchieved);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }


        }

 

But I get a "Value does not fall within expected range" message on the exception. Any ideas?

Outcomes