Select to view content in your preferred language

Help with ITinEdit.AddFromPixelBlock

2820
1
08-04-2015 09:39 AM
GregMcQuat
New Contributor III

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?

Tags (2)
0 Kudos
1 Reply
seria
by Esri Contributor
Esri Contributor

The issue is probably caused by one or more of the parameters in your tinEdit.AddFromPixelBlock() not being compatible input into the method.

I noticed that the last two parameters are supposed to passed in "by reference", but it appears that the last parameter has been passed in as "out toleranceAchieved". This could be causing your problem.

Try replacing the last two parameters with "null" objects in accordance with the example provided on the Help page below:

ITinEdit.AddFromPixelBlock Method

http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//0025000008wz000000

It says somewhere on the page:

Optional Values

pMaxPoints   To indicate that this parameter is undefined, first define a variable

    object Missing = Type.Missing; then pass this in as ref Missing.

pbToleranceAchieved   To indicate that this parameter is undefined, first define a variable

    object Missing = Type.Missing; then pass this in as ref Missing.

Replace the last two parameters with "ref Missing" and see if this resolves your issue.